-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
223 lines (194 loc) · 7.92 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// This loads the environment variables from the .env file
require('dotenv-extended').load();
var builder = require('botbuilder');
var restify = require('restify');
var Store = require('./store');
var spellService = require('./spell-service');
// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
console.log("listen")
});
// Create connector and listen for messages
var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
server.post('/api/messages', connector.listen());
var bot = new builder.UniversalBot(connector, function (session) {
session.send('Dijiste \'%s\', verdad? Habláme en argentino o no entenderé un carajo. Teclea \'help\' si nesesitá ashuda al respecto.', session.message.text);
});
// You can provide your own model by specifing the 'LUIS_MODEL_URL' environment variable
// This Url can be obtained by uploading or creating your model from the LUIS portal: https://www.luis.ai/
var recognizer = new builder.LuisRecognizer(process.env.LUIS_MODEL_URL);
bot.recognizer(recognizer);
var inMemoryStorage = new builder.MemoryBotStorage();
var intervalSet = false;
bot.set('storage', inMemoryStorage)
bot.dialog('searchGif', [
function (session, args, next) {
console.log("hola")
// try extracting entities
var gif = builder.EntityRecognizer.findEntity(args.intent.entities, 'typeGif');
if (gif) {
// gif entity detected, continue to next step
next({ gif: gif.entity });
} else {
// no entities detected, ask user for a gif
builder.Prompts.text(session, 'Pibe, si no espesificás el tipo de gif no puedo aser nada');
}
},
function (session, results) {
var gif = results.gif;
var message = 'EESSAAA!!! Buscando gifs de chicas, digoo de %s';
session.send(message, gif);
// Async search
Store.searchGif(gif)
.then(function (gifs) {
// args
var message = new builder.Message()
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments(gifs.map(gifAsAttachment));
session.send(message);
// End
session.endDialog();
});
}
]).triggerAction({
matches: 'searchGif',
onInterrupted: function (session) {
session.send('Conexión interrumpida');
}
});
bot.dialog('help', [
function (session, results) {
var message = new builder.Message()
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments([new builder.HeroCard()
.title("El Mesías Gastón siempre a su servicio")
.images([new builder.CardImage().url('https://image.ibb.co/dYCBGw/gaston_mesias.jpg')])
])
session.send(message);
message = 'Prueba a poner "muestrame un gif de gatitos" por ejemplo';
session.send(message);
session.endDialog();
}
]).triggerAction({
matches: 'help',
onInterrupted: function (session) {
session.send('Conexión interrumpida');
session.endDialog()
}
});
bot.dialog('hello', [
function (session, results) {
var message = new builder.Message()
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments([new builder.HeroCard()
.images([new builder.CardImage().url('https://image.ibb.co/fSyOUG/IMG_20180112_WA0001.jpg')])
])
session.send(message);
session.send("HEY PIBE COMO ANDÁS? Justo me pillas en el gym, pero pídeme lo que quieras")
session.endDialog()
if(!intervalSet) {
intervalSet = true;
setInterval(() => {
var date = new Date();
var hour = date.getHours();
var minutes = date.getMinutes();
if(hour == 10 && minutes == 30) session.send("Boludo, recuerda pedir comida en las encarnas")
if(hour == 11 && minutes == 25) session.send("CHUIII, CHUIII, CHUIII, Nostrum en 5 minutos, quien se viene?")
var randomMessages = [
"Tranquilo, todavia no es hora de ir al nostrum",
"Esta noche salimos",
"Eh, te gusta la noche?",
"Que viva el fuuuuuuuuutbol",
"VIVA EL VINO DE CARTÓN",
"PARÁ, PARÁ",
"Mandale recuerdos a pere Benegol",
"Pere Benedetto!",
"Ese Piquéeee",
"Un Ping pong?"
]
var number = Math.random() * (9 - 0) + 0;
session.send(randomMessages[Math.floor(number)])
}, 30000);
}
}
]).triggerAction({
matches: 'hello',
onInterrupted: function (session) {
session.send('Conexión interrumpida');
session.endDialog()
}
});
bot.dialog('singSomething', [
function (session, results) {
return new builder.AudioCard(session)
.title('I am your father')
.subtitle('Star Wars: Episode V - The Empire Strikes Back')
.text('The Empire Strikes Back (also known as Star Wars: Episode V – The Empire Strikes Back) is a 1980 American epic space opera film directed by Irvin Kershner. Leigh Brackett and Lawrence Kasdan wrote the screenplay, with George Lucas writing the film\'s story and serving as executive producer. The second installment in the original Star Wars trilogy, it was produced by Gary Kurtz for Lucasfilm Ltd. and stars Mark Hamill, Harrison Ford, Carrie Fisher, Billy Dee Williams, Anthony Daniels, David Prowse, Kenny Baker, Peter Mayhew and Frank Oz.')
.image(builder.CardImage.create(session, 'https://upload.wikimedia.org/wikipedia/en/3/3c/SW_-_Empire_Strikes_Back.jpg'))
.media([
{ url: 'http://www.wavlist.com/movies/004/father.wav' }
])
.buttons([
builder.CardAction.openUrl(session, 'https://en.wikipedia.org/wiki/The_Empire_Strikes_Back', 'Read More')
]);
// console.log("singing")
// try {
// return new builder.AudioCard(session)
// .title('Aquí tenés la cansión')
// .subtitle('Pere benegoool!!!!')
// .media([
// { url: 'http://www.wavlist.com/movies/004/father.wav' }
// ]);
// } catch (error) {
// console.log(error)
// }
}
]).triggerAction({
matches: 'singSomething',
onInterrupted: function (session) {
session.send('Conexión interrumpida');
session.endDialog()
}
});
bot.dialog('nostrum', [
function (session, results) {
session.send("CHUIIIII! Cada día a las 11:30, NO PODÉS FALTAR");
session.endDialog();
}
]).triggerAction({
matches: 'nostrum',
onInterrupted: function (session) {
session.send('Conexión interrumpida');
session.endDialog()
}
});
// Spell Check
if (process.env.IS_SPELL_CORRECTION_ENABLED === 'true') {
console.log("spellcheck active")
bot.use({
botbuilder: function (session, next) {
spellService
.getCorrectedText(session.message.text)
.then(function (text) {
session.message.text = text;
next();
})
.catch(function (error) {
console.error(error);
next();
});
}
});
}
// Helpers
function gifAsAttachment(gif) {
return new builder.HeroCard()
.title(gif.name)
.subtitle('Proporcionado por el pibe gastón')
.images([new builder.CardImage().url(gif.image)]);
}