Reputation: 339
I want my bot to display an introductory message when a user begins a new conversation. I've seen this working with bots in Skype where the bot sends a message before the user types anything.
I have got this working using the Bot Framework Channel Emulator with this code in the MessagesController class:
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
else
{
await this.HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
private async Task HandleSystemMessage(Activity message)
{
if (message.Type == ActivityTypes.ConversationUpdate)
{
var reply = message.CreateReply("Hello World!");
var connector = new ConnectorClient(new Uri(message.ServiceUrl));
await connector.Conversations.SendToConversationAsync(reply);
}
}
This displays 'Hello World!' at the beginning of a new conversation. No input required. However on Skype this introductory message does not appear. What I am misunderstanding here? I know it is possible.
Upvotes: 0
Views: 254
Reputation: 14589
Skype is throwing different ActivityTypes given the situation:
You will get a contactRelationUpdate
after adding the bot in your contacts. Then we you start talking to the bot, there is no special Activity
When you start a conversation group with the bot included, you will get conversationUpdate
So if you want to welcome your user, you should add the contactRelationUpdate
activity type in your test, like:
private async Task HandleSystemMessage(Activity message)
{
if (message.Type == ActivityTypes.ConversationUpdate || message.Type == ActivityTypes.ContactRelationUpdate)
{
var reply = message.CreateReply("Hello World!");
var connector = new ConnectorClient(new Uri(message.ServiceUrl));
await connector.Conversations.SendToConversationAsync(reply);
}
}
Extract of the content of the message you receive when adding the bot:
Here From
is my user and Recipient
is bot. You can see that the Action
value is add
Upvotes: 1