Created
August 24, 2017 02:23
-
-
Save KhanMaytok/77a925ddd5f5bd15db48523afdd49bfa to your computer and use it in GitHub Desktop.
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
// Maytok Boot | |
const BootBot = require('bootbot'); | |
const bot = new BootBot({ | |
accessToken: 'EAAWXYjB4XLcBADPoDZCVfAGyzAGwpvdhLlQNKkfGvtj6C8ez5TPDZAVZAYQwnqZAWw3ZC6pLEoya0kRZA0Q4z6zszq1K0at8mRTZAfNSGF05cLus96yyHKFeesIKmo7tkaknKtUYbEfbGiop68TeQQMBR4sjxeZAZBwdBWLZCQDhJMGPgdbTPkMoeA', | |
verifyToken: 'perita', | |
appSecret: '8e9fb9de00925f56778947b8f6ec54d4' | |
}); | |
bot.hear(['hola', 'hello' , 'hi', /hey( there)?/i], (payload, chat) => { | |
// Send a text message followed by another text message that contains a typing indicator | |
chat.say('Hola, amigo').then(() => { | |
chat.say('Soy un bot para test, una prueba de contexto. ¿Qué deseas aprender de mi?', { typing: true }).then(() => { | |
chat.say({ | |
text: 'Escoje con cuidado, joven aprendiz', | |
buttons: [ | |
{ type: 'postback', title: 'Precios', payload: 'PB_PRICES' }, | |
{ type: 'postback', title: 'Cuéntame un chiste', payload: 'PB_JOKE' } | |
] | |
}); | |
}); | |
}); | |
}); | |
bot.hear([/mierda?/i, /puto?/i], (payload, chat) => { | |
// Send a text message with quick replies | |
chat.say('No hay por que ser maleducado', { typing: true }); | |
}); | |
bot.hear(['help'], (payload, chat) => { | |
// Send a text message with buttons | |
chat.say({ | |
text: 'What do you need help with?', | |
buttons: [ | |
{ type: 'postback', title: 'Settings', payload: 'HELP_SETTINGS' }, | |
{ type: 'postback', title: 'FAQ', payload: 'HELP_FAQ' }, | |
{ type: 'postback', title: 'Talk to a human', payload: 'HELP_HUMAN' } | |
] | |
}); | |
}); | |
bot.hear('Preguntame algo', (payload, chat) => { | |
chat.conversation((convo) => { | |
askName(convo); | |
}); | |
}); | |
const askName = (convo) => { | |
convo.ask(`Cuál es tu nombre?`, (payload, convo) => { | |
const text = payload.message.text; | |
convo.set('name', text); | |
convo.say(`Así que tu nombre es ${text}`).then(() => askFavoriteFood(convo)); | |
}); | |
}; | |
const askFavoriteFood = (convo) => { | |
convo.ask(`Cual es tu platillo favorito?`, (payload, convo) => { | |
const text = payload.message.text; | |
convo.set('food', text); | |
convo.say(`Oh a mi tambien me encanta comer ${text}`).then(() => sendSummary(convo)); | |
}); | |
}; | |
const sendSummary = (convo) => { | |
convo.say(`Ahora se de ti estas cosas: | |
- Nombre: ${convo.get('name')} | |
- Te encanta comer: ${convo.get('food')}`); | |
convo.end(); | |
}; | |
bot.on('postback:PB_PRICES', (payload, chat) => { | |
chat.say({ | |
attachment: 'image', | |
url: 'http://1.bp.blogspot.com/-0angqtZ0Qy0/VX681EQcDKI/AAAAAAABASQ/y8ONdwHc0wU/s1600/garra-espada-valyria.jpg' | |
}).then(function(){ | |
chat.say('¿Que te parece esta fina espada de acero valyrio?', { typing: true }); | |
}).then(function(){ | |
chat.say({ | |
text: 'Imbuida con poderes especiales contra caminantes blancos', | |
buttons: [ | |
{ type: 'postback', title: 'Me lo llevo', payload: 'PB_BUY' }, | |
{ type: 'postback', title: 'Ahorita no, joven', payload: 'PB_NO' } | |
], | |
typing: true | |
}); | |
}); | |
}); | |
bot.on('postback:PB_JOKE', (payload, chat) => { | |
console.log('Joke postback'); | |
chat.say('Ahorita no, joven', { typing: true }).then(function(){ | |
chat.say('Mi creador estaba demasiado ocupado para rellenarme con chistes graciosos. No es mi culpa, es mi programacion', { typing: true }); | |
}); | |
}); | |
bot.on('postback:PB_BUY', (payload, chat) => { | |
console.log('Joke postback'); | |
chat.say('Genial, la orden de compra ha sido enviada.', { typing: true }) | |
}); | |
bot.on('postback:PB_NO', (payload, chat) => { | |
console.log('Joke postback'); | |
chat.say('Descuida, regresa cuando quieras.', { typing: true }) | |
}); | |
bot.start(4000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment