dialogflow-fulfillment-nodejs icon indicating copy to clipboard operation
dialogflow-fulfillment-nodejs copied to clipboard

Clearing contexts is not working any more!

Open hima-egen opened this issue 6 years ago • 13 comments

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!

hima-egen avatar Feb 06 '19 09:02 hima-egen

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.

lasyapriyanka avatar Feb 07 '19 05:02 lasyapriyanka

Yeah! It actually worked. Thanks!

hima-egen avatar Feb 07 '19 05:02 hima-egen

This works but .clearContext() and .clearOutgoingContexts() should clear the contexts which are not working.

hima-egen avatar Feb 07 '19 06:02 hima-egen

agent.context.set('context_name', 0)
// and 
agent.context.delete('context_name')

Are not working either

M-Abozaid avatar Feb 13 '19 01:02 M-Abozaid

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?

n1ght-owl avatar Feb 24 '19 01:02 n1ght-owl

Hey Philippe!

Thanks, specifying the lifespan as a string instead of number worked.

hima-egen avatar Feb 25 '19 04:02 hima-egen

Is there a plan to fix this , I am facing similar issue with Inline Editor ( Firebase ) version of dialogflow

maheshmahadevan avatar Mar 07 '19 12:03 maheshmahadevan

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.

cdharris avatar Apr 12 '19 18:04 cdharris

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?????

mwoyden avatar May 14 '19 15:05 mwoyden

I think contexts can be cleared by setting the lifespan to -1. This worked for me.

revs1 avatar Mar 24 '20 10:03 revs1

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:

image

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.

czajkuba avatar Jul 17 '20 14:07 czajkuba

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

TharakaSl avatar Oct 19 '20 07:10 TharakaSl

This works for me

`agent.context.set("currentintent-followup", 5, {});`

botchway44 avatar Dec 01 '21 10:12 botchway44