[Botframework]:如何修复:欢迎消息未能向C#WebChatbot中的用户显示在V4中开发的,但在模拟器中显



<!DOCTYPE html>
<html>
<head>
    <title>Avanade D365 F&O Assets BOT</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!--
      For demonstration purposes, we are using development branch of Web Chat at "/master/webchat.js".
      When you are using Web Chat for production, you should use the latest stable at "/latest/webchat.js".
      Or locked down on a specific version "/4.1.0/webchat.js".
    -->
    <script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
    <style>
        html, body {
            height: 100%
        }
        body {
            margin: 0
        }
        #webchat {
            height: 100%;
            width: 100%;
        }
    </style>
</head>
<body>
    <div id="webchat" role="main">
        <iframe src='https://webchat.botframework.com/embed/AssetsBot?s=<<given my code here as it is secret i have attached this removing the code>>' style='min-width: 400px; width: 100%; min-height: 500px;'></iframe>
    </div>
     <script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
    <script>
               // We are using a customized store to add hooks to connect event
        const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
          if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
            // When we receive DIRECT_LINE/CONNECT_FULFILLED action, we will send an event activity using WEB_CHAT/SEND_EVENT
            dispatch({
              type: 'WEB_CHAT/SEND_EVENT',
              payload: {
                name: 'webchat/join',
                value: { language: window.navigator.language }
              }
            });
          }
          return next(action);
        });
        
        const styleOptions = {
            botAvatarImage: '<<Given Image URL, removed as these are project specific>>',
            botAvatarInitials: 'BF',
            userAvatarImage: '<<Given Image URL, removed as these are project specific>>',
            userAvatarInitials: 'WC',
            bubbleBackground: 'rgba(0, 0, 255, .1)',
            bubbleFromUserBackground: 'rgba(0, 255, 0, .1)'
        };
        window.WebChat.renderWebChat({
            directLine: window.WebChat.createDirectLine({ secret: '<<given my code here as it is secret i have attached this removing the code>>' }),
            // Passing "styleOptions" when rendering Web Chat
            styleOptions
        }, document.getElementById('webchat'));
    </script>
</body>
</html>

我使用SDK 4在C#中创建的聊天机器人,当用户打开浏览器中的WebChatbot时,我正在尝试显示欢迎文本。当前,欢迎文本已在模拟器中显示,但在WebChatbot中没有在发布到Azure后打开Ion浏览器。它仅在我输入一些" hi"之类的东西之后才显示欢迎消息。不应该首先显示欢迎文本,然后我可以输入HI或其他任何内容来继续对话

问题:模拟器中显示的欢迎消息,但在我输入任何内容后仅显示发布后,在WebChat Bot中不显示?应在浏览器中打开WebChatbot后立即显示欢迎消息。

语言:c#

bot sdk:v4

bot Builder软件包:全部最新直到4.4.3通过Nuget

bot仿真器:最新的4.4.1从github发行

下载并安装

在ibot类的Onturnsync方法中,欢迎文本在对话update活动中被调用。下面给出的代码供参考。

请提供帮助,因为我是刚刚进行机器人和编码,通过提供逐步指导?

我已经尝试了一些事情:

  1. 模拟器中的调试但没有帮助

我使用过的代码下方:

public const string WelcomeText = "Welcome!. This bot uses a custom dialog that executes a data driven flow.  Type anything to get started.";
public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{            
    if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate)
    {
        if (turnContext.Activity.MembersAdded != null)
        {
            await SendWelcomeMessageAsync(turnContext, cancellationToken);
        }
    }
}
private static async Task SendWelcomeMessageAsync(ITurnContext turnContext, CancellationToken cancellationToken)
{
    foreach (var member in turnContext.Activity.MembersAdded)
    {
        if (member.Id != turnContext.Activity.Recipient.Id)
        {
            var reply = turnContext.Activity.CreateReply();
            reply.Text = WelcomeText;
            await turnContext.SendActivityAsync(reply, cancellationToken);
        }
    }
}

预期结果:不仅在模拟器中发布后,还应在WebChatbot中显示欢迎文本。
实际结果:仅在模拟器中工作,但在WebChatbot中不工作,仅在我输入任何内容后才显示。

这是关于欢迎用户的常见问题。

在每个频道上抛出的事件并不相同:WebchatEmulator中事件之间的主要区别之一是:

  • 在模拟器上,在对话的开头发送了2个ConversationUpdate事件(添加了1个,其中1个用户添加了1个(
  • 在网络聊天上,仅在用户发送1个消息
  • 之后发送有关用户的ConversationUpdate

因此,要绕过此行为,您可以使用称为backchannel的机制在侧面处理event。在GitHub的存储库上,此用例有一个样本

用几句话,您必须:

  • 从start
  • 发送网络聊天的事件
  • 在机器人侧处理此事件,然后您欢迎消息

最新更新