botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

URL origin webchat from users browser

Open eskivelevolution opened this issue 8 years ago • 2 comments

Hi,

Has a way to get the URL origin webchat (URL from browser that send and receive the messages). I need validate if the URL origin is the URL that instanced the BotFramework.

If I use for example (origin):

BotChat.App({
        directLine: { secret: '{directline_secret}' },
        user: { id: '{user_id}', origin : window.location.href},
        bot: { id: '{bot_id}' },
    }, document.getElementById('bot'));

It can be changed in browser, I need get it from header or more security.

Thank you!

eskivelevolution avatar Jun 14 '18 13:06 eskivelevolution

You'll want to use your bot's directline backchannel to pass information like this. Expanding on what you already have there, here's a bit of example code.

const botConnection = new BotChat.DirectLine({
  secret: "<bot secret>"
});

BotChat.App({
  botConnection:  botConnection,
  user: { id: '{user_id}' },
  bot: { id: '{bot_id' },
  resize: 'detect'
}, document.getElementById("bot"));

//Call this function whenever after the bot is initialized.
function sendOriginUrl(){
  botConnection
  .postActivity({
    from: { id: '{user_id}' },
            name: 'pageURL',
            text: window.location.href,
            type: 'message' //consider making this an event so no message is expected to be posted back
  })
  .subscribe(id=> console.log("Success, url posted" + id));
}

sbuffkin avatar Jun 14 '18 20:06 sbuffkin

Thank you @nyxsys, with this solution I'll block the user to change the url origin?

eskivelevolution avatar Jun 22 '18 02:06 eskivelevolution