Created
July 9, 2020 18:06
-
-
Save neuberfran/b89807a209219aa20e0a9c2832bfa921 to your computer and use it in GitHub Desktop.
dialogflow file
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
'use strict'; | |
const functions = require('firebase-functions'); | |
const { | |
Logging | |
} = require('@google-cloud/logging'); | |
const { | |
WebhookClient | |
} = require('dialogflow-fulfillment'); | |
const admin = require('firebase-admin'); | |
admin.initializeApp(); | |
const db = admin.firestore(); | |
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements | |
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => { | |
const agent = new WebhookClient({ | |
request, response }); | |
const logging = new Logging(); | |
const log = logging.log(logName); | |
// function getLogEntries() { | |
// const logging = Logging(); | |
// const options = { | |
// pageSize: 10, | |
// filter: 'resource.type="cloud_function"' | |
// }; | |
// return logging.getEntries(options) | |
// .then(([entries]) => { | |
// console.log('Entries:'); | |
// entries.forEach((entry) => console.log(entry)); | |
// return entries; | |
// }); | |
// } | |
async function printEntryMetadata() { | |
const [entries] = await log.getEntries(); | |
console.log('Logs:'); | |
entries.forEach(entry => { | |
const metadata = entry.metadata; | |
console.log(`${metadata.timestamp}:`, metadata[metadata.payload]); | |
}); | |
} | |
printEntryMetadata(); | |
function getGpioHandler(agent) { | |
let doc = db.collection('products').doc('tutorial'); | |
let observer = doc.onSnapshot(docSnapshot => { | |
console.log(`Received doc snapshot: ${docSnapshot}`); | |
let valor = docSnapshot.data().gpioalarmstate; | |
console.log(`Valor valor valor ${valor}`); | |
// ... | |
}, err => { | |
console.log(`Encountered error: ${err}`); | |
}); | |
// db.collection('products').doc('tutorial').update({ "gpioalarmstate" : true }); | |
// function getGpioHandler( agent ){ | |
// var gpioalarmstate = agent.parameters.gpioalarmstate; | |
// return db.collection('products').doc(tutorial).get() | |
// .then( doc => { | |
// var gpiogaragestate = doc.data(); | |
// agent.add(`Alarms is ${gpioalarmstate} garage is ${gpiogaragestate}.`); | |
// }); | |
// } | |
} | |
let intentMap = new Map(); | |
intentMap.set('Jfran Intent', getGpioHandler); | |
agent.handleRequest(intentMap); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment