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

问题描述 投票:1回答:1

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

或者在Directline网络聊天收到Bot的回复之后有没有办法调用Javascript功能?

botframework direct-line-botframework
1个回答
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;
      }

此示例显示了bot如何将changeBackground事件发送到WebChat并更改页面的backgroundColor。

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

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

© www.soinside.com 2019 - 2024. All rights reserved.