Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass default value of 'meta' parameter as "keyword" in 'postActivity' function of postActivitySaga.js #1651

Closed
ghost opened this issue Jan 28, 2019 · 2 comments

Comments

@ghost
Copy link

ghost commented Jan 28, 2019

Hi,
When I tried to add Minimizable Webchat from samples to my project, somehow it's not hitting the action '../actions/postActivity.js'.
So from below part of MinimizableWebChat.js

const store = createStore({}, ({ dispatch }) => next => action => {
      if (action.type === "DIRECT_LINE/CONNECT_FULFILLED") {
        setTimeout(() => {
          dispatch({
            type: "DIRECT_LINE/POST_ACTIVITY",
            payload: {
              activity: {
                name: "webchat/join",
                type: "event",
                value: {
                  language: window.navigator.language
                }
              }
            }
          });
        }, 1000);
      } else if (action.type === "DIRECT_LINE/INCOMING_ACTIVITY") {
        if (action.payload.activity.from.role === "bot") {
          this.setState(() => ({ newMessage: true }));
        }
      }

      return next(action);
    });

when the below action is dispatched:

dispatch({
            type: "DIRECT_LINE/POST_ACTIVITY",
            payload: {
              activity: {
                name: "webchat/join",
                type: "event",
                value: {
                  language: window.navigator.language
                }
              }
            }
          });

It does not have meta property set as default "keyword". Hence, this breaks when 'postActivity' method of postActivitySaga.js is hit. I am referring the below code:

function* postActivity(directLine, userID, numActivitiesPosted, { meta: { method } , payload: { activity } }) {
  const locale = yield select(languageSelector);.........

Now to fix this I am following two approaches:

  1. Either dispatch action with meta property like below:
dispatch({
           type: "DIRECT_LINE/POST_ACTIVITY",
           meta: "keyword",
           payload: {
             activity: {
               name: "webchat/join",
               type: "event",
               value: {
                 language: window.navigator.language
               }
             }
           }
         });
  1. Or give default value as "keyword" to the postActivity method of postActivitySaga.js as below:
 function* postActivity(directLine, userID, numActivitiesPosted, { meta: { method } = "keyword", payload: { activity } }) {
  const locale = yield select(languageSelector);.......

Please let me know which one is correct.

@compulim
Copy link
Contributor

compulim commented Jan 28, 2019

@neetu-das thanks for taking the time drilling into the code.

I think I fixed minimizable sample in #1631. We introduced WEB_CHAT/SEND_EVENT and it will use postActivity that will fill action.meta.method automatically.

The method is mainly to determine how the message is sent, e.g. is it from keyboard? Or is it from microphone?

And the primary usage of this method field is for messages that sent thru microphone, they will turn on speech synthesis engine on next incoming message from the bot.

I didn't think thru the method field complete yet. But I believe, people would love to use postActivity to send message "from JavaScript code". Then, method should by default be javascript or code. I didn't think thru how much value this method field would provide, other than turning on speech synthesizer.

Can you check if the latest minimizable Web Chat sample is working for you? You can look at the PR #1631 for the diff.

IMO, the "minimizable sample" is a very popular one, we should make it simpler and more intuitive to use and understand.

@compulim compulim reopened this Jan 28, 2019
@ghost
Copy link
Author

ghost commented Jan 29, 2019

@compulim Thanks for the update. Yes PR #1631 solved the problem.

@ghost ghost closed this as completed Jan 29, 2019
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant