1

How can we update a parameter value with the DialogFlow Fulfillment library? I wrote a helper method to access the agent's contexts and loop through updating the values, but that does not seem to be working:

export const dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
    const wbhc = new WebhookClient({ request, response });

    function testIntentHandler(agent: any) {
        const date = agent.parameters['date'];
        const datePeriod = agent.parameters['date-period'];

        if (date && !datePeriod) {
            setDialogFlowParameter('date-period', {
                startDate: date,
                endDate: date
            }, agent.context);
        }

        agent.add("I've set the value");
    }

    // Run the proper function handler based on the matched Dialogflow intent name
    const intentMap = new Map();
    intentMap.set('TestIntent', testIntentHandler);
    wbhc.handleRequest(intentMap);
});

function setDialogFlowParameter(param: string, val: any, context: any) {
    const contexts = context.contexts;
    const keys = Object.keys(contexts);

    for (const key of keys) {
        const c = context.get(key);
        c.parameters[param] = val;
        context.set(key, c.lifespan, c.parameters);
    }
}

Please note, this question is focused around the NodeJS dialogflow-fulfillment library, which I couldn't find an answer for after hours of searching.

arao6
  • 3,316
  • 5
  • 30
  • 51

1 Answers1

1

Did you look at the output contexts attribute of FULFILMENT RESPONSE tab in"DIAGNOSTIC INFO" of the Dialogflow console? You should be able to see the values there after you use the agent.context.set() method and update the param values.

Ershadi
  • 133
  • 10