rasa-webchat icon indicating copy to clipboard operation
rasa-webchat copied to clipboard

Not sure about what is the purpose of dispatch evalUrl function

Open chun-wen opened this issue 2 years ago • 1 comments
trafficstars

hi I have two questions below

  1. May I know what is the purpose of this function ?
  2. why we need to dispatch evalUrl method every 500 milliseconds ?

Below is source code Path: packages\chatbot-rasa-webchat\src\components\Widget\index.js

this.intervalId = setInterval(() => dispatch(evalUrl(window.location.href)), 500);

Path: packages\chatbot-rasa-webchat\src\store\store.js

      case actionTypes.EVAL_URL: {
        const pageCallbacks = store.getState().behavior.get('pageChangeCallbacks');
        const pageCallbacksJs = pageCallbacks ? pageCallbacks.toJS() : {};

        const newUrl = action.url;

        if (!pageCallbacksJs.pageChanges) break;

        if (store.getState().behavior.get('oldUrl') !== newUrl) {
          const { pageChanges, errorIntent } = pageCallbacksJs;
          const matched = pageChanges.some((callback) => {
            if (callback.regex) {
              if (newUrl.match(callback.url)) {
                emitMessage(callback.callbackIntent);
                return true;
              }
            } else {
              let cleanCurrentUrl = cleanURL(newUrl);
              let cleanCallBackUrl = cleanURL(callback.url);
              if (!cleanCallBackUrl.match(/\?.+$/)) {
                // the callback does not have a querystring
                cleanCurrentUrl = trimQueryString(cleanCurrentUrl);
                cleanCallBackUrl = trimQueryString(cleanCallBackUrl);
              }
              if (cleanCurrentUrl === cleanCallBackUrl) {
                emitMessage(callback.callbackIntent);
                return true;
              }
              return false;
            }
          });
          if (!matched) emitMessage(errorIntent);
        }
        break;
      }

chun-wen avatar Sep 19 '23 03:09 chun-wen

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Mar 17 '24 16:03 stale[bot]