我正在使用Microsoft Bot Framework开发一个聊天机器人,我最近将框架3.0升级到3.5.升级之前它工作正常,但现在
当用户向我的机器人发送消息时,他会收到欢迎消息.但是当用户响应时,bot再次发送欢迎消息.我怎样才能解决这个问题?这是代码.
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; }
但是在本地模拟器中它的工作正常,而发布时只会发生这种情况.请帮忙.
我相信这可能与几天前推出的变化有关; Direct Line将发送ConversationUpdate
比以往更多的消息.
检查公告和相关问题(与您的相似,但在中node.js
).
第一个ConversationUpdate
是在将bot添加到对话时发送的.之后,ConversationUpdate
当新用户加入对话时,会发送每个附加内容.
所以,我认为这里的解决方案是检查成员添加(activity.MembersAdded
)
else if (message.Type == ActivityTypes.ConversationUpdate) { if (message.MembersAdded.Any(o => o.Id == message.Recipient.Id)) { // logic } }