所以我刚刚开始做一个项目。我遇到了 Google Action Agent 的两种不同的 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);
});
最佳答案
这两个库均有效且受 Google 支持。您使用哪一种取决于您的目标。
如果您的目标仅开发 Actions,则 actions-on-google
库是最佳选择。它支持AoG平台支持的一些更高级的功能,但不支持Dialogflow支持的其他平台。
如果您想使用 Dialogflow(可能包括 Google 平台上的 Actions)支持多个机器人平台,dialogflow-fulfillment
库是最佳选择。
关于node.js - Google Action Webhook 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53447656/