How to Integrate Dialogflow ES with Twilio SMS - twilio

Has anyone worked on how to integrate Twilio with Dialogflow so people can text a number in their phones and get answers from Dialogflow?
I have looked everywhere and no luck.
The documentation I found on the Dialogflow integrations session was not very helpful:
https://github.com/GoogleCloudPlatform/dialogflow-integrations/tree/master/twilio#readme

I was able to do it and integrated my nodejs app that is a custom for Dialogflow with Twilio.
The documentation is a little confusing but these are the steps:
Requirements:
Twilio account
Dialogflow Agent
Create a Service account in GCP with role: Dialogflow Client API, create a key and save json file (If deploying using Cloud Run).
Enable Cloud Build and Cloud Run API
Setup Gcloud command line tool
Getting Started:
Clone and open the repository for Dialogflow Open Source Integrations: https://github.com/GoogleCloudPlatform/dialogflow-integrations.git
Open Twilio’s folder inside dialogflow-integrations with an editor and open the Dockerfile. Change the ENV INTEGRATION=YOUR_INTEGRATION to ENV INTEGRATION=twilio, then open server.js and. update projectId with Dialogflow’s project ID, accountSid, AuthToken, phoneNumber with Twilio’s Account SID and Auth Token and Phone Number.
Purchase a number with Twilio
Run these commands inside dialogflow-integrations folder:
gcloud init
gcloud config set project dialogflow-proj-name
gcloud config get-value project (to make sure the variable is set)
gcloud builds submit --tag http://gcr.io/dialogflow-proj-name/dialogflow-twilio
gcloud beta run deploy --image http://gcr.io/dialogflow-proj-name/dialogflow-twilio --update-env-vars GOOGLE_APPLICATION_CREDENTIALS=key_that_you_downloaded_previously.json --memory 1Gi
Copy the URL provided
Go to Twilio’s portal and in the "Phone Number" section, go to Active Numbers and click on the purchased number. In "Messaging", paste URL by "A message comes in" and HTTP POST box field. Set the drop-down to Webhook and the HTTP method to HTTP POST.

Related

Permission error in GCP when creating a new compute instance but service account does have permissions

I am running a cloudbuild.yaml job in Google Cloud Platform that builds, pushes and tags a Docker Image and then it creates a Compute Engine instance to run that image via gcr.io/cloud-builders/gcloud.create-with-container. I also specify a service account to be used in this step:
- id: "Create Compute Engine instance"
name: gcr.io/cloud-builders/gcloud
args: [
'compute',
'instances',
'create-with-container',
'${INSTANCE_NAME}',
'--container-image',
'eu.gcr.io/${PROJECT_ID}/${PROJECT_ID}-${REPO_NAME}',
'--zone',
'${ZONE}',
'--service-account',
'${SERVICE_ACCOUNT},
'--machine-type',
'n2-standard-4'
]
However I am getting an error:
Already have image (with digest): gcr.io/cloud-builders/gcloud
ERROR: (gcloud.compute.instances.create-with-container) Could not fetch resource:
- Required 'compute.instances.create' permission for 'projects/...'
The service account in use does have the permissions for that as it has been assigned "role": "roles/compute.instanceAdmin.v1", which includes compute.instances.* as per documentation.
Anyone has experienced this or a similar situation and can give a hint on how to proceed? Am I missing something obvious? I have tried using other service accounts, including the project default compute account and get the same error. One thing to note is I do not specify a service account for Docker steps (gcr.io/cloud-builders/docker).
Make sure that you are not misinterpreting service accounts.
There is a special service account used by Cloud Build.
There is also the service account to "be used" by the VM/instance you are creating.
The "compute.instances.create" permission should be granted to the special Cloud Build account, not to the account for the instance.
The Cloud Build account has a name like 123123123#cloudbuild.gserviceaccount.com.
In the Cloud Console go to Cloud Build -> Settings -> Service Accounts
and check if correct permissions are granted.

GCP Cloud Run Cannot Pull Image from Artifact Registry in Other Project

