上下文在对话流中无法正常工作

问题描述 投票:0回答:1
const contextlist = 'customer';
app.intent('Welcome', (conv) => {
    const customer = { 'companyId': '11131' };
    conv.contexts.set(contextlist, 5, customer);
});


app.intent('Delivery',(conv)=>{
let companycontext = conv.contexts.get(contextlist);
})

These are the logs regarding the context

我将在调用我的欢迎意图时设置上下文,并在调用传递意图时从意图中获取值,但是在获取上下文值时我变得不确定。

node.js dialogflow actions-on-google
1个回答
0
投票

[首先尝试添加带有一些文本的conv.ask()调用,在您显示的代码示例中,您没有返回响应,这可能会影响上下文的设置。

如果不起作用,请尝试将在上下文中设置变量的方式更改为以下内容:

conv.contexts.set(contextlist, 5, { customer });

您要设置的属性必须是对象的一部分。如果要检索客户,则需要使用以下代码:

// Set context
conv.contexts.set(contextlist, 5, { customer });

// Retrieve context
const companycontext = conv.contexts.get(contextlist);
const customer = companycontext.parameters.customer;
© www.soinside.com 2019 - 2024. All rights reserved.