Last active
April 11, 2017 16:34
-
-
Save pveller/e5f23161ceb3d43ae92113d7ef75bdcd to your computer and use it in GitHub Desktop.
Conversation Transcript with Bot Framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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