【问题标题】:Welcome message not visibile in Webchat,but work in Emulator欢迎信息在网络聊天中不可见,但在模拟器中工作
【发布时间】:2017-12-08 02:29:42
【问题描述】:
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

【问题讨论】:

    标签: c# c#-4.0 botframework direct-line-botframework


    【解决方案1】:

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

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

    【讨论】:

    • 他@JasonSowers 非常感谢你,现在它工作正常。但我有一个问题,如果可以使用 Webchat 在 QueryString 中传递一些 ExtraData,我正在使用 C#,我使用 webchat 部署了机器人,但想要基于现有网站登录验证用户。
    • 我能否在我的 MessageController.cs 中取回 QueryString 值,我使用 Request.RequestUri.Query 进行了分层,它适用于模拟器,但不适用于实时环境。
    • 您可能希望使用反向通道发送所需的任何数据。请看我的回答here 会解释更多
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    • 2021-07-30
    相关资源
    最近更新 更多