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...
}
}