Created
July 9, 2020 16:32
-
-
Save neuberfran/6cf226c92de0b3afb22be28d9dcc5043 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 | |
}); | |
function getLogEntries() { | |
// Instantiates a client | |
const logging = Logging(); | |
const options = { | |
pageSize: 10, | |
filter: 'resource.type="cloud_function"' | |
}; | |
// Retrieve the latest Cloud Function log entries | |
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/logging | |
return logging.getEntries(options) | |
.then(([entries]) => { | |
console.log('Entries:'); | |
entries.forEach((entry) => console.log(entry)); | |
return entries; | |
}); | |
} | |
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}`); | |
}); | |
} | |
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