当用户向我的机器人发送消息时,他会收到欢迎消息.但是,当用户对此做出响应时,机器人会再次发送欢迎消息.我怎样才能解决这个问题? [英] 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?
问题描述
我正在使用Microsoft Bot Framework开发聊天机器人,最近又将Framework 3.0升级到3.5.在升级之前,它可以正常工作,但现在
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
消息.
I believe this could be related to a change that was rolled out a few days ago; where Direct Line will send more ConversationUpdate
messages than it used to.
检查公告和
Check the announcement and a related issue (similar to yours, but in node.js
).
将自动程序添加到对话中后,将发送第一个ConversationUpdate
.
之后,当新用户加入对话时,将发送每个附加的ConversationUpdate
.
The first ConversationUpdate
is sent when the bot is added to the conversation.
After that, each additional ConversationUpdate
is sent when a new user joins the conversation.
所以,我认为解决方案是检查添加的成员(activity.MembersAdded
)
So, I think the solution here will be to check the members added (activity.MembersAdded
)
else if (message.Type == ActivityTypes.ConversationUpdate)
{
if (message.MembersAdded.Any(o => o.Id == message.Recipient.Id))
{
// logic
}
}
这篇关于当用户向我的机器人发送消息时,他会收到欢迎消息.但是,当用户对此做出响应时,机器人会再次发送欢迎消息.我怎样才能解决这个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!