dialogflow-fulfillment-nodejs
dialogflow-fulfillment-nodejs copied to clipboard
context name in agent.context object always '-' when used with environments
Hey!
I came across this bug as I managed my agent with environments. Upon building the contexts in the v2-agents context object the name is set as the substring after the sixth slash.
src/context.js
_processV2InputContexts(v2InputContexts) {
let contexts = {};
for (let index = 0; index<v2InputContexts.length; index++) {
let context = v2InputContexts[index];
const name = context['name'].split('/')[6];
contexts[name] = {
name: name,
lifespan: context['lifespanCount'],
parameters: context['parameters']};
}
return contexts;
}
In cases where the v2InputContexts name includes an environment, the name is build like this:
projects/projectname/agent/environments/environmentname/users/-/sessions/123456/contextname
and the name always turns out to be '-', as that is now the substring after the sixth slash x)
The issue is that none of the actual contexts are stored in agent.context when requesting a specific environment.
Here's an example of workarounds that you can add in your index.js meanwhile.
const agent = new WebhookClient({ request, response });
if (agent.session.indexOf('/agent/environments/') !== -1) {
const requestContexts = request.body.queryResult.outputContexts;
for (let index = 0; index < requestContexts.length; index++) {
const context = requestContexts[index];
const name = context.name.split('/').slice(-1)[0];
agent.context.set(name, context.lifespanCount, context.parameters);
}
}
Thanks for the report! This will be fixed in 0.6.2
omg...
In case it's of any use, here's my session when testing a draft version of AOG: (which does work)
projects/<my-bot-project>/agent/sessions/ABwppHGISLcVmEr57_QqQ9bkadlOXito_HdsZFI1Kps11B-sa_HJeBRBXMaen2dlubYeIy0pn-xYcL3vbsoKvb4nt0_K80k
And here's the session that arrives when the review team is trying to test my submitted version: (which fails miserably)
projects/<my-bot-project>/agent/environments/__aog-3/users/-/sessions/ABwppHER2SeAanA8vZ3FFGhjB7EDm9Sbwf_WzRRSWKllQbN3SoXtyZi-QachDnPgk_Jvcze1ggIWjDFFnrscul8p_4Wd3e0
This is what's causing my bot to be rejected by AOG review team... once, and again... :-/
Any estimates when dialogflow-fulfillment-nodejs will be working with nodejs-dialogflow lib using v2.beta1?
Correct me if I'm wrong, but I think there hasn't been an update in over 7 months. I've been struggling for the past week with random issues, inconsistent documentation, and much sadness over my inability to get this library to work. I really want to get DialogFlow to work for my needs, but it hasn't been too promising.
Any update on this bug?
any update on this?
I'm also keen to get this resolved, especially when the pull request for the fix had a positive comment from Google on 29th November 2018!
In the meantime, rather than using agent.context.get('myContextName')
, I'm using my own function getContext('myContextName')
(defined within the onRequest handler) instead:
function getContext(name){
const contexts = request.body.queryResult.outputContexts;
for(let context of contexts.filter(p => p.name)) {
const splitName = context.name.split('/');
const contextName = splitName[splitName.length - 1];
if(contextName === name) {
return context;
}
}
return undefined;
}
Is an easy fix, but just in case people didn't want to waste additional time.
Thanks for the report! This will be fixed in 0.6.2
Fixed ?
folks - any updates on this issue? We are facing the same problem
This PR should fix the bug but it does not get merged https://github.com/dialogflow/dialogflow-fulfillment-nodejs/pull/189
Wow, the PR is still open... what are they waiting for?