Botframework-webchat: How to receive error message from the Bot on Timeout

Created on 23 Jan 2019  路  5Comments  路  Source: microsoft/BotFramework-WebChat

In this scenario we have failed to send our message and I want to reply (in the chat, as it is written by the bot). I can't find any action to dispatch in order to receive a message from the bot. If I call SEND_MESSAGE_BACK action i end up sending more messages instead of receiving. You can reproduce this if you connect to the chat and then turn off the Internet from you PC/Browser.

this.chatStore = createStore(
      onErrorResumeNext(() => {
        const reduxStore = window.localStorage.getItem(REDUX_CHAT_STORE_KEY) ? window.localStorage.getItem(REDUX_CHAT_STORE_KEY) : "{}";
        return JSON.parse(reduxStore as string);
      }),
      ({ dispatch }: any) => (next: any) => (action: any) => {
        if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
          dispatch({
            type: 'WEB_CHAT/SEND_EVENT',
            payload: {
              name: 'webchat/join',
              value: { language: window.navigator.language },
              type: 'event',
              from: { id: this.id },
            }
          });
        } else if (action.type === 'DIRECT_LINE/POST_ACTIVITY_REJECTED') {
          console.log("enters required reducer")
          // dispatch({
          //   type: '', //WHAT ACTION SHOULD I DISPATCH IN ORDER TO RECEIVE MESSAGE????
          //   payload: {
          //     displayText: 'dont care',
          //     text: 'hahahah',
          //     value: "whatever"
          //   }
          // })
        }
        return next(action);
      }
    );
Question

All 5 comments

@ljubomirsinadinovski I'm sorry, I'm having trouble understanding your request. Could you clarify? What I understand is that you are trying to alert the bot USER that sending a message to the BOT has failed. You want this message to come from the bot. Is this correct? This is not a feature of Web Chat.

We have some enhancement work items #135 related to Offline UI display, but this would not be a message from the bot. Is this similar to what you are looking for?

@ljubomirsinadinovski I'm sorry, I'm having trouble understanding your request. Could you clarify? What I understand is that you are trying to alert the bot USER that sending a message to the BOT has failed. You want this message to come from the bot. Is this correct? This is not a feature of Web Chat.

We have some enhancement work items #135 related to Offline UI display, but this would not be a message from the bot. Is this similar to what you are looking for?

Yes you understood right. I am going to write the scenario in order to clarify better:

  • User: Hello chat bot, give me some help (this request fails and activates DIRECT_LINE/POST_ACTIVITY_REJECTED)
  • Bot: I am sorry, I am not available at the moment, please try again in couple of minutes (this is the message response action that I am looking for that comes from the bot)

I think that the Web Chat should include this type of action, because it is really important to make the Web Chat as user friendly as possible. Also would help developers to add custom things without contacting the directLine/back-end

BTW: The reducer I call above (with action type DIRECT_LINE/POST_ACTIVITY_REJECTED) covers the case when the message send is failing... that is the very reason why I want to return general error message that looks like its coming from the bot (but actually isn't)

Thanks for the clarification. It sounds like the features you are looking for are similar to the Offline UI issues that are already filed and in the works. The only difference is that these messages will show above the Sendbox, within the transcript as a notification, not an activity from the bot. One of the problems of making the message appear to come from the bot is that because there are connectivity issues, you are not necessarily connected to the bot for it to receive or send activities.

As an example, https://github.com/Microsoft/BotFramework-WebChat/issues/1521 is the issue that will display a message when connecting to the bot is slow or has errors. The front-end waits for a connection from the bot, and displays a warning or error if no data comes from the bot. The feature will not look like a message from the bot, however.

One solution I can see for you is to modify our component (once the feature is released) with styleOptions to appear like a chat bubble. @compulim, @cwhitten, should we preemptively create mod-ability for Offline UI to support this scenario?

@ljubomirsinadinovski I think in this case, there are few options for now:

  • Wait for @corinagum work on offline UI, targetting mid-Feb release (there are some mock ups in #1521)
  • You can mock an incoming message by dispatching DIRECT_LINE/INCOMING_ACTIVITY. I won't recommend this approach because anything DIRECT_LINE/* could change from time to time. But at the very least, you know this is Redux, and anything that change the store must be triggered by an action. If we change this action, there must be another action to replace it
  • Look at reducer/activities.js, and add an artificial activity when you get WEB_CHAT/DISCONNECT_PENDING (or some other actions). I didn't take a deep thought on this, but I think this might work

What do you think?

Cheers, thank you @compulim and @corinagum! I guess I am going to wait for the mid-Feb release, that works for me. I won't play around with DIRECT_LINE/* actions as suggested, I agree. I won't take into consideration the 3rd approach because if technical debt that may arose, as well as maintenance. I am going to close this issue now, because we have come to a conclusion ^_^

Was this page helpful?
0 / 5 - 0 ratings