I have a parent project that has an artifact registry configured for docker.
A child project has a cloud run service that needs to pull its image from the parent.
The child project also has a service account that is authorized to access the repository via an IAM role roles/artifactregistry.writer.
When I try to start my service I get an error message:
Google Cloud Run Service Agent must have permission to read the image,
europe-west1-docker.pkg.dev/test-parent-project/docker-webank-private/node:custom-1.
Ensure that the provided container image URL is correct and that the
above account has permission to access the image. If you just enabled
the Cloud Run API, the permissions might take a few minutes to
propagate. Note that the image is from project [test-parent-project], which
is not the same as this project [test-child-project]. Permission must be
granted to the Google Cloud Run Service Agent from this project.
I have tested manually connecting with docker login and using the service account's private key and the docker pull command works perfectly from my PC.
cat $GOOGLE_APPLICATION_CREDENTIALS | docker login -u _json_key --password-stdin https://europe-west1-docker.pkg.dev
> Login succeeded
docker pull europe-west1-docker.pkg.dev/bfb-cicd-inno0/docker-webank-private/node:custom-1
> OK
The service account is also attached to the cloud run service:
You have 2 types of service account used in Cloud Run:
The Google Cloud Run API service account
The Runtime service account.
In your explanation, and your screenshot, you talk about the runtime service account, the identity that will be used by the service when it runs and call Google Cloud API.
BUT before running, the service must be deployed. This time, it's a Google Cloud Run internal process that run to pull the container, create a revision and do all the required internal stuff. To do that job, a service account also exist, it's named "service agent".
In the IAM console, you can find it: the format is the following
service-<PROJECT_NUMBER>#serverless-robot-prod.iam.gserviceaccount.com
Don't forget to tick the checkbox in the upper right corner to include the Google Managed service account
If you want that this deployment service account be able to pull image in another project, grant on it the correct permission, not on the runtime service account.

Programmatically check if Cloud Run domain mapping has done

I'm developing a service which will have a subdomain for each customer. So far I've set a DNS rule on Google Domains as
* | CNAME | 3600 | ghs.googlehosted.com.
and then I add the mapping for each subdomain in the Cloud Run console. I want to do all this programmatically everytime a new user registers.
The DNS rule will handle automatically any new subdomain, and to map it to the service I'll use the gcloud command:
gcloud beta run domain-mappings create --service frontend --domain sub.domain.com
Now, how can I check when the Cloud Run provisioning has done so that I can notify the customer that the platform is ready to use? I could CRON every minute the command gcloud beta run domain-mappings describe --domain sub.domain.com, parse the JSON output and check if the status has done. It's expensive, but it should work.
The problem is that even if the gcloud cli or the web console mark the provisioning as done, the platform isn't reachable for another 5-10 minutes, resulting in a ERR_CONNECTION_REFUSED error. The service logs show that a request to the subdomain is being made, but somehow it won't serve it.
I ended up using a load balancer as suggested. I followed this doc "Setting up a load balancer with Cloud Run, App Engine, or Cloud Functions", the only different thing is that I provided my own wildcard certificate (thanks to Let's Encrypt and certbox).
Now I can just use the Google Domains' API to instantly create a subdomain.

Dialogflow Integration with Twitter

I have followed the steps given for integrating with Twitter https://github.com/GoogleCloudPlatform/dialogflow-integrations but I am not able to find the server URL
When command gcloud beta run deploy is executed successfully, it will explicitly prompt in the CLI Service URL: https://dialogflow-PLATFORM-xxxxxxxx-xx.x.run.app and this will be the server URL.
In case you missed it in the CLI you can check it in the GCP console:
Open Cloud Run, it will show all available cloud run services
Select the recently deployed Dialogflow service
Click "Details" tab. This tab will contain information including the server URL
These fields are Region,URL, Last revision deployed
Copy value for URL as this is your Service URL.
For testing I deployed a simple helloworld app. Sample deployed service:

Jenkins in Docker Container and Google Cloud Source Repository - no Credentials visible

I read everything in this post and multiple others but nothing is working... I cannot use Google Credentials to access my git Repo in Google Cloud Platform
I have Jenkins running in a Docker Container in Google Cloud Platform. I have Source Code in a Google Cloud Repository that I want to use for a Build.
On the Google Cloud Platform side I created a Service User, gave the User the following Roles:
Project Worker
Source-Repository Admin
Storageobject creator
ComputeEngine creator
I created the JSON File and downloaded it.
On The Jenkins Side I installed the Google OAuth Credentials and the Google Container Registry Auth Plugin.
I added new Credentials "Google Service Account from private key" and added the json file.
So, if I now want to create a new Job (Freestyle or pipeline does not matter) I see the following:
I see the credentials I created but for the "Google Container Registry". As soon as I add the repository URL, "https://source.developers.google.com/p...." The Drop-down is cleared and all is gone.
I also took a look at the credentials.xml and job file, to see, if I can rewrite there something by myself. The Google Credentials do not have an credentialId like others...
<com.google.jenkins.plugins.credentials.oauth.GoogleRobotPrivateKeyCredentials plugin="google-oauth-plugin#0.6">
<module/>
<projectId>testprojekt</projectId>
<serviceAccountConfig class="com.google.jenkins.plugins.credentials.oauth.JsonServiceAccountConfig">
<jsonKeyFile>/var/jenkins_home/gauth/key8529180263669390055.json</jsonKeyFile>
</serviceAccountConfig>
</com.google.jenkins.plugins.credentials.oauth.GoogleRobotPrivateKeyCredentials>
I'm currently out of ideas... would be happy for any hint.
Thank you!

Resources