The second ConversationUpdate event will follow at the back of user first input?

I test my bot at Azure Portal(Bot Channels Registration/BOT MANAGEMENT/Test in Web Chat). The second ConversationUpdate event will follow at the back of user first input, like below,

click StartOver ant Azure Portal WebChat The second ConversationUpdate event will follow at the back of user first input? Azure's Webchat Step like below,

  1. click Startover
  2. bot get first ConversationUpdate, memberAdd bot
  3. user input text
  4. bot get user input text
  5. bot get second ConversationUpdate, memberAdd user

But emulator working fine, 2 ConversationUpdate events and wait for user input. botframework-emulator Step like below,

  1. click Start new Conversation
  2. bot get first ConversationUpdate, memberAdd bot
  3. bot get second ConversationUpdate, memberAdd user
  4. user input text
  5. bot get user input text

I want send welcome message(include user's name, like hi, rainmaker welcome ...) to user when second ConversationUpdate was coming. The welcome message will send after user input in azure webchat. How can i fix this problem?

Thanks.

1 answer

  • answered 2018-05-16 12:18 Nicolas R

    That's a common question posted here; yes the conversationUpdate event is not thrown on the same way between emulator and webchat, that's quite disturbing.

    Send a welcome to your user in Webchat

    I want send welcome message(include user's name, like hi, rainmaker welcome ...) to user when second ConversationUpdate was coming. The welcome message will send after user input in azure webchat. How can i fix this problem?

    If your need is to send a welcome message with some information about the user before this user starts talking, you can use the backchannel feature of the webchat to pass those information and then catch the message and send your welcome message.

    It needs a few lines of code on the front-side, so that cannot be used for Azure webchat tester. But it is working well on a webchat implementation, see sample below.

    Sidenote: if you don't need information about the user, you can still use the 1st conversationUpdate you are receiving.

    Sample

    Sample code: I made a demo about that, you can get it there: https://github.com/nrobert/Bot-Language-Demo

    Main points:

    1. Backchannel message sent from the front here

    In the sample I'm passing a locale information:

    botConnectionSettings.postActivity({
        type: 'event',
        from: { id: 'userid' },
        locale: chatLocale,
        name: 'localeSelectionEvent',
        value: chatLocale
    }).subscribe(function (id) { console.log('event language "' + chatLocale + '" selection sent'); });
    

    2. Message received at the bot level, here

    else if (activity.Type == ActivityTypes.Event && activity.ChannelId == "webchat")
    {
        var receivedEvent = activity.AsEventActivity();
    
        if ("localeSelectionEvent".Equals(receivedEvent.Name, StringComparison.InvariantCultureIgnoreCase))
        {
            // Send your welcome message here, using the special information you would have put in the event message...
    
        }
    }