sschuf
sschuf

Reputation: 76

Point a specific Dialogflow environment in nodejs

Since DF environments is no longer beta feature, there's no much info and examples about agent versioning and environments.

I have a chatbot in nodejs, I want to use the same DF agent but to have different environments with different intents on each one.

How can i specify the environment in the code? Something like having the environment as argument: I tried this, but instead of getting the specific environmet, I get the active version in agent (version = environment).

Is there a way of pointing the environment, something like:

keys: {
    googleProjectID: 'xxx',
    dialogFlowSessionID: 'xxx',
    dialogFlowSessionLanguageCode: 'xxx',
    dialogFlow_ENVIRONMENT: 'here',
    googleClientEmail: 'xxx',
    googlePrivateKey: 'xxx',
    chatBasePlatformName: 'xxx',
    chatBasePrivateKey: 'xxx'
}

and then define Session Path and SessionClient with the specific environment, like:

const projectId = config[update.payload.training].keys.googleProjectID;
const sessionId = config[update.payload.training].keys.dialogFlowSessionID;
const environment = config[update.payload.training].keys.dialogFlow_ENVIRONMENT;
const languageCode = config[update.payload.training].keys.dialogFlowSessionLanguageCode;
const credentials = {
  client_email: config[update.payload.training].keys.googleClientEmail,
  private_key: config[update.payload.training].keys.googlePrivateKey,
};
const sessionClient = new dialogflow.SessionsClient({projectId, credentials});
const sessionPath = sessionClient.sessionPath(projectId, environment, sessionId + update.sender.id);

Any other suggestion or info is welcome.

Upvotes: 1

Views: 139

Answers (0)

Related Questions