Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

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

Open
woeckener opened this issue Nov 21, 2018 · 12 comments
Labels
bug Something isn't working

Comments

@woeckener
Copy link

woeckener commented Nov 21, 2018

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.

@masahills
Copy link

masahills commented Nov 29, 2018

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

@aradwyr aradwyr self-assigned this Dec 11, 2018
@mattcarrollcode mattcarrollcode added the bug Something isn't working label Dec 14, 2018
@mattcarrollcode
Copy link
Contributor

Thanks for the report! This will be fixed in 0.6.2

@maganap
Copy link

maganap commented Jan 21, 2019

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

@aponski
Copy link

aponski commented Mar 14, 2019

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

@kr05
Copy link

kr05 commented May 1, 2019

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.

@adhityan26
Copy link

Any update on this bug?

@amammay
Copy link

amammay commented Jun 3, 2019

any update on this?

@Alxandir
Copy link

Alxandir commented Jul 4, 2019

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.

@sashikiran52
Copy link

Thanks for the report! This will be fixed in 0.6.2

Fixed ?

@juno-vate
Copy link

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

@fgodino
Copy link

fgodino commented Nov 13, 2019

This PR should fix the bug but it does not get merged #189

@vverrastro
Copy link

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

@mattcarrollcode mattcarrollcode removed their assignment Feb 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests