【问题标题】:How to Reload Web Application using Directline Webchat?如何使用 Directline Webchat 重新加载 Web 应用程序?
【发布时间】:2017-12-23 03:42:13
【问题描述】:

如何使用 Directline Webchat 重新加载 Web 应用程序?

或者有什么方法可以在 Directline Webchat 收到 Bot 的响应后调用 Javascript 函数?

【问题讨论】:

    标签: botframework direct-line-botframework


    【解决方案1】:

    您可以为此使用 WebChat 控件的 BackChannel:

          const user = {
            id: 'userid',
            name: 'username'
          };
          const bot = {
            id: 'botid',
            name: 'botname'
          };
    
         const botConnection = new BotChat.DirectLine({
            secret: 'SECRET'
          });
    
          BotChat.App({
            bot: bot,
            botConnection: botConnection,
            user: user
          }, document.getElementById('BotChatGoesHere'));
    
          botConnection.activity$
            .filter(function (activity) {
              return activity.type === 'event' && activity.name === 'changeBackground';
            })
            .subscribe(function (activity) {
              console.log('"changeBackground" received with value: ' + activity.value);
              changeBackgroundColor(activity.value);
            });
    
          function changeBackgroundColor(newColor) {
            document.body.style.backgroundColor = newColor;
          }
    

    此示例展示了机器人如何向 WebChat 发送 changeBackground 事件并更改页面的背景颜色。

    来自: https://github.com/Microsoft/BotFramework-WebChat/blob/master/samples/backchannel/index.html

    您可以发送 reloadPage 事件并在 javascript 中调用 location.reload(),而不是 changeBackground 事件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-18
      • 2012-06-22
      • 2016-09-13
      • 1970-01-01
      • 2022-11-19
      • 2019-07-25
      相关资源
      最近更新 更多