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

WebhookClient - getContext()

Open kingarawana opened this issue 7 years ago • 3 comments

I believe the WebhookClient class has a bug.

when I do this,

let agent = new WebhookClient({request:{body: requestBody}, response:{}});
let ctx = {'name': 'custom_name', 'lifespan': 2, 'parameters': {'city': 'Rome'}};
agent.setContext(ctx);
let res = agent.getContext('custom_name');
console.log(res); // prints null

When I looked into the source code, getContext() was using 'this.contexts', while setContext() was using 'this.outgoingContexts_'

I'd be glad to make the update and submit the pull request if you guys like.

kingarawana avatar May 15 '18 00:05 kingarawana

the getContext() method is meant to get contexts that are current active in the session and not contexts that will be active after the webhook response.

What's your use case for having getContext work for contexts you've just set?

mattcarrollcode avatar May 21 '18 23:05 mattcarrollcode

Hello, @matthewayne. My case is partially related to this one.

The currently available methods to get the contexts, such as .contexts and .getContext(), work as expected, returning current active contexts.

But sometimes we need all the contexts, including outgoing contexts set as in the example above.

Here is the case: As written in the doc, contexts expire in a 10-20 minutes. If we want to restore the conversation after this period, we can apply this solution. So to store all the contexts we should have a possibility to get them in the end of the handling of request.

What do you think on this?

stasusov avatar Jul 25 '18 09:07 stasusov

try this. It may help you to fix this bug let res = agent.getContext.name;

ArsalanSiddique avatar Aug 08 '19 23:08 ArsalanSiddique