Created
March 11, 2019 15:09
-
-
Save yasugahira0810/657ed179825c8a71686dc249d69a6624 to your computer and use it in GitHub Desktop.
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 { dialogflow } = require('actions-on-google'); | |
const ambient = require('ambient-lib'); | |
// Ambient Settings | |
const AMBIENT_CHANNEL_ID = XXXX; | |
const AMBIENT_WRITE_KEY = 'YYYYYYYYYYYYYYYY'; | |
const AMBIENT_READ_KEY = 'ZZZZZZZZZZZZZZZZ'; | |
const app = dialogflow(); | |
app.intent('Default Welcome Intent', conv => { | |
conv.ask(`こんにちは`); | |
}); | |
app.intent('Temperature Intent', conv => { | |
// Read Temperature from Ambient | |
var temp; | |
var promise = new Promise(function(resolve, reject) { | |
ambient.connect(AMBIENT_CHANNEL_ID, AMBIENT_WRITE_KEY, AMBIENT_READ_KEY); | |
ambient.read({n: 1}, function(err, res, data) { | |
temp = data[0].d2.toFixed(1); | |
console.log({err: err, data: data}); | |
resolve(temp); | |
}); | |
}); | |
return promise.then(function(value) { | |
conv.close(`${temp}度です`); | |
}); | |
}); | |
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment