Created
July 11, 2020 20:58
-
-
Save neuberfran/7e210a229ff93346914d91e253055829 to your computer and use it in GitHub Desktop.
gists importante
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 | |
}); | |
// Imports the Google Cloud client library | |
// async function quickstart( | |
// projectId = 'blink-29d54', // Your Google Cloud Platform project ID | |
// logName = 'neuberfran02' // The name of the log to write to | |
// ) { | |
// // Creates a client | |
// const logging = new Logging({ | |
// projectId | |
// }); | |
// // Selects the log to write to | |
// const log = logging.log(logName); | |
// // The data to write to the log | |
// const text = 'Hello, world!'; | |
// // The metadata associated with the entry | |
// const metadata = { | |
// resource: { | |
// type: 'global' | |
// }, | |
// // See: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity | |
// severity: 'INFO', | |
// }; | |
// // Prepares a log entry | |
// const entry = log.entry(metadata, text); | |
// async function writeLog() { | |
// // Writes the log entry | |
// await log.write(entry); | |
// console.log(`Logged: ${text}`); | |
// } | |
// writeLog(); | |
// } | |
// quickstart(); | |
async function getGpioHandler(agent) { | |
// let doc = db.collection('products').doc('tutorial'); | |
// let observer = doc.onSnapshot(docSnapshot => { | |
// functions.logger.log(`Received doc snapshot: ${docSnapshot}`); | |
// let valor = docSnapshot.data().gpioalarmstate; | |
// functions.logger.log(`Valor valor valor ${valor}`); | |
// agent.add(`Valor valor valor, ${valor}`); | |
// // ... | |
// }, err => { | |
// functions.logger.log(`Encountered error: ${err}`); | |
// }); | |
// db.collection('products').doc('tutorial').update({ gpioalarmstate : true }); | |
const snap = await db.collection('products').doc('tutorial') | |
const data = snap.data() | |
if (!data.gpioalarmstate) { | |
await db.collection('products').doc('tutorial').update({ | |
gpioalarmstate: true | |
}) | |
} | |
agent.add(`Valor valor valor`); | |
} | |
// 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