1

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".

Doc
  • 179
  • 2
  • 12

2 Answers2

1

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, i.e. 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,...

aemon4
  • 1,037
  • 6
  • 11
0

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},
  });