我有一个具有必需参数和实现的意图。当你回答它时会带你到我的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')
,但这似乎不起作用。
我有一个意图设置输入上下文为“颜色”所以我希望当我的履行完成时,它应该交换到该意图,但它不会。
有人可以帮我弄这个吗?
您需要确保在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之后提供生命周期。这将使上下文对于许多提示处于活动状态,在上面的示例中,我将其设置为1,因此您的问题上下文仅对该特定响应有效。
conv.contexts.set('colour', 1);