Skip to content

Instantly share code, notes, and snippets.

@raykibul
Created March 9, 2020 20:10
Show Gist options
  • Select an option

  • Save raykibul/4bf7a454a6c1b56abb2cb32ee99efeee to your computer and use it in GitHub Desktop.

Select an option

Save raykibul/4bf7a454a6c1b56abb2cb32ee99efeee to your computer and use it in GitHub Desktop.
This is dialogflow inline editor code for firebase realtime database
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const admin= require ('firebase-admin');
admin.initializeApp({
credential:admin.credential.applicationDefault(),
databaseURL:'ws://myresturent-wrjlyh.firebaseio.com/'
});
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 OrderNowFuction(agent){
const food=agent.parameters.foodvalue;
const phone =agent.parameters.phonevalue;
const address=agent.parameters.addressvalue;
return admin.database().ref('orders').set({
food_item:food,
user_phone:phone,
user_location:address
});
}
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('OrderNow', OrderNowFuction);
// intentMap.set('your intent name here', googleAssistantHandler);
agent.handleRequest(intentMap);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment