Skip to content

Instantly share code, notes, and snippets.

@jakkaj
Created August 1, 2017 05:56
Show Gist options
  • Save jakkaj/637cfb19f6e7d3cac3e26fd82b3640c8 to your computer and use it in GitHub Desktop.
Save jakkaj/637cfb19f6e7d3cac3e26fd82b3640c8 to your computer and use it in GitHub Desktop.
Set session data in back channel
bot.dialog('/SetUser',
(session, args, next) => {
session.conversationData.user = args.result.user;
session.endDialog(`Okay set user`);
}
);
// bot listening for inbound backchannel events
bot.on('event', function (event) {
bot.beginDialog(event.address, "*:/SetUser", {result:{user:event.value}});
});
//once the thing has loaded, type help to see the user responded.
bot.dialog('Help',
(session, args, next) => {
var user = session.conversationData.user
session.endDialog(`${user} I'm the help desk bot and I can help you create a ticket or explore the knowledge base.\n` +
`You can tell me things like _I need to reset my password_ or _explore hardware articles_.`);
}
).triggerAction({
matches: /^help$/i
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link href="https://unpkg.com/botframework-webchat/botchat.css" rel="stylesheet" />
<style>
.wc-chatview-panel {
width: 400px;
margin: 0 auto;
border: 1px solid black;
}
aside {
font-size: 12px;
font-family: Arial, Helvetica, sans-serif;
position: absolute;
width: calc((100% - 420px) / 2);
right: 0;
color: #3a96dd;
}
aside div {
color: black;
}
#results h3 {
margin-top: 0;
margin-bottom: 0;
cursor: pointer;
}
#results span {
color: #006621;
}
#results p {
margin-top: 0;
word-wrap: break-word;
font-weight: normal;
}
</style>
</head>
<body>
<div id="bot">
</div>
<aside>
<h1>The user might be interested in some of these related articles:</h1>
<div id="results">
<p>No insights yet!</p>
</div>
</aside>
<script src="https://unpkg.com/botframework-webchat/botchat.js"></script>
<script>
var botConnection = new BotChat.DirectLine({
secret: '<directline secret>'
});
var resPanel = document.getElementById('results');
BotChat.App({
botConnection: botConnection,
user: { id: 'WebChatUser' },
bot: { id: '<bot id>' },
locale: 'en-us',
}, document.getElementById('bot'));
// catch incomming backchannel "event"
function send() {
botConnection
.postActivity({
type: 'event',
value: "Jordan",
from: { id: 'user' },
name: 'showDetailsOf'
})
.subscribe(function (id) {
console.log('event sent', id);
});
}
send();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment