GoogleCloudPlatform / dialogflow-integrations

Dialogflow integrations with multiple platforms including KIK, Skype, Spark, Twlio, Twitter and Viber
https://cloud.google.com/dialogflow/
Apache License 2.0
256 stars 503 forks source link

Setting Environment to use with Integration #21

Open diamondobama opened 4 years ago

diamondobama commented 4 years ago

On the console, we are able to specify which environment to deploy to a particular integration and we are able to deploy incrementally with versions. For instance: we have Draft, QA, Staging, and Production.

How do we do the same with Cloud Run? Right now it seems to just use whatever is in the draft.

diamondobama commented 4 years ago

Ok, I managed to solve this by digging a little deeper into the source code. I will outline my steps below.

constructor(projectId){
  this.sessionClient = new dialogflow.SessionsClient();
  this.projectId = projectId;
}

to

constructor(projectId, environmentId, userId){
  this.sessionClient = new dialogflow.v2beta1.SessionsClient();
  this.projectId = projectId;
  this.environmentId = environmentId;
  this.userId = userId;
}
const sessionPath = this.sessionClient.sessionPath(
        this.projectId, sessionId);

to

const sessionPath = this.sessionClient.environmentSessionPath(
        this.projectId, this.environmentId, this.userId, sessionId);
const environmentId = 'YOUR_ENVIRONMENT_NAME';
const userId = 'ANY_36_CHARACTER_OR_LESS';

In the same server.js, change this line

const sessionClient = new dialogflowSessionClient(projectId);

to

const sessionClient = new dialogflowSessionClient(projectId, environmentId, userId);

Then re-deploy your integration using Cloud Run as per the instructions in the README.md

I will leave this open for now, for future visitors to easily find.

tyhu-google commented 4 years ago

diamondobama, thanks for reporting the issue. Dialogflow team will be working on an improvement to support environment.