一个人如何将参数从实现编辑器中的意图传递到另一个后续意图。
这是我的代码
// original intent
// the params defined here are the ones I want to pass to the app.intent below.
app.intent('Book Appointment', (conv, params) => {
// the params that i want to access in the next intent
const date = params['date'];
const time = params['time'];
const firstName = params['given-name'];
const email = params['email'];
// what i dont get is what to put in here is it
// how am i formatting this?
const parameters = {'date':params.date,}
// is the 'welcome-context' replaced with this one from the JSON? like so?
conv.contexts.set('projects/myproject-120c2/agent/sessions/c2c1c9e0-2ccf-0cf0-d7ce-e52561d44de3/contexts/bookappointment-followup"', 5, parameters);
// or is it
conv.contexts.set('bookappointment-followup', 5, parameters); // ??
// like it is in Dialogflow
})
// follow-up intent
app.intent('Book Appointment - yes', (conv, params) => {
// this is where I want to access the ones above
// then im accessing them like this?
const conv.contexts.get('bookappointment-followup').parameters['whatever it is above'];
})
电子邮件中的变量返回未定义。我认为这与上下文有关,但是我不知道它是否与#book.appointment.follow.date等相同的代码。
感谢帮助,欢呼
答案 0 :(得分:0)
您可以查看我的答案here
使用输出上下文保存参数
{
"fulfillmentText":"This is a text response",
"fulfillmentMessages":[ ],
"source":"example.com",
"payload":{
"google":{ },
"facebook":{ },
"slack":{ }
},
"outputContexts":[
{
"name":"<Context Name>",
"lifespanCount":5,
"parameters":{
"<param name>":"<param value>"
}
}
],
"followupEventInput":{ }
}
如果您使用的是NodeJS client
您可以使用类似参数的上下文来保存
let param1 = [];
let param2 = {};
let ctx = {'name': '<context name>', 'lifespan': 5, 'parameters': {'param1':param1, 'param2': param2}};
agent.setContext(ctx);
并得到它
let params = agent.getContext("<context name>").parameters;
let param1 = params.param1;
let param2 = params.param2;
如果使用conv
,您也可以这样尝试:
app.intent('<INTENT>', conv => {
conv.ask('<RESPONSE>');
const parameters = {'param1':param1, 'param2': param2}};
conv.contexts.set('welcome-context', 5, parameters);
});
并像here一样访问它:
const conv.contexts.get(<context>).parameters[<param>];
如果通过context
无效,则可以尝试使用data
之类的
conv.data.someProperty = 'someValue'
如here
答案 1 :(得分:0)
感谢这项工作。
const firstName = conv.contexts.get('bookappointment-followup').parameters['given-name'];
:)