dialogflow / dialogflow-fulfillment-nodejs

Dialogflow agent fulfillment library supporting v1&v2, 8 platforms, and text, card, image, suggestion, custom responses
Apache License 2.0
597 stars 282 forks source link

someone help me with this code? #318

Open allantalles opened 3 years ago

allantalles commented 3 years ago

// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs // for Dialogflow fulfillment library docs, samples, and to report issues 'use strict';

const functions = require('firebase-functions'); const {WebhookClient} = require('dialogflow-fulfillment'); const {Card, Suggestion} = require('dialogflow-fulfillment');

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => { const agent = new WebhookClient({ request, response }); console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers)); console.log('Dialogflow Request body: ' + JSON.stringify(request.body));

function welcome(agent) { agent.add(Welcome to my agent!); }

function fallback(agent) { agent.add(I didn't understand); agent.add(I'm sorry, can you try again?); }

function pedido(agent) {

const borda=agent.parameters.borda;
const bebidas=agent.parameters.bebidas;
const sabor=agent.parameters.sabor;

//Variáveis do Pedido
var soma=agent.parameters.sabor + agent.parameters.bebidas + agent.parameters.borda;
var total=agent.parameters.sabor + agent.parameters.bebidas + agent.parameters.borda;
var totalborda=agent.parameters.totalborda;
var totalsabor=agent.parameters.sabor;
var totalbebidas=agent.parameters.bebidas;

//Pizza
  if(sabor==='Calabresa'){
    totalsabor=25.00;
  }
  else if(sabor==='A moda da casa'){
    totalsabor=25.00;
  }
  else if(sabor==='Baiana'){
    totalsabor=25.00;
  }
else if(sabor==='Frango c/ catupiry'){
    totalsabor=25.00;
  }
  else if(sabor==='Strogonoff de carne'){
    totalsabor=25.00;
  }
else if(sabor==='Lombo ao creme'){
    totalsabor=25.00;
  }
  else if(sabor==='Quatro queijos'){
    totalsabor=25.00;
  }
else if(sabor==='Calabresa ao bacon'){
    totalsabor=25.00;
  }
//bordas
if(borda=='Catupiry'){
  totalborda=2.00;
}
else if(borda=='Cheddar'){
  totalborda=4.00;
}
else if(borda=='Sem borda'){
  totalborda=0;
}    

//bebidas
if(bebidas=='Coca cola lata de 350ml'){
  totalbebidas=4.00;
}
else if(bebidas=='Corumba Lata de 600ml'){
  totalbebidas=0;
}
 else if(bebidas=='Guaraná antárctica 1litro'){
  totalbebidas=4.00;
}
else if(bebidas=='CORUBA 2Litros'){
  totalbebidas=6.00;
}
else if(bebidas=='POTY 2Litros'){
  totalbebidas=6.00;
}
else if(bebidas=='ROLLER 2Litros'){
  totalbebidas=6.00;
}
 else if(bebidas=='GUARANÁ ANTÁRCTICA 2Litros'){
  totalbebidas=7.00;
}
else if(bebidas=='FANTA LARANJA 2Litros'){
  totalbebidas=7.00;
}
else if(bebidas=='FANTA UVA 2Litros'){
  totalbebidas=7.00;
}
else if(bebidas=='SPRITE 2Litros'){
  totalbebidas=7.00;
}
 else if(bebidas=='COCA COLA 2Litro'){
  totalbebidas=8.00;
}
else if(bebidas=='COCA COLA 2Litro'){
  totalbebidas=9.00;
}
else if(bebidas=='SUCO DE LARANJA 1Litros'){
  totalbebidas=8.00;
}
else if(bebidas=='SUCO DE MARACUJÁ 1Litros'){
  totalbebidas=8.00;
}
 else if(bebidas=='SUCO DE TAMARINDO 1Litros'){
  totalbebidas=8.00;
}
else if(bebidas=='SUCO DE ABACAXI C/ HORTELÃ 1Litros'){
  totalbebidas=8.00;
}
else if(bebidas=='Sem bebida'){
  totalbebidas=0;
}

total=totalsabor+totalbebidas+totalborda;   

agent.add('======CONFIRA SEU PEDIDO====== '+'\n'+

'👉 Nº PEDIDO:「 _%day_of_month%%hour_of_day%%minute%_ 」'+'\n'+ 'CLIENTE: ' +agent.parameters.nome +'\n'+ 'PIZZA: ' +agent.parameters.sabor+'\n'+ 'BORDA: ' +agent.parameters.borda+'\n'+ 'BEBIDA: ' +agent.parameters.bebidas+'\n'+ 'LOCAL DE ENTREGA: ' +agent.parameters.local+'\n'+ 'PAGAMENTO: ' +agent.parameters.pagamento+' ' +agent.parameters.troco+'\n'+ 'TOTAL: ' +' R$ ' +total+ ' reais');

agent.add('Para confirmar Digite OK ou CANCELAR');

}

// // Uncomment and edit to make your own intent handler // // uncomment intentMap.set('your intent name here', yourFunctionHandler); // // below to get this function to be run when a Dialogflow intent is matched // function yourFunctionHandler(agent) { // agent.add(This message is from Dialogflow's Cloud Functions for Firebase editor!); // agent.add(new Card({ // title: Title: this is a card title, // imageUrl: 'https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png', // text: This is the body text of a card. You can even use line\n breaks and emoji! 💁, // buttonText: 'This is a button', // buttonUrl: 'https://assistant.google.com/' // }) // ); // agent.add(new Suggestion(Quick Reply)); // agent.add(new Suggestion(Suggestion)); // agent.setContext({ name: 'weather', lifespan: 2, parameters: { city: 'Rome' }}); // }

// // Uncomment and edit to make your own Google Assistant intent handler // // uncomment intentMap.set('your intent name here', googleAssistantHandler); // // below to get this function to be run when a Dialogflow intent is matched // function googleAssistantHandler(agent) { // let conv = agent.conv(); // Get Actions on Google library conv instance // conv.ask('Hello from the Actions on Google client library!') // Use Actions on Google library // agent.add(conv); // Add Actions on Google library responses to your agent's response // } // // See https://github.com/dialogflow/dialogflow-fulfillment-nodejs/tree/master/samples/actions-on-google // // for a complete Dialogflow fulfillment library Actions on Google client library v2 integration sample

// Run the proper function handler based on the matched Dialogflow intent name

let intentMap = new Map(); intentMap.set('Default Welcome Intent', welcome); intentMap.set('Default Fallback Intent', fallback); intentMap.set('pedido', pedido);

// intentMap.set('your intent name here', yourFunctionHandler); // intentMap.set('your intent name here', googleAssistantHandler); agent.handleRequest(intentMap); });

BliTz037 commented 3 years ago

What is the problem ?

allantalles commented 3 years ago

The code it is wrong, i need calculate the options which the user choose on whatsapp, but something is wrong, the result never go right.

Obter o Outlook para Androidhttps://aka.ms/ghei36


From: BliTz notifications@github.com Sent: Monday, October 5, 2020 10:18:16 AM To: dialogflow/dialogflow-fulfillment-nodejs dialogflow-fulfillment-nodejs@noreply.github.com Cc: allantalles allantalles@hotmail.com; Author author@noreply.github.com Subject: Re: [dialogflow/dialogflow-fulfillment-nodejs] someone help me with this code? (#318)

What is the problem ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/dialogflow/dialogflow-fulfillment-nodejs/issues/318#issuecomment-703625815, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHL273LXUQGB6PHYKBHRCJ3SJHBRRANCNFSM4R55E34Q.