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

context name in agent.context object always '-' when used with environments

Open woeckener opened this issue 6 years ago • 12 comments

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.

woeckener avatar Nov 21 '18 12:11 woeckener

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

masahills avatar Nov 29 '18 09:11 masahills

Thanks for the report! This will be fixed in 0.6.2

mattcarrollcode avatar Dec 17 '18 00:12 mattcarrollcode

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... :-/

maganap avatar Jan 21 '19 23:01 maganap

Any estimates when dialogflow-fulfillment-nodejs will be working with nodejs-dialogflow lib using v2.beta1?

aponski avatar Mar 14 '19 17:03 aponski

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.

kr05 avatar May 01 '19 04:05 kr05

Any update on this bug?

adhityan26 avatar May 02 '19 09:05 adhityan26

any update on this?

amammay avatar Jun 03 '19 17:06 amammay

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.

Alxandir avatar Jul 04 '19 14:07 Alxandir

Thanks for the report! This will be fixed in 0.6.2

Fixed ?

sashikiran52 avatar Sep 24 '19 12:09 sashikiran52

folks - any updates on this issue? We are facing the same problem

juno-vate avatar Oct 10 '19 10:10 juno-vate

This PR should fix the bug but it does not get merged https://github.com/dialogflow/dialogflow-fulfillment-nodejs/pull/189

fgodino avatar Nov 13 '19 09:11 fgodino

Wow, the PR is still open... what are they waiting for?

vverrastro avatar Mar 31 '21 09:03 vverrastro