Dialogflow履行在代码中访问实体

问题描述 投票:2回答:1

我正在使用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 actions-on-google
1个回答
2
投票

intent处理程序回调的第二个参数是一个包含Dialogflow中所有参数(实体)的对象。

在您当前的代码中,您正在为age参数解构此对象(即:{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发送回复并结束对话。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.