Sandip
Sandip

Reputation: 262

How to Reload Web Application using Directline Webchat?

How to Reload Web Application using Directline Webchat ?

Or Is there any way to call Javascript function after Directline Webchat recieve response from Bot?

Upvotes: 1

Views: 415

Answers (1)

Eric Dahlvang
Eric Dahlvang

Reputation: 8292

You could use the WebChat control's BackChannel for this:

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

This example shows how a bot could send a changeBackground event to WebChat and have the backgroundColor of the page changed.

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

Instead of a changeBackground event, you can send a reloadPage event and call location.reload() in javascript.

Upvotes: 2

Related Questions