WebhookClient - getContext()
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.
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?
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?
try this. It may help you to fix this bug let res = agent.getContext.name;