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

时间:2017-12-22 15:09:34

标签: botframework direct-line-botframework

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

或者,在Directline网络聊天收到Bot的回复后,有没有办法调用Javascript函数?

1 个答案:

答案 0 :(得分:2)

您可以使用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 事件并更改页面的backgroundColor。

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

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