Skip to content

Instantly share code, notes, and snippets.

@corpr8
Created February 8, 2017 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corpr8/65a3e1958d3c5de32a26331b8cf4a472 to your computer and use it in GitHub Desktop.
Save corpr8/65a3e1958d3c5de32a26331b8cf4a472 to your computer and use it in GitHub Desktop.
// Core dependency
const talkify = require('talkify');
const Bot = talkify.Bot;
// Types dependencies
const BotTypes = talkify.BotTypes;
const Message = BotTypes.Message;
const SingleLineMessage = BotTypes.SingleLineMessage;
const MultiLineMessage = BotTypes.MultiLineMessage;
// Skills dependencies
const Skill = BotTypes.Skill;
// Training dependencies
const TrainingDocument = BotTypes.TrainingDocument;
var bots = []
var trainBots = function(callback){
bots.push(new Bot())
//const bot = new Bot();
//topic, content
bots[0].trainAll([
new TrainingDocument('how_are_you', 'how are you'),
new TrainingDocument('how_are_you', 'how are you going'),
new TrainingDocument('how_are_you', 'how is it going'),
new TrainingDocument('help', 'how can you help'),
new TrainingDocument('help', 'i need some help'),
new TrainingDocument('help', 'how could you assist me'),
new TrainingDocument('displaySomething', 'send news to screen1'),
new TrainingDocument('displaySomething', 'show me system status on screen one'),
new TrainingDocument('displaySomething', 'news on screen one please'),
new TrainingDocument('displaySomething', 'play news on screen 1'),
new TrainingDocument('displaySomething', 'send news to screen2'),
new TrainingDocument('displaySomething', 'show me a news update on screen1'),
new TrainingDocument('displaySomething', 'news screen two'),
new TrainingDocument('displaySomething', 'news on screen 2 please'),
], function() {
//done training
bots.push(new Bot())
bots[1].trainAll([
new TrainingDocument('screen1', 'screen one'),
new TrainingDocument('screen1', 'screen 1'),
new TrainingDocument('screen1', 'screen1'),
new TrainingDocument('screen1', 'left screen'),
new TrainingDocument('screen2', 'screen two'),
new TrainingDocument('screen2', 'right screen'),
new TrainingDocument('screen2', 'screen 2'),
new TrainingDocument('screen2', 'screen2')
], function() {
//done training
bots.push(new Bot())
bots[2].trainAll([
new TrainingDocument('news', 'BBC news'),
new TrainingDocument('news', 'the latest headlines'),
new TrainingDocument('news', 'whats goin on today'),
new TrainingDocument('systemStatus', 'system status'),
new TrainingDocument('systemStatus', 'your status')
], function() {
//done training
callback();
});
});
});
}
var resolveQuery = function(context, query, callback){
bots[0].resolve(context, query, function(err, thisMessage){
//console.log(thisMessage)
if(err) return console.error(err);
bots[1].resolve(context, query, function(err, thisDestination){
//console.log(thisDestination)
if(err) return console.error(err);
bots[2].resolve(context, query, function(err, thisSubject){
//console.log(thisSubject)
if(err) return console.error(err);
callback(thisMessage, thisDestination, thisSubject)
})
})
})
}
trainBots(function(){
var howAction = function(context, request, response, next) {
response.message = new SingleLineMessage('You asked: \"' + request.message.content + '\". I\'m doing well. Thanks for asking.');
next();
};
var helpAction = function(context, request, response, next) {
response.message = new SingleLineMessage('You asked: \"' + request.message.content + '\". I can tell you how I\'m doing if you ask nicely.');
next();
};
var displaySomethingAction = function(context, request, response, next) {
response.message = new SingleLineMessage('display something');
next();
};
//name, topic, function
var howSkill = new Skill('how_skill', 'how_are_you', howAction);
var helpSkill = new Skill('help_skill', 'help', helpAction);
var displaySomethingSkill = new Skill('displaySomething', 'displaySomething', displaySomethingAction);
bots[0].addSkill(howSkill);
bots[0].addSkill(helpSkill);
bots[0].addSkill(displaySomethingSkill);
var screen1Action = function(context, request, response, next) {
response.message = new SingleLineMessage('on screen1');
next();
};
var screen2Action = function(context, request, response, next) {
response.message = new SingleLineMessage('on screen2');
next();
};
//name, topic, function
var screen1Skill = new Skill('screen1Skill', 'screen1', screen1Action);
var screen2Skill = new Skill('screen2Skill', 'screen2', screen2Action);
bots[1].addSkill(screen1Skill);
bots[1].addSkill(screen2Skill);
var newsAction = function(context, request, response, next) {
response.message = new SingleLineMessage('https://news.bbc.co.uk');
next();
};
var systemStatusAction = function(context, request, response, next) {
response.message = new SingleLineMessage('http://localhost/something');
next();
};
//name, topic, function
var newsSkill = new Skill('newsSkill', 'news', newsAction);
var systemStatusSkill = new Skill('systemStatusSkill', 'systemStatus', systemStatusAction);
bots[2].addSkill(newsSkill);
bots[2].addSkill(systemStatusSkill);
resolveQuery(123, "send news to screen1", function(thisMessage, thisDestination, thisSubject){
console.log(thisMessage, thisDestination, thisSubject)
})
resolveQuery(123, "show system status on screen two", function(thisMessage, thisDestination, thisSubject){
console.log(thisMessage, thisDestination, thisSubject)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment