I am developing a chatbot using Microsoft Bot Framework and i recently upgraded the framework 3.0 to 3.5. before upgrading it was working fine but now
When user sends message to my bot, he receives Welcome message. But when user respond to that, bot sends Welcome message again. How can I fix this? here s the code.
private Activity HandleSystemMessage(Activity message)
{
if (message.Type == ActivityTypes.DeleteUserData)
{
// Implement user deletion here
// If we handle user deletion, return a real message
}
else if (message.Type == ActivityTypes.ContactRelationUpdate)
{
// Handle conversation state changes, like members being added and removed
// Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
// Not available in all channels
}
else if (message.Type == ActivityTypes.ConversationUpdate)
{
// Handle conversation state changes, like members being added and removed
// Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
// Not available in all channels
logger.Debug("Activity Type " + message.Type);
logger.Debug("Inside conversation update and activity Id is :-"+ message.Id);
ConnectorClient connector = new ConnectorClient(new System.Uri(message.ServiceUrl));
Activity reply = message.CreateReply(ConstantsTable.WelcomeMessage);
connector.Conversations.ReplyToActivityAsync(reply);
message.Type = ActivityTypes.Message;
}
else if (message.Type == ActivityTypes.ContactRelationUpdate)
{
// Handle add/remove from contact lists
// Activity.From + Activity.Action represent what happened
}
else if (message.Type == ActivityTypes.Typing)
{
// Handle knowing tha the user is typing
ConnectorClient connector = new ConnectorClient(new System.Uri(message.ServiceUrl));
Activity reply = message.CreateReply("You are typing");
connector.Conversations.ReplyToActivityAsync(reply);
}
else if (message.Type == ActivityTypes.Ping)
{
ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));
Activity reply = message.CreateReply("Hello PING. Please reply");
connector.Conversations.ReplyToActivityAsync(reply);
}
return message;
}
But in local emulator it's work fine while publishing only this is happening. Please help.
ConversationUpdate. So, every time he will get same welcome message. You can handle it based on user state values using Channel Idactivity.ChannelIdand UserIDactivity.From.Id. - Praveen R