首页 文章

欢迎消息在Webchat中不可见,但在模拟器中工作

提问于
浏览
3
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开发的新手 .

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

1 回答

  • 2

    我刚刚测试了你的代码并得到了相同的行为 . 奇怪的是,机器人加入时似乎只有一个对话更新,而不是一个用于机器人,一个用于用户 . 我正在调查这个 . 如果您想尝试以下代码:

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

相关问题