每当有人连接到我的机器人时,我都想显示欢迎消息。我已经使用了github(https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/demo-ContosoFlowers)上的demo-ContosoFlowers示例中的技术,该技术在Bot Framework Emulator中运行良好,但在Skype或Facebook Messenger中却无法使用。具体来说,MessageController.HandleSystemMessage中的此代码不会触发:

        else if (message.Type == ActivityTypes.ConversationUpdate)
        {
            if (message.MembersAdded.Any(o => o.Id == message.Recipient.Id))
            {
                var reply = message.CreateReply(Resources.RootDialog_Welcome_Message);

                ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));

                await connector.Conversations.ReplyToActivityAsync(reply);
            }
        }


有人知道如何正确执行此操作吗?

最佳答案

我今天还试用了ContosoFlowers演示。我遇到了与您描述的相同的行为:在模拟器中,触发了ConversationUpdate代码,但在Skype中则未触发。但是,我确实注意到,在Skype中确实触发了ContactRelationUpdate活动类型(我没有尝试过Facebook Messenger)。如果您的目标是每当有人“连接”您的漫游器时显示欢迎消息,则可以尝试使用ContactRelationUpdate活动类型,如下所示:

else if (message.Type == ActivityTypes.ContactRelationUpdate)
{
    if(message.Action == "add")
    {
        var reply = message.CreateReply("WELCOME!!!");
        ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));
        await connector.Conversations.ReplyToActivityAsync(reply);
    }
}

关于c# - 如何使用Microsoft Bot Framework从我的Bot显示欢迎消息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42943665/

10-09 18:01
查看更多