![](/img/trans.png)
[英]how to extract parameters from the context for list response using dialogflow fulfillment
[英]How to use Parameters to modify Context in Google Dialogflow
我们正在运行一个实验,我需要根据参与者的 ID 操作对话流响应。 我的想法是有一种方法可以根据参数值设置输出上下文。
例如,我们有一个询问参与者 ID 的提示。 这匹配具有“participantID”参数的意图。 现在我想做的是将输出上下文设置为“participantID”参数的值。 然后我可以将输入上下文设置为特定的“参与者 ID”。
在意图上设置的任何参数都将保留在输出上下文中,并可在此类上下文的生命周期内在后续的后续意图中恢复。
通过 Dialogflow UI,您可以在初始响应中将它们引用为$<parameter-name>
。
例如,假设您的参数名称是id ,则响应可以是: Welcome player $id,...
。
对于后验后续意图中上下文中的值,请使用#<context-name>.<parameter-name>
。
例如,在具有参数answer和输入上下文id-followup的第二个后续操作中, Your answer has been $answer, if you are not player #id-followup.id please let me know your actual id
。
如果您需要使用 Fulfillment Webhook,我推荐一种类似于此处所示结构的结构,即如下结构:
//The user inputs a participant ID (name of the parameter is id)
function answers(agent){
const id = agent.parameters.id;
agent.add(`So your id is ${id}`);
agent.add(`Any extra questions...`);
agent.setContext({
name: 'question',
lifespan: 5, // Amount of follow-up intents this context will be kept
parameters: {'cid': id},
});
}
// Next functions that use the participant id as input context
function answers2(agent){
// Get the context and from it extract the id value
const cont = agent.getContext('question');
const particular_id = cont.parameters.cid;
// The rest of your code
根据您使用的 dialogflow-fulfillment 版本,我在这里谈论的是 0.6.1。 设置上下文的语法是:
agent.context.set({
name: "ctx_name",
lifespan: 5,
parameters: {'cid': id},
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.