如何使用Microsoft Bot Framework从我的Bot显示欢迎消息

Pet*_*son 3 c# botframework

我想在有人连接到我的机器人时显示欢迎信息.我在github上使用了demo-ContosoFlowers示例中的技术(https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/demo-ContosoFlowers),它在Bot框架模拟器中运行良好,但不是在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);
            }
        }
Run Code Online (Sandbox Code Playgroud)

有谁知道如何正确地做到这一点?

Eri*_*ang 5

我今天也尝试了ContosoFlowers演示.我遇到了您描述的相同行为:在模拟器中,ConversationUpdate代码被触发但在Skype中却没有.但是,我确实注意到ContactRelationUpdate活动类型在Skype中触发(我还没试过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);
    }
}
Run Code Online (Sandbox Code Playgroud)