We are running an experiment, where I need to manipulate the dialog flow responses based on the participant's ID. My thought is there is a way to set the Output Context based on a parameter value.
For example, we have a prompt that asks for the participant's id. This matches an intent with a "participantID" parameter. Now what I would like to do is set the output context to be the value of the "participantID" parameter. Then I could set the input context to be a specific "participantID".
Any parameters set on an intent will be kept in the output context and recoverable in posterior follow-up intents within the lifespan of such context.
Through the Dialogflow UI you can reference them in the initial response as $<parameter-name>
.
For example, assuming your parameter name is id , the response can be: Welcome player $id,...
.
For values in the context in posterior follow-up intents use #<context-name>.<parameter-name>
.
For example, in a second follow-up which has parameter answer and input context id-followup use Your answer has been $answer, if you are not player #id-followup.id please let me know your actual id
.
If you need to use the Fulfillment Webhook I recommend a structure like the one illustrated here , ie a structure like:
//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
Some documentation you may find useful includes Input and output contexts , Parameter reference ,...
Depending on what version of dialogflow-fulfillment you are using, I'm talking about 0.6.1 here. The syntax for setting context is:
agent.context.set({
name: "ctx_name",
lifespan: 5,
parameters: {'cid': id},
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.