I'm trying to pass additional channel data through to my C# back end via the web chat html template supplied by Microsoft, and I'm having no luck.
I've read so many blog posts around this, but I have no idea how these guys got it to work, as I'm always getting a 502 Bad Gateway with every post.
My bot App initialization in the HTML looks like this:
// removed my token for brevity
var connection = new BotChat.DirectLine({
token: "{secret}",
webSocket: true
});
function getBotConnectionDetail(botconnection) {
var botConnectionDetail = {};
var keys = Object.keys(botconnection);
for (var i = 0; i < keys.length; i++) {
botConnectionDetail[keys[i]] = botconnection[keys[i]];
};
botConnectionDetail['postActivity'] = function (activity) {
activity.channelData = {
Username: 'John Doe'
};
return botconnection.postActivity(activity);
};
return botConnectionDetail;
}
BotChat.App({
botConnection: getBotConnectionDetail(connection),
user: { id: "Yo" },
bot: { id: "Yo" },
resize: "window"
},
document.getElementById("bot"));
this example is loosely based on the following blogs and github tickets I've tried, below.
Either this is a new bug introduced on the DirectlineJS component, or this never worked. Any help would be greatly appreciated.
Sending channelData to webchat with each message
https://github.com/Microsoft/BotBuilder/issues/15
https://github.com/Microsoft/BotBuilder/issues/201
https://github.com/Microsoft/BotFramework-WebChat/issues/142
Update
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Bot Chat</title>
<title>Siza</title>
<link href="webview/webview.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans" />
<style>
html, body {
height: 100%;
margin: 0;
overflow: hidden;
padding: 0;
}
</style>
</head>
<body>
<div id="bot"></div>
<script src="webview/botchat.js"></script>
<script>
var connection = new BotChat.DirectLine({
secret: "{secret}",
webSocket: true
});
function getBotConnectionDetail(botconnection) {
var botConnectionDetail = {};
var keys = Object.keys(botconnection);
for (var i = 0; i < keys.length; i++) {
botConnectionDetail[keys[i]] = botconnection[keys[i]];
};
botConnectionDetail['postActivity'] = function (activity) {
activity.channelData = {
Username: 'John Doe'
};
return botconnection.postActivity(activity);
};
return botConnectionDetail;
}
BotChat.App({
botConnection: getBotConnectionDetail(connection),
user: { id: "Yo" },
bot: { id: "Yo" },
resize: "window"
},
document.getElementById("bot"));
</script>
</body>
</html>