欢迎消息在Webchat中不可见,但可在Emulator中使用 [英] Welcome message not visibile in Webchat,but work in Emulator

查看:64
本文介绍了欢迎消息在Webchat中不可见,但可在Emulator中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IConversationUpdateActivity update = message;
        using (var scope = Microsoft.Bot.Builder.Dialogs.Internals.DialogModule.BeginLifetimeScope(Conversation.Container, message))
        {
            var client = scope.Resolve<IConnectorClient>();
            if (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);
                    }
                }
            }
        }

我是使用Microsoft BotFramework开发ChatBot的新手.

I'm new to ChatBot development using Microsoft BotFramework.

我已经注册并部署了一个可以与模拟器正常运行的简单bot(即bot说欢迎使用我的简单bot),但是当我使用WebChat时,没有显示欢迎问候,而是当用户键入Hi或此后的任何文本时,显示问候消息. 已经去过各种教程和解决方案,但没有找到确切的原因.我正在使用Microsoft.Bot.Builder v3.12

I have register and deployed a simple bot that was working fine with emulator (i.e bot says welcome to my simple bot),but when i used WebChat no welcome greeting was displayed,instead when user type Hi or any text after that the greeting message is displayed. had gone to various tutorial and solution but not getting the exact cause. i'm using Microsoft.Bot.Builder v3.12

推荐答案

我刚刚测试了您的代码,并得到了相同的行为.奇怪的是,僵尸程序加入时似乎只有一次对话更新,而不是僵尸程序和用户的对话更新.我正在调查这个.如果您想尝试一下,下面的代码将起作用:

I just tested your code and got the same behavior. The odd part is that there seems to only be one conversation update for when the bot joins, rather than one for the bot and one for the user. I am looking into this. The following code is working if you would like to give it a try:

IConversationUpdateActivity iConversationUpdated = message as IConversationUpdateActivity;
if (iConversationUpdated != null)
{
    ConnectorClient connector = new ConnectorClient(new System.Uri(message.ServiceUrl));

    foreach (var member in iConversationUpdated.MembersAdded ?? System.Array.Empty<ChannelAccount>())
    {
        // if the bot is added, then
        if (member.Id == iConversationUpdated.Recipient.Id)
        {
            var reply = ((Activity)iConversationUpdated).CreateReply(
                $"Hi! I'm Botty McBotface and this is a welcome message");
            connector.Conversations.ReplyToActivityAsync(reply);
        }
    }
}

这篇关于欢迎消息在Webchat中不可见,但可在Emulator中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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