首页 文章

Dialogflow履行在代码中访问实体

提问于
浏览
2

我正在使用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);

这对我来说都是新的 .

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 发送回复并结束对话 .

相关问题