dialogflow-fulfillment-nodejs
dialogflow-fulfillment-nodejs copied to clipboard
Clearing contexts is not working any more!
Hi,
We used the below methods to clear contexts:
agent.setContext({ 'name': 'context_name', 'lifespan': 0});
agent.clearOutgoingContexts();
agent.clearContext('context_name')
but looks like nothing worked! And also while setting context lifespan to "0", context is getting created with lifespan "5". It would be great if this issue is resolved.
Thanks!
Hello Hima,
Here might be a quick fix for this issue.
Looks like the problem is with .setContext() method, because it does not set lifespan count to 0.
Here is the code:
agent.setContext({'name':context_name, "lifespanCount":-1});
It kind of works, the context is reset.
Yeah! It actually worked. Thanks!
This works but .clearContext() and .clearOutgoingContexts() should clear the contexts which are not working.
agent.context.set('context_name', 0)
// and
agent.context.delete('context_name')
Are not working either
Hello Hima, agent.clearContext & agent.clearOutgoingContexts doesn't clear contexts that have been set in your previous fulfillment endpoint call. They only clear contexts that have been added in your current fulfillment endpoint call.
I believe in older version of dialogflow-fulfillment, you had to specify the lifespan value as string ('lifespan':'0') instead of a number.
By the way, if you update your dialogflow-fullfilment version, clearContext & clearOutgoingContexts are deprecated. You should use agent.context.set / agent.context.delete instead.
@M-Abozaid, what release of dialogflow-fulfillment do you use?
Hey Philippe!
Thanks, specifying the lifespan as a string instead of number worked.
Is there a plan to fix this , I am facing similar issue with Inline Editor ( Firebase ) version of dialogflow
wow, I tried all the seemingly official approaches also
agent.setContext({ 'name': 'context_name', 'lifespan': 0});
agent.setContext({ 'name': 'context_name', 'lifespan': -1});
agent.clearOutgoingContexts();
agent.clearContext('context_name');
The only thing that does work is @KoffeeToKode's suggestion of using a string value
agent.setContext({ 'name': 'context_name', 'lifespan': '0'});
That's the only thing that changes the fullfillment API respons's "lifespanCount"
Seems like there's either a misunderstanding or a bug somewhere here.
None of this is working for me, the only thing I can change in my output context using my webhook are the parameters. I cannot clear/delete contexts nor set the lifespan using any sort of hack or otherwise. Can someone please fix this?????
I think contexts can be cleared by setting the lifespan to -1. This worked for me.
Hello,
I am having the same issues as described above, only that for me neither of the solution works. I have a context with several parameters and at some point I want to reset it and start collecting the parameters again from scratch.
agent.context.set('context-name', 0) or agent.context.delete('context-name') as well as those described above doesn't work. Cloud function throws same error each time:

Would be grateful for help.
EDIT: solved. I didn't have any response for the agent in my fulfilment code, instead I had a response in the intent in console, this was sort of a conflict that caused this issue. Now agent.context.delete('context-name') works fine.
any fix for clear the contexts ? I have tried below methods , but non of method not works.
agent.setContext({ 'name': 'context_name', 'lifespan': 0});
agent.setContext({ 'name': 'context_name', 'lifespan': -1});
agent.clearOutgoingContexts();
agent.clearContext('context_name');
agent.setContext({ 'name': 'context_name', 'lifespan': '0'});
This works for me
`agent.context.set("currentintent-followup", 5, {});`