如何使用Microsoft Bot Framework从我的Bot显示欢迎消息 [英] How to display a welcome message from my Bot using Microsoft Bot Framework

查看:113
本文介绍了如何使用Microsoft Bot Framework从我的Bot显示欢迎消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to display a welcome message whenever someone connects to my bot. I've used the technique from the demo-ContosoFlowers sample on github (https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/demo-ContosoFlowers) which works fine in the Bot Framework Emulator, but not in Skype or Facebook Messenger. Specifically, this code in MessageController.HandleSystemMessage doesn't trigger:

        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);
            }
        }

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

Does anyone know how to do this correctly?

推荐答案

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

I also tried out the ContosoFlowers demo today. I experienced the same behavior you describe: in the emulator, ConversationUpdate code is triggered but in Skype it is not. However, I did notice that the ContactRelationUpdate activity type does fire in Skype (I haven't tried Facebook Messenger). If your goal is to display a welcome message whenever someone "connects" to your bot, you could try using the ContactRelationUpdate activity type like this:

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);
    }
}

这篇关于如何使用Microsoft Bot Framework从我的Bot显示欢迎消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