我想在dialogflow中检索先前意图的参数值
I want to retrieve the value of the parameter of the previous intent in dialogflow
我有一个 dialogflow 机器人,它要求用户分别输入名字、姓氏、出生日期、出生月份、出生年份(所以我在 DF 中有 5 个意图,在 webhook 中每个字段有 5 个单独的 intent.js 文件) .
我想以这样的方式验证 dob,即当用户给出月份时,bot 应该验证用户是否输入正确的日期 format.This 应该在 Nodejs
中
示例:
机器人:您好,请输入您的名字
User:John
Bot:your 姓
user:Sally
Bot:your dob 月份?
User:02
Bot:your 工作日?
User:31
Bot:sorry,这是无效的dob
我为每个字段创建了一个单独的意图,并在 webhook 中使用 nodejs.I 验证了每个字段我不确定如何处理这种类型的 validation.For,我是否需要使用任何上下文或后续意图?如果我必须在单独的 .js 文件中验证 Dob 日,我需要检索从用户保留的月份值。
到目前为止:
我已经验证了我从用户那里得到的出生日期。我是 Javascript 和节点 js 的新手。
我建议您将信息保存在上下文中。然后您可以根据同一上下文中的任何意图检索数据。
要添加到@MizarConstanti 的答案中,您可以将以下内容用于您的实体:
- 对于日期,您可以使用实体
@sys.date
- 对于名字
@sys.given-name
- 姓
@sys.last-name
注意:对于名字和姓氏实体,这些实体只能识别通用名称 (reference)。
另一种获取日期和姓名的方法是您可以用这种方式创建训练短语并使用定义的实体提取信息。
意图->测试意图
意图 -> getName
如果您在 Dialogflow 内联编辑器中使用库 dialogflow-fulfillment
,则可以使用以下代码调用这些实体:
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const axios = require('axios');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function yourFunctionHandler(agent) {
// initial value of agent.parameters.date is 1994-07-29T12:00:00+08:00
// thus the splitting done below
const date = agent.parameters.date.split('T')[0];
const year = agent.parameters.date.split('-')[0];
const month = agent.parameters.date.split('-')[1];
const day = agent.parameters.date.split('-')[2].split('T')[0];
agent.add(`year: ${year}, month:${month}, day:${day}`);
}
function getName(agent) {
const lastName = agent.parameters.lastName;
const firstName= agent.parameters.givenName;
agent.add(`first: ${firstName}, last: ${lastName}`);
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('test intent', yourFunctionHandler);
intentMap.set('getName', getName);
agent.handleRequest(intentMap);
});
测试日期和名称意图:
首先我建议你从没有后端的 Dialogflow 中获取变量,然后从诊断信息中读取它,如果信息被监视你可以从后端响应中获取。
我有一个 dialogflow 机器人,它要求用户分别输入名字、姓氏、出生日期、出生月份、出生年份(所以我在 DF 中有 5 个意图,在 webhook 中每个字段有 5 个单独的 intent.js 文件) .
我想以这样的方式验证 dob,即当用户给出月份时,bot 应该验证用户是否输入正确的日期 format.This 应该在 Nodejs
示例:
机器人:您好,请输入您的名字
User:John
Bot:your 姓
user:Sally
Bot:your dob 月份?
User:02
Bot:your 工作日?
User:31
Bot:sorry,这是无效的dob
我为每个字段创建了一个单独的意图,并在 webhook 中使用 nodejs.I 验证了每个字段我不确定如何处理这种类型的 validation.For,我是否需要使用任何上下文或后续意图?如果我必须在单独的 .js 文件中验证 Dob 日,我需要检索从用户保留的月份值。
到目前为止: 我已经验证了我从用户那里得到的出生日期。我是 Javascript 和节点 js 的新手。
我建议您将信息保存在上下文中。然后您可以根据同一上下文中的任何意图检索数据。
要添加到@MizarConstanti 的答案中,您可以将以下内容用于您的实体:
- 对于日期,您可以使用实体
@sys.date
- 对于名字
@sys.given-name
- 姓
@sys.last-name
注意:对于名字和姓氏实体,这些实体只能识别通用名称 (reference)。
另一种获取日期和姓名的方法是您可以用这种方式创建训练短语并使用定义的实体提取信息。
意图->测试意图
意图 -> getName
如果您在 Dialogflow 内联编辑器中使用库 dialogflow-fulfillment
,则可以使用以下代码调用这些实体:
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const axios = require('axios');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function yourFunctionHandler(agent) {
// initial value of agent.parameters.date is 1994-07-29T12:00:00+08:00
// thus the splitting done below
const date = agent.parameters.date.split('T')[0];
const year = agent.parameters.date.split('-')[0];
const month = agent.parameters.date.split('-')[1];
const day = agent.parameters.date.split('-')[2].split('T')[0];
agent.add(`year: ${year}, month:${month}, day:${day}`);
}
function getName(agent) {
const lastName = agent.parameters.lastName;
const firstName= agent.parameters.givenName;
agent.add(`first: ${firstName}, last: ${lastName}`);
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('test intent', yourFunctionHandler);
intentMap.set('getName', getName);
agent.handleRequest(intentMap);
});
测试日期和名称意图:
首先我建议你从没有后端的 Dialogflow 中获取变量,然后从诊断信息中读取它,如果信息被监视你可以从后端响应中获取。