【问题标题】:Dialogflow fulfilment accessing entities in codeDialogflow 实现访问代码中的实体
【发布时间】:2018-09-07 14:57:53
【问题描述】:

我正在 Dialogflow 中开发一个聊天机器人,并希望验证某人的年龄。快速了解一下背景:我正在创建一个聊天机器人来识别护理需求,例如住宅或痴呆症护理。在最初的查询中,我希望能够通过在 Dialogflow 的履行代码中执行快速 IF 语句来确保用户年满 65 岁!

这是我目前的意图: Current Intents

这里是 getUserInfo 意图: getUserInfo intent

这是实现代码:

'use strict';

// Import the Dialogflow module from the Actions on Google client library.
const {dialogflow} = require('actions-on-google');

// Import the firebase-functions package for deployment.
const functions = require('firebase-functions');

// Instantiate the Dialogflow client.
const app = dialogflow({debug: true});

app.intent('careEqnuiry - yourself - getUserInfo', (conv, {age}) => {
    const userAge = age;

    if (userAge < 65) {
        conv.add("You're not old enough to recieve care!");
    }

});

// Set the DialogflowApp object to handle the HTTPS POST request.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

这对我来说是全新的。

【问题讨论】:

  • 您面临什么问题?我不明白。

标签: javascript dialogflow-es actions-on-google


【解决方案1】:

意图处理程序回调的第二个参数是一个对象,其中包含来自 Dialogflow 的所有参数(实体)。

在您当前的代码中,您正在为年龄参数解构此对象(即:{age})。

我注意到您有两个不同的参数,年龄和名字。

您可以通过执行以下操作来获取这些值:

'use strict';

// Import the Dialogflow module from the Actions on Google client library.
const {dialogflow} = require('actions-on-google');

// Import the firebase-functions package for deployment.
const functions = require('firebase-functions');

// Instantiate the Dialogflow client.
const app = dialogflow({debug: true});

app.intent('careEqnuiry - yourself - getUserInfo', (conv, params) => {
    const name = params['given-name'];
    const age = params['age'];
    if (age.amount < 65) {
        conv.ask("You're not old enough to receive care!");
    }

});

// Set the DialogflowApp object to handle the HTTPS POST request.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

此外,从对话返回响应的正确方法是在对话对象上使用ask()close() 方法。 ask() 在允许对话继续的同时发送响应,close 发送响应并结束对话。

【讨论】:

    猜你喜欢
    • 2018-11-21
    • 2020-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多