Last active
October 23, 2018 07:28
-
-
Save eblancoh/32a4d8986b9ecd4491098d6db5fffe46 to your computer and use it in GitHub Desktop.
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
// Receive messages from the user and respond by echoing each message back (prefixed with 'You said:') | |
const bot = new builder.UniversalBot(connector, [ | |
(session, results, next) => { | |
session.preferredLocale('es', (err) => { | |
if (err) { | |
session.error('error'); | |
} | |
session.send("Bienvenido al Chatbot Eco de Luca"); | |
next(); | |
}); | |
}, | |
(session, results, next) => { | |
const choices = ["Favoritos", "Dirección"] | |
const card = new builder.ThumbnailCard(session) | |
.text('¿Qué prefieres usar, localizaciones favoritas o introducir una dirección?') | |
.title('Elección ubicaciones') | |
.buttons(choices.map(choice => new builder.CardAction.imBack(session, choice, choice))); | |
const message = new builder.Message(session) | |
.addAttachment(card); | |
builder.Prompts.choice(session, message, choices); | |
next(); | |
}, | |
(session, results, next) => { | |
if (results.response && results.response.entity) { | |
var dialogResult = (results.response.entity === "Favoritos" ? 'locationfavorites' : 'locationBot'); | |
session.beginDialog(dialogResult, null); | |
} else { | |
session.cancelDialog(); | |
} | |
}, | |
(session, results, next) => { | |
session.dialogData.place = results.response; | |
next(); | |
}, | |
(session, args, next) => { | |
const choices = ['12 horas', '24 horas', '48 horas'] | |
const card = new builder.ThumbnailCard(session) | |
.text('¿Cuántas horas va a permanecer en la dirección de interés indicada?') | |
.title('Período de predicción') | |
.buttons(choices.map(choice => new builder.CardAction.imBack(session, choice, choice))); | |
const message = new builder.Message(session) | |
.addAttachment(card); | |
builder.Prompts.choice(session, message, choices); | |
next(); | |
}, | |
(session, results, next) => { | |
if (results.response && results.response.entity) { | |
session.dialogData.forecastperiod = results.response.entity; | |
const dateRange = getDateRange(session); | |
// The payload to be provided to LUCA API is created here | |
// const payload = { | |
// address: session.dialogData.place.streetAddress, | |
// start: dateRange.start, | |
// end: dateRange.end | |
// }; | |
// console.log('payload ===>', payload); | |
const address = session.dialogData.place.streetAddress; | |
var image = ""; | |
switch(address) { | |
case "Calle Gran Vía, 31": | |
case "Calle Gran Vía": | |
case "gran_via": | |
image = "https://botinvokatorae46.blob.core.windows.net/images/granvia.png"; | |
statusLabel = "La calidad del aire será BUENA, no se prevén restricciones de tráfico."; | |
break; | |
case "Calle de Orense, 21": | |
case "Calle Orense, 21": | |
case "Calle Orense": | |
case "orense_madrid": | |
image = "https://botinvokatorae46.blob.core.windows.net/images/orense.png"; | |
statusLabel = "La calidad del aire será ADMISIBLE, el máximo de contaminación será en 5h"; | |
break; | |
case "Paseo de la Chopera": | |
case "paseo_chopera": | |
image = "https://botinvokatorae46.blob.core.windows.net/images/paseochopera.png"; | |
statusLabel = "La calidad del aire será ADMISIBLE, el máximo de contaminación será en 5h"; | |
break; | |
case "Plaza de Castilla": | |
case "plaza_castilla": | |
image = "https://botinvokatorae46.blob.core.windows.net/images/plazacastilla.png"; | |
statusLabel = "La calidad del aire será ADMISIBLE, el máximo de contaminación será en 5h"; | |
break; | |
case "Distrito Telefonica": | |
case "distrito_telefonica": | |
image = "https://botinvokatorae46.blob.core.windows.net/images/distritotelefonica.png"; | |
statusLabel = "La calidad del aire será ADMISIBLE, el máximo de contaminación será en 5h"; | |
break; | |
default: | |
image = "https://botinvokatorae46.blob.core.windows.net/images/granvia.png"; | |
statusLabel = "La calidad del aire será BUENA, no se prevén restricciones de tráfico."; | |
break; | |
}; | |
session.send({ | |
text: "", | |
attachments: [ | |
{ | |
contentType: "image/jpeg", | |
contentUrl: image, | |
name: "Previsión" | |
} | |
] | |
}); | |
const msg = new builder.Message(session).addAttachment(createHeroCard(session)); | |
session.send(msg); | |
session.send('¡Muchas gracias por hacer uso del servicio!'); | |
session.endDialog(); | |
} else { | |
session.send('Lo siento, no he entendido tu elección.'); | |
} | |
} | |
]).set('storage', inMemoryStorage); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment