Reputation: 71
We are building a MS botframework bot that will be hosted on a website that we control.
Is there a way to pass a session ID from the host website to the web chat bot widget so that it is accessible when processing messages from within the bot?
If not, is it possible to access the 't' token parameter as described here http://docs.botframework.com/connector/embed-chat-control/
Thanks
Upvotes: 1
Views: 2667
Reputation: 159
Using DirectLine and Backchannel might help you here. You'll find the info in the readme on this repo if you scroll to the last section. It allows Webchat and the host can send/receive whatever you want from each other.
<body onload="postLoadMessage()">
<div id="BotChatGoesHere" class="wc-narrow"></div>
<script src="botchat.js"></script>
<script>
var params = BotChat.queryParams(location.search);
var user = { id: '***' };
var bot = { id: '***' };
window['botchatDebug'] = params['debug'] && params['debug'] === "true";
var botConnection = new BotChat.DirectLine({
secret: '****',
token: params['t'],
domain: params['domain'],
webSocket: params['webSocket'] && params['webSocket'] === "true" // defaults to true
});
BotChat.App({
botConnection: botConnection,
user: user,
bot: bot
}, document.getElementById("BotChatGoesHere"));
//var x= whatever value you want to send;
const postLoadMessage = () => {
botConnection
.postActivity({type: "event", value: x , from: {id: "me" }, name: "PageLoaded"})
.subscribe(id => console.log("success"));
}
</script>
</body>
The code given above is how i used it to send value x when the page with the bot is loaded.
I hope this helps :)
Upvotes: 0
Reputation: 11
It's possible to retrieve conversationId, which is available in the Message in your bot. For that you should make POST request to https://webchat.botframework.com/api/conversations with header Authorization with value "BOTCONNECTOR {your secure code}"
You should receive new token and conversationId as a result or request. The token is used in iframe tag creation, conversationId can be used as your session token.
Upvotes: 1
Reputation: 416
Currently there is no way to do this with the chat control.
If you want tighter integration you should consider using the DirectLIne API and build your own UX experience via that.
Upvotes: 3