Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const request = require('request');
const get = (url) => new Promise((resolve, reject) => {
request.get({
url: url,
json: true
}, (error, res, json) => {
if (error) {
return reject(error);
}
resolve(json);
});
});
const post = (url) => new Promise((resolve, reject) => {
request.post({
url: url,
json: true
}, (error, res, json) => {
if (error) {
return reject(error);
}
resolve(json);
});
});
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 lightOn(agent) {
agent.add(`つけました`);
const url = '<RunKitの点灯用エンドポイントのURL>';
return get(url).then(responsedJson => {})
}
function lightOff(agent) {
agent.add(`消しました`);
const url = 'RunKitの消灯用エンドポイントのURL';
return get(url).then(responsedJson => {})
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('Light On Intent', lightOn);
intentMap.set('Light Off Intent', lightOff);
agent.handleRequest(intentMap);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.