node.js 的对话流如何切换意图
dialogflow with node.js how do you swtich intents
我的意图具有必需的参数和实现。当您回答时,它会将您带到我的 node.js 应用程序,该应用程序当前如下所示:
app.intent(QUESTIONS_INTENT, (conv, params) => {
let data = conv.data;
let categoryId = data.categoryId;
let formulas = data.formulas;
let options = {
'method': 'PUT',
'url': apiUrl + 'questions/filter',
'body': {
categoryId: categoryId,
organisationId: organisation,
formulas: formulas
},
'json': true
};
return request(options).then(response => {
// We need to change how we get these
var questionText = params.questions;
var questions = response.filter(item => item.text === questionText);
data.questions = questions;
conv.ask(questions[0].text);
conv.contexts.set('colour');
}, error => {
conv.ask(JSON.stringify(error));
});
})
目前它得到 questionText
并找到与您所说的相匹配的问题。我想让它做的是切换到一个新的意图。我已经尝试 conv.contexts.set('colour')
但似乎没有用。
我有一个输入上下文为 "Colour" 的意图设置,所以我希望当我的实现完成时,它应该切换到那个意图,但它没有。
有人可以帮我解决这个问题吗?
您需要确保在 DialogFlow 中有一个 colour
意图设置,它将处理用户的输入并对其做出响应。在设置上下文后应该问这个问题。
return request(options).then(response => {
// We need to change how we get these
var questionText = params.questions;
var questions = response.filter(item => item.text === questionText);
data.questions = questions;
// Sets the context to colour.
conv.contexts.set('colour', 1);
// Now that the context is in control you'll be able to ask a question.
conv.ask(questions[0].text);
您还需要在上下文 arg 之后提供生命周期。这将使那么多提示的上下文处于活动状态,在上面的示例中,我将其设置为一个,因此您的问题上下文将仅针对该特定响应处于活动状态。
conv.contexts.set('colour', 1);
我的意图具有必需的参数和实现。当您回答时,它会将您带到我的 node.js 应用程序,该应用程序当前如下所示:
app.intent(QUESTIONS_INTENT, (conv, params) => {
let data = conv.data;
let categoryId = data.categoryId;
let formulas = data.formulas;
let options = {
'method': 'PUT',
'url': apiUrl + 'questions/filter',
'body': {
categoryId: categoryId,
organisationId: organisation,
formulas: formulas
},
'json': true
};
return request(options).then(response => {
// We need to change how we get these
var questionText = params.questions;
var questions = response.filter(item => item.text === questionText);
data.questions = questions;
conv.ask(questions[0].text);
conv.contexts.set('colour');
}, error => {
conv.ask(JSON.stringify(error));
});
})
目前它得到 questionText
并找到与您所说的相匹配的问题。我想让它做的是切换到一个新的意图。我已经尝试 conv.contexts.set('colour')
但似乎没有用。
我有一个输入上下文为 "Colour" 的意图设置,所以我希望当我的实现完成时,它应该切换到那个意图,但它没有。
有人可以帮我解决这个问题吗?
您需要确保在 DialogFlow 中有一个 colour
意图设置,它将处理用户的输入并对其做出响应。在设置上下文后应该问这个问题。
return request(options).then(response => {
// We need to change how we get these
var questionText = params.questions;
var questions = response.filter(item => item.text === questionText);
data.questions = questions;
// Sets the context to colour.
conv.contexts.set('colour', 1);
// Now that the context is in control you'll be able to ask a question.
conv.ask(questions[0].text);
您还需要在上下文 arg 之后提供生命周期。这将使那么多提示的上下文处于活动状态,在上面的示例中,我将其设置为一个,因此您的问题上下文将仅针对该特定响应处于活动状态。
conv.contexts.set('colour', 1);