node.js - Google Action Webhook 实现

标签 node.js webhooks dialogflow-es actions-on-google

所以我刚刚开始做一个项目。我遇到了 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/

相关文章:

node.js - 运行 launch.json 配置时找不到模块 '"/Applications/Visual'

javascript - Node.js、Express 和 Mongoose,未定义数据

php - 如何在 PHP 上将 hash_hmac() 与 "SHA256withRSA"一起使用?

php - Laravel 收银员事件

node.js - 调用createEntityType时出现权限错误

bots - Actions on Google 上的设备位置

javascript - 带有 node.js 的 Ruby 子进程

javascript - 仅在某些路由上使用 Express.JS 中间件

stripe-payments - Stripe -定期付款中包含其他发票项目

dialogflow-es - 如何通过 actions-for-google/google assistant 集成为 dialogflow 提供时区?