Skip to content

Instantly share code, notes, and snippets.

@pveller
Last active April 11, 2017 16:34
Show Gist options
  • Save pveller/e5f23161ceb3d43ae92113d7ef75bdcd to your computer and use it in GitHub Desktop.
Save pveller/e5f23161ceb3d43ae92113d7ef75bdcd to your computer and use it in GitHub Desktop.
Conversation Transcript with Bot Framework
// Read more on http://www.pveller.com/smarter-conversations-part-4-transcript/
const transcript = function (session, direction, message, next) {
session.privateConversationData.transcript = session.privateConversationData.transcript || [];
session.privateConversationData.transcript.push({
direction,
message,
timestamp: new Date().toUTCString()
});
if (next) {
session.options.onSave(next);
}
};
bot.on('routing', function (session) {
transcript(session, 'incoming', session.message.text);
});
const journal = (direction) => (message, next) => {
if (message.type === 'message') {
bot.loadSession(message.address, (error, session) => {
transcript(session, direction, message.text, next);
});
} else {
next();
}
};
bot.use({
send: journal('outgoing')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment