botframework-sdk
botframework-sdk copied to clipboard
URL origin webchat from users browser
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!
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));
}
Thank you @nyxsys, with this solution I'll block the user to change the url origin?