Search code examples
dialogflow-esactions-on-google

How to delete or set lifespan to zero - Dialogflow Agent Context


I would like to ask you how could I set to zero or null a lifespan of a context.

Example that I’ve tried:

    const { WebhookClient } = require('dialogflow-fulfillment'); //"dialogflow-fulfillment": "^0.5.0"

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

agent.context.set({
            'name': 'context_name',
            'lifespan': 0 
          });

Or

agent.context.set({
            'name': 'context_name',
            'lifespan': null
          });

Or

agent.setContext({ name: 'context_name', lifespan: 0 });

Or

agent.setContext({ name: 'context_name', lifespan: null });

or

agent.context.delete('context_name');

However, it always sets itself up to the value of 5 again.

Is there a way to delete or set it to zero?


Solution

  • You need to use clearContext():

    const { WebhookClient } = require('dialogflow-fulfillment'); //"dialogflow-fulfillment": "^0.5.0"
    
    exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
        const agent = new WebhookClient({ request, response });
    
    agent.clearContext('context_name');
    

    Hope it helps.