如何在对话流中获取先前的意图
How to get previous intent in dialogflow
我遇到了一个问题:
我已经创建了 4 个意向书Table,bookingDate、bookingTime 和人数统计intent.i 已经添加了使用输入和输出上下文的意向链接。
假设我现在处于第三个意图,即“预订时间”,当我对 google 家说“预订 A Table”时,它会直接跳转到第一个意图。
我需要不跳转到第一个意图的解决方案,但如果用户说除必需输入之外的任何内容,那么它将调用自定义回退意图并停留在该特定意图上。
请提供解决方案,不要将意图跳转到任何其他意图..
// welcome intent here
app.intent('DefaultWelcomeIntent', (conv) => {
conv.ask('What would you like me to do for you?. Book a table or Check your calendar?');
});
// Booktable intent
app.intent('BookTable', (conv) => {
conv.ask('Please provide a date?');
});
// bookingDate intent
app.intent('bookingDate', (conv, params) => {
var speech = new Speech();
const currentDate = moment().format("YYYY-MM-DD");
const bookingDate = moment(params.date).format("YYYY-MM-DD");
const displayBookingDate = moment(bookingDate).format("DD MMM YYYY");
let say = '';
if (bookingDate && moment(bookingDate).isSameOrAfter(currentDate)) {
speech.say(`OK, ${displayBookingDate}`)
.pause('300ms')
.say(`Please provide time?`);
const speechOutput = speech.toObject();
conv.ask(speechOutput.speech);
conv.data.restaurantData.date = bookingDate;
} else {
say = `Please provide today's or upcoming date.`;
conv.ask(say);
}
});
// bookingTime intent
app.intent('bookingTime', (conv, params) => {
var speech = new Speech();
const currentDateTime = moment().format("YYYY-MM-DD HH:mm");
const bookingDate = moment(conv.data.restaurantData.date).format("YYYY-MM-DD");
const bookingTime = moment(params.time).format("HH:mm");
const booking12HourTimeString = moment(bookingTime, ["HH:mm"]).format("hh:mm A");
const concateDateTime = moment(bookingDate + " " + bookingTime).format('YYYY-MM-DD HH:mm');
let say = '';
if(moment(concateDateTime).isSameOrAfter(currentDateTime)) {
speech.say(`OK, ${booking12HourTimeString}`)
.pause('300ms')
.say(`How many people?`);
const speechOutput = speech.toObject();
conv.ask(speechOutput.speech);
conv.data.restaurantData.time = bookingTime;
} else {
say = `please provide a valid booking time.`;
conv.ask(say);
}
});
// people count intent
app.intent('peopleCount', (conv, params) => {
let peopleCounts = parseInt(params.count);
let restaurantName = 'Dominos pizza';
let restaurantAddress = 'San Francisco, ca';
let bookingDate = conv.data.restaurantData.date;
let bookingTime = conv.data.restaurantData.time;
const booking12HourTimeString = moment(bookingTime, ["HH:mm"]).format("hh:mm A");
let bookingDisplayDate = moment(bookingDate).format("DD MMM YYYY");
if (peopleCounts > 0) {
conv.ask(`OK You would like to create a table for ${restaurantName} in ${restaurantAddress} on ${bookingDisplayDate} at ${booking12HourTimeString} for ${peopleCounts} people`);
} else {
conv.ask(`Please add people more than zero`);
}
});
app.intent('customFallback', (conv, params) => {
conv.ask(`I couldn't understand. Can you say that again?`);
});
您的用例不是很清楚,但根据我的理解,您真正需要的是 contexts 或 follow-up intents。使用这些你可以链接意图。
如果您仍想获取以前的意图名称,我认为您应该将其存储在缓存中以便获取。 dialogflow 中没有规定可以做到这一点。
根据我对你的问题的理解,这个问题非常模糊,可以借助上下文获得当前意图中先前意图的值。
如果这个答案还有任何不明确的地方,如果你提供一些例子会很有帮助。
您无法直接获取先前的意图名称,但您可以根据“conversationToken”识别意图,如下所示。
function getFeedbackFunc(agent){
...
let convTokens= request.body.originalDetectIntentRequest.payload.conversation.conversationTo
ken;
console log("Original Intent :"+convTokens);
...
}
我得到的输出为:["awaiting_feedback","customer_phone","awaiting_contact","customer_name","phonepair-no-followup "]
因此根据输出,原始意图与上下文“phonepair-no-followup”相关,您可以 select 相应地表达您的意图。
如果有帮助,请提供您的反馈。
我遇到了一个问题:
我已经创建了 4 个意向书Table,bookingDate、bookingTime 和人数统计intent.i 已经添加了使用输入和输出上下文的意向链接。
假设我现在处于第三个意图,即“预订时间”,当我对 google 家说“预订 A Table”时,它会直接跳转到第一个意图。
我需要不跳转到第一个意图的解决方案,但如果用户说除必需输入之外的任何内容,那么它将调用自定义回退意图并停留在该特定意图上。
请提供解决方案,不要将意图跳转到任何其他意图..
// welcome intent here
app.intent('DefaultWelcomeIntent', (conv) => {
conv.ask('What would you like me to do for you?. Book a table or Check your calendar?');
});
// Booktable intent
app.intent('BookTable', (conv) => {
conv.ask('Please provide a date?');
});
// bookingDate intent
app.intent('bookingDate', (conv, params) => {
var speech = new Speech();
const currentDate = moment().format("YYYY-MM-DD");
const bookingDate = moment(params.date).format("YYYY-MM-DD");
const displayBookingDate = moment(bookingDate).format("DD MMM YYYY");
let say = '';
if (bookingDate && moment(bookingDate).isSameOrAfter(currentDate)) {
speech.say(`OK, ${displayBookingDate}`)
.pause('300ms')
.say(`Please provide time?`);
const speechOutput = speech.toObject();
conv.ask(speechOutput.speech);
conv.data.restaurantData.date = bookingDate;
} else {
say = `Please provide today's or upcoming date.`;
conv.ask(say);
}
});
// bookingTime intent
app.intent('bookingTime', (conv, params) => {
var speech = new Speech();
const currentDateTime = moment().format("YYYY-MM-DD HH:mm");
const bookingDate = moment(conv.data.restaurantData.date).format("YYYY-MM-DD");
const bookingTime = moment(params.time).format("HH:mm");
const booking12HourTimeString = moment(bookingTime, ["HH:mm"]).format("hh:mm A");
const concateDateTime = moment(bookingDate + " " + bookingTime).format('YYYY-MM-DD HH:mm');
let say = '';
if(moment(concateDateTime).isSameOrAfter(currentDateTime)) {
speech.say(`OK, ${booking12HourTimeString}`)
.pause('300ms')
.say(`How many people?`);
const speechOutput = speech.toObject();
conv.ask(speechOutput.speech);
conv.data.restaurantData.time = bookingTime;
} else {
say = `please provide a valid booking time.`;
conv.ask(say);
}
});
// people count intent
app.intent('peopleCount', (conv, params) => {
let peopleCounts = parseInt(params.count);
let restaurantName = 'Dominos pizza';
let restaurantAddress = 'San Francisco, ca';
let bookingDate = conv.data.restaurantData.date;
let bookingTime = conv.data.restaurantData.time;
const booking12HourTimeString = moment(bookingTime, ["HH:mm"]).format("hh:mm A");
let bookingDisplayDate = moment(bookingDate).format("DD MMM YYYY");
if (peopleCounts > 0) {
conv.ask(`OK You would like to create a table for ${restaurantName} in ${restaurantAddress} on ${bookingDisplayDate} at ${booking12HourTimeString} for ${peopleCounts} people`);
} else {
conv.ask(`Please add people more than zero`);
}
});
app.intent('customFallback', (conv, params) => {
conv.ask(`I couldn't understand. Can you say that again?`);
});
您的用例不是很清楚,但根据我的理解,您真正需要的是 contexts 或 follow-up intents。使用这些你可以链接意图。
如果您仍想获取以前的意图名称,我认为您应该将其存储在缓存中以便获取。 dialogflow 中没有规定可以做到这一点。
根据我对你的问题的理解,这个问题非常模糊,可以借助上下文获得当前意图中先前意图的值。
如果这个答案还有任何不明确的地方,如果你提供一些例子会很有帮助。
您无法直接获取先前的意图名称,但您可以根据“conversationToken”识别意图,如下所示。
function getFeedbackFunc(agent){
...
let convTokens= request.body.originalDetectIntentRequest.payload.conversation.conversationTo
ken;
console log("Original Intent :"+convTokens);
...
}
我得到的输出为:["awaiting_feedback","customer_phone","awaiting_contact","customer_name","phonepair-no-followup "]
因此根据输出,原始意图与上下文“phonepair-no-followup”相关,您可以 select 相应地表达您的意图。
如果有帮助,请提供您的反馈。