Created
June 11, 2016 05:27
-
-
Save alvareztech/8a169a0006dc845fdbf610539b48dd83 to your computer and use it in GitHub Desktop.
Codelab: Mi primer bot para Slack. Modificación 2.
This file contains 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
// INICIO CONVERSACIÓN | |
var maxCats = 20 | |
var catEmojis = [ | |
':smile_cat:', | |
':smiley_cat:', | |
':joy_cat:', | |
':heart_eyes_cat:', | |
':smirk_cat:', | |
':kissing_cat:', | |
':scream_cat:', | |
':crying_cat_face:', | |
':pouting_cat:', | |
':cat:', | |
':cat2:', | |
':leopard:', | |
':lion_face:', | |
':tiger:', | |
':tiger2:' | |
] | |
controller.hears( | |
['gato', 'gatos', 'gatito', 'gatitos'], | |
['ambient', 'direct_message', 'direct_mention', 'mention'], | |
function (bot, message) { | |
bot.startConversation(message, function (err, convo) { | |
if (err) { | |
console.log(err) | |
return | |
} | |
convo.ask('¿Quiéres que te envie gatitos? Dime SI o NO.', [ | |
{ | |
pattern: bot.utterances.yes, | |
callback: function (response, convo) { | |
convo.say('¡Genial!') | |
convo.ask('¿Cuantos?', [ | |
{ | |
pattern: '[0-9]+', | |
callback: function (response, convo) { | |
var numCats = | |
parseInt(response.text.replace(/[^0-9]/g, ''), 10) | |
if (numCats === 0) { | |
convo.say({ | |
'text': 'Lo siento pero yo no puedo enviarte cero gatos. ' + | |
'Toma un perro. :dog:', | |
'attachments': [ | |
{ | |
'fallback': 'Chihuahua Bubbles - https://youtu.be/s84dBopsIe4', | |
'text': '<https://youtu.be/s84dBopsIe4|' + | |
'Chihuahua Bubbles>!' | |
} | |
] | |
}) | |
} else if (numCats > maxCats) { | |
convo.say('Lo siento, ' + numCats + ' es muchos gatos.') | |
} else { | |
var catMessage = '' | |
for (var i = 0; i < numCats; i++) { | |
catMessage = catMessage + | |
catEmojis[Math.floor(Math.random() * catEmojis.length)] | |
} | |
convo.say(catMessage) | |
} | |
convo.next() | |
} | |
}, | |
{ | |
default: true, | |
callback: function (response, convo) { | |
convo.say( | |
"Mmmmm no te entiendo. Ingresa un número, por favor.") | |
convo.repeat() | |
convo.next() | |
} | |
} | |
]) | |
convo.next() | |
} | |
}, | |
{ | |
pattern: bot.utterances.no, | |
callback: function (response, convo) { | |
convo.say('Bueno, quizás luego.') | |
convo.next() | |
} | |
}, | |
{ | |
default: true, | |
callback: function (response, convo) { | |
// Repeat the question. | |
convo.repeat() | |
convo.next() | |
} | |
} | |
]) | |
}) | |
}) | |
// FIN CONVERSACIÓN |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment