Welcome message not visibile in Webchat,but work in Emulator

a 夏天 提交于 2019-12-10 18:29:29

问题


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

I'm new to ChatBot development using Microsoft BotFramework.

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


回答1:


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


来源:https://stackoverflow.com/questions/47694305/welcome-message-not-visibile-in-webchat-but-work-in-emulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!