【发布时间】:2018-11-23 13:31:36
【问题描述】:
所以我刚开始做一个项目。我遇到了两种不同的用于 Google 操作代理的 webhook 实现。谁能解释一下,两者有什么区别?
还有哪个更可扩展。
第一个使用actions-on-google库,
'use strict';
// Imports
// =================================================================================================
const { dialogflow } = require('actions-on-google');
const functions = require('firebase-functions');
// Constants
// =================================================================================================
// Instantiate the Dialogflow client with debug logging enabled.
const app = dialogflow({ debug: true });
// Intents
// =================================================================================================
app.intent('welcome.intent', (conv) => {
conv.ask('Hello from webhook');
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
第二个使用dialogflow-fulfillment,
`'use strict'`;
const functions = require('firebase-functions');
const { WebhookClient } = require('dialogflow-fulfillment');
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(`Hello from webhook agent`);
}
let intentMap = new Map();
intentMap.set('welcome.intent', welcome);
agent.handleRequest(intentMap);
});
【问题讨论】:
标签: node.js webhooks dialogflow-es actions-on-google