当我将我的机器人测试到网络聊天频道时,接受两次欢迎回复,而不是一次。
我正在使用会话更新机制在新成员添加或新会话的情况下发送欢迎回复。
你可以告诉我缺少什么吗?提前感谢,
Sanjeev
答案 0 :(得分:1)
当BOT添加到对话时,它也必须显示消息。 如果添加到对话中的成员不是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.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
// Note: Add introduction here:
IConversationUpdateActivity update = message;
var client = new ConnectorClient(new Uri(message.ServiceUrl), new MicrosoftAppCredentials());
if (update.MembersAdded != null && update.MembersAdded.Any())
{
foreach (var newMember in update.MembersAdded)
{
if (newMember.Id != message.Recipient.Id)
{
var reply = message.CreateReply();
reply.Text = $"Welcome {newMember.Name}!";
client.Conversations.ReplyToActivityAsync(reply);
}
}
}
}
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
}
else if (message.Type == ActivityTypes.Ping)
{
}
return null;
}
这就是你要做的。
您可以通过以下链接获取更多详细信息:http://www.davidezordan.net/blog/?p=8119