'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion, Payload} = require('dialogflow-fulfillment');
var answers = [];
var score = {};
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function answerIntroductionHandler(agent){
agent.add(new Card({
title: '1 Faut-il accélérer l’automatisation du métro ?', # pregunta 1
imageUrl: 'http://www.leparisien.fr/resizer/mz-PnB5RECZ1q-z9GDRvlB_3jsg=/932x582/arc-anglerfish-eu-central-1-prod-leparisien.s3.amazonaws.com/public/RJPSM346RO4M5VIDDOS35APBII.jpg'
})
);
agent.add(new Suggestion("Oui"));
agent.add(new Suggestion("Non"));
}
function answer1Handler(agent){
const answer = agent.parameters.Boolean;
if(answer === 'true'){
score.griveaux = (score.griveaux+1) || 1 ;
}else{
}
answers.push(answer);
agent.add(new Card({
title: '2 Faut-il faire payer le stationnement des deux-roues ?', # pregunta 2
imageUrl: 'https://img.autoplus.fr/news/2017/06/28/1517769/c4d017960fb061c5e50cf2c4-1350-900.jpg?r'
})
);
agent.add(new Suggestion("Oui"));
agent.add(new Suggestion("Non"));
}
function answer2Handler(agent){
const answer = agent.parameters.Boolean;
answers.push(answer);
if(answer === 'true'){
score.villani = (score.villani+1) || 1;
}else{
}
console.log(score);
var max = Object.keys(score).reduce(function(a, b){ return score[a] > score[b] ? a : b ;});
agent.add('Vous semblez etre assez proche de ' + max);
}
function answer3Handler(agent){
console.log(agent.parameters);
const answer = agent.parameters.Boolean;
answers.push(answer);
if(answer === 'true'){
score.villani = (score.villani+1) || 1;
}else{
}
console.log(score);
var max = Object.keys(score).reduce(function(a, b){ return score[a] > score[b] ? a : b ;});
agent.add('Vous semblez etre assez proche de ' + max);
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('answerIntroduction', answerIntroductionHandler);
intentMap.set('answer1', answer1Handler);
intentMap.set('answer2', answer2Handler);
agent.handleRequest(intentMap);
});
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion, Payload} = require('dialogflow-fulfillment');
var answers = [];
var score = {};
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function answerIntroductionHandler(agent){
agent.add(new Card({
title: '1 Faut-il accélérer l’automatisation du métro ?', # pregunta 1
imageUrl: 'http://www.leparisien.fr/resizer/mz-PnB5RECZ1q-z9GDRvlB_3jsg=/932x582/arc-anglerfish-eu-central-1-prod-leparisien.s3.amazonaws.com/public/RJPSM346RO4M5VIDDOS35APBII.jpg'
})
);
agent.add(new Suggestion("Oui"));
agent.add(new Suggestion("Non"));
}
function answer1Handler(agent){
const answer = agent.parameters.Boolean;
if(answer === 'true'){
score.griveaux = (score.griveaux+1) || 1 ;
}else{
}
answers.push(answer);
agent.add(new Card({
title: '2 Faut-il faire payer le stationnement des deux-roues ?', # pregunta 2
imageUrl: 'https://img.autoplus.fr/news/2017/06/28/1517769/c4d017960fb061c5e50cf2c4-1350-900.jpg?r'
})
);
agent.add(new Suggestion("Oui"));
agent.add(new Suggestion("Non"));
}
function answer2Handler(agent){
const answer = agent.parameters.Boolean;
answers.push(answer);
if(answer === 'true'){
score.villani = (score.villani+1) || 1;
}else{
}
console.log(score);
var max = Object.keys(score).reduce(function(a, b){ return score[a] > score[b] ? a : b ;});
agent.add('Vous semblez etre assez proche de ' + max);
}
function answer3Handler(agent){
console.log(agent.parameters);
const answer = agent.parameters.Boolean;
answers.push(answer);
if(answer === 'true'){
score.villani = (score.villani+1) || 1;
}else{
}
console.log(score);
var max = Object.keys(score).reduce(function(a, b){ return score[a] > score[b] ? a : b ;});
agent.add('Vous semblez etre assez proche de ' + max);
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('answerIntroduction', answerIntroductionHandler);
intentMap.set('answer1', answer1Handler);
intentMap.set('answer2', answer2Handler);
agent.handleRequest(intentMap);
});
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion, Payload} = require('dialogflow-fulfillment');
var answers = [];
var score = {};
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function answerIntroductionHandler(agent){
agent.add(new Card({
title: '1 Faut-il accélérer l’automatisation du métro ?', # pregunta 1
imageUrl: 'http://www.leparisien.fr/resizer/mz-PnB5RECZ1q-z9GDRvlB_3jsg=/932x582/arc-anglerfish-eu-central-1-prod-leparisien.s3.amazonaws.com/public/RJPSM346RO4M5VIDDOS35APBII.jpg'
})
);
agent.add(new Suggestion("Oui"));
agent.add(new Suggestion("Non"));
}
function answer1Handler(agent){
const answer = agent.parameters.Boolean;
answers.push(answer);
agent.add(new Card({
title: '2 Faut-il faire payer le stationnement des deux-roues ?', # pregunta 2
imageUrl: 'https://img.autoplus.fr/news/2017/06/28/1517769/c4d017960fb061c5e50cf2c4-1350-900.jpg?r'
})
);
agent.add(new Suggestion("Oui"));
agent.add(new Suggestion("Non"));
}
function answer2Handler(agent){
const answer = agent.parameters.Boolean;
answers.push(answer);
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('answerIntroduction', answerIntroductionHandler);
intentMap.set('answer1', answer1Handler);
intentMap.set('answer2', answer2Handler);
agent.handleRequest(intentMap);
});
¿Cómo iterar en los elementos de un archivo json?
Tengo un chatbot DialogFlow donde creo tarjetas con preguntas y respuestas. Las escribí a mano. Sin embargo, tengo esta lista como una pregunta en un archivo json. ¿Cómo puedo acceder a las preguntas y respuestas de mi expediente en lugar de escribirlas a mano? ¿Hay alguna forma de automatizar?
Aquí está el código del editor en línea para mi chatbot
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion, Payload} = require('dialogflow-fulfillment');
var answers = [];
var score = {};
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function answerIntroductionHandler(agent){
agent.add(new Card({
title: '1 Faut-il accélérer l’automatisation du métro ?', # pregunta 1
imageUrl: 'http://www.leparisien.fr/resizer/mz-PnB5RECZ1q-z9GDRvlB_3jsg=/932x582/arc-anglerfish-eu-central-1-prod-leparisien.s3.amazonaws.com/public/RJPSM346RO4M5VIDDOS35APBII.jpg'
})
);
agent.add(new Suggestion("Oui"));
agent.add(new Suggestion("Non"));
}
function answer1Handler(agent){
const answer = agent.parameters.Boolean;
if(answer === 'true'){
score.griveaux = (score.griveaux+1) || 1 ;
}else{
}
answers.push(answer);
agent.add(new Card({
title: '2 Faut-il faire payer le stationnement des deux-roues ?', # pregunta 2
imageUrl: 'https://img.autoplus.fr/news/2017/06/28/1517769/c4d017960fb061c5e50cf2c4-1350-900.jpg?r'
})
);
agent.add(new Suggestion("Oui"));
agent.add(new Suggestion("Non"));
}
function answer2Handler(agent){
const answer = agent.parameters.Boolean;
answers.push(answer);
if(answer === 'true'){
score.villani = (score.villani+1) || 1;
}else{
}
console.log(score);
var max = Object.keys(score).reduce(function(a, b){ return score[a] > score[b] ? a : b ;});
agent.add('Vous semblez etre assez proche de ' + max);
}
function answer3Handler(agent){
console.log(agent.parameters);
const answer = agent.parameters.Boolean;
answers.push(answer);
if(answer === 'true'){
score.villani = (score.villani+1) || 1;
}else{
}
console.log(score);
var max = Object.keys(score).reduce(function(a, b){ return score[a] > score[b] ? a : b ;});
agent.add('Vous semblez etre assez proche de ' + max);
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('answerIntroduction', answerIntroductionHandler);
intentMap.set('answer1', answer1Handler);
intentMap.set('answer2', answer2Handler);
agent.handleRequest(intentMap);
});
Aqui esta mi archivo json de preguntas y respuestas:
{
"Transports": {
"Faut-il accélérer l’automatisation du métro ?": [
"Oui",
"Non"
],
"Faut-il faire payer le stationnement des deux-roues ?": [
"Oui",
"Non"
],
"Faut-il interdire les bus de tourisme dans la capitale ?": [
"Oui",
"Non"
],
"Faut-il piétonniser les quatre arrondissements centraux de la capitale ?": [
"Oui",
"Non"
],
"Faut-il réduire le nombre de places de stationnement en surface ?": [
"Oui",
"Non"
],
"Faut-il rendre le Vélib' gratuit ?": [
"Oui",
"Non"
],
"Faut-il renforcer la vidéoverbalisation ?": [
"Oui",
"Non"
],
"Faut-il rouvrir à la circulation les voies sur berges ?": [
"Oui",
"Non"
],
"Faut-il interdire les trottinettes électriques ? (free floating)": [
"Oui",
"Non"
],
"Le périphérique doit-il...": [
"... être supprimé",
"... comprendre une voie pour bus et covoiturage",
"... être préservé"
],
"Les transports doivent-ils être rendus gratuits...": [
"... uniquement pour les seniors",
"... pour les mineurs et les seniors",
"... pour tout le monde",
"Non, ils doivent rester payants"
]
},
"Sports et Loisirs": {
"Faut-il demander l'annulation des Jeux olympiques ?": [
"Oui",
"Non"
],
"Faut-il mettre fin à la pratique du tirage au sort pour le conservatoire ?": [
"Oui",
"Non"
]
}
}
default