Javascript Dialogflow访问代码中的实体
我正在Dialogflow中开发聊天机器人,希望验证某人的年龄。简单介绍一下上下文:我正在创建一个聊天机器人,用于识别护理需求,如住院或痴呆症护理。在最初的查询中,我希望能够通过在Dialogflow中的实现代码中执行快速IF语句来确保用户是65岁或65岁以上 以下是我目前的意图: 以下是getUserInfo的意图: 以下是履行代码:Javascript Dialogflow访问代码中的实体,javascript,dialogflow-es,actions-on-google,Javascript,Dialogflow Es,Actions On Google,我正在Dialogflow中开发聊天机器人,希望验证某人的年龄。简单介绍一下上下文:我正在创建一个聊天机器人,用于识别护理需求,如住院或痴呆症护理。在最初的查询中,我希望能够通过在Dialogflow中的实现代码中执行快速IF语句来确保用户是65岁或65岁以上 以下是我目前的意图: 以下是getUserInfo的意图: 以下是履行代码: 'use strict'; // Import the Dialogflow module from the Actions on Google clie
'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);
“严格使用”;
//从Google客户端库上的操作导入Dialogflow模块。
const{dialogflow}=require('actions-on-google');
//导入firebase功能包以进行部署。
const functions=require('firebase-functions');
//实例化Dialogflow客户端。
const-app=dialogflow({debug:true});
app.intent('careEqnuiry-yourself-getUserInfo',(conv,{age})=>{
const userAge=年龄;
如果(用户年龄<65岁){
conv.add(“你还没有到接受护理的年龄!”);
}
});
//设置DialogflowApp对象以处理HTTPS POST请求。
exports.dialogflowFirebaseFulfillment=functions.https.onRequest(应用程序);
这对我来说是全新的。意图处理程序回调的第二个参数是一个包含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);
“严格使用”;
//从Google客户端库上的操作导入Dialogflow模块。
const{dialogflow}=require('actions-on-google');
//导入firebase功能包以进行部署。
const functions=require('firebase-functions');
//实例化Dialogflow客户端。
const-app=dialogflow({debug:true});
app.intent('careEqnuiry-yourself-getUserInfo',(conv,params)=>{
const name=params['given-name'];
常量年龄=参数['age'];
如果(年龄、金额<65){
conv.ask(“你还没有到接受护理的年龄!”);
}
});
//设置DialogflowApp对象以处理HTTPS POST请求。
exports.dialogflowFirebaseFulfillment=functions.https.onRequest(应用程序);
另外,从对话返回响应的正确方法是对对话对象使用
ask()
或close()
方法ask()
在允许对话继续的同时发送响应,close
发送响应并结束对话。您面临什么问题?我不明白。