首页 文章

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

提问于
浏览
1

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

或者在Directline Webchat收到Bot的回复之后有没有办法调用Javascript函数?

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

    此示例显示机器人如何向WebChat发送 changeBackground 事件并更改页面的backgroundColor .

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

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

相关问题