【问题标题】:Google Action Webhook ImplementationGoogle Action Webhook 实施
【发布时间】: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


    【解决方案1】:

    这两个库均有效且受 Google 支持。您使用哪一种取决于您的目标。

    如果您的目标是开发 Actions,则最好使用 actions-on-google 库。它支持 AoG 平台支持的一些更高级的功能,但不支持 Dialogflow 支持的其他平台。

    如果您想使用 Dialogflow(可能包括 Actions on Google 平台)支持多个机器人平台,最好使用 dialogflow-fulfillment 库。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多