Google Business Messages + Open.AI + OAuth

I have created a chat bot with Open.AI and have it setup doing many things such as answering online chats, emails, and even Facebook messages.

Now I am working setting up the chatbot to answer Google Business Messages (BM).

I am able to receive Google BM via a Bubble webhook, and create a chatbot response through Open.AI.

But now I need to send our chatbot response back to the user via the Google BM API, using the below call and Oauth. I have always been confused by Oauth actions. Hoping someone good give me some advice on how to set this up so I can make the call.

**I already have the service account, private key, private key id, client ID and so on. Just need to know how to set it up in bubble.

Redacted - Oauth /Service Account Key File.
{
“type”: “service_account”,
“project_id”: “gbc-wyoming-bail-agenc-ag4qufi”,
“private_key_id”: “ENTER KEY”,
“private_key”: “-----BEGIN PRIVATE KEY-----ENTER KEY=\n-----END PRIVATE KEY-----\n”,
“client_email”: “solution-provider@gbc-wyoming-bail-agenc-ag4qufi.iam.gserviceaccount.com”,
“client_id”: “123456789103”,
“auth_uri”: “Sign in - Google Accounts”,
“token_uri”: “https://oauth2.googleapis.com/token”,
“auth_provider_x509_cert_url”: “https://www.googleapis.com/oauth2/v1/certs”,
“client_x509_cert_url”: “https://www.googleapis.com/robot/v1/metadata/x509/solution-provider%40gbc-wyoming-bail-agenc-ag4qufi.iam.gserviceaccount.com”,
“universe_domain”: “googleapis.com
}

API Endpoint

This code sends a text message to the user.

Read more: Send messages  |  Business Messages  |  Google for Developers

Replace the CONVERSATION_ID with a conversation id that you can send messages to

Make sure a service account key file exists at ./service_account_key.json

}
curl -X POST “https://businessmessages.googleapis.com/v1/conversations/__CONVERSATION_ID__/messages
-H “Content-Type: application/json”
-H “User-Agent: curl/business-messages”
-H “$(oauth2l header --json ./service_account_key.json businessmessages)”
-d "{
‘messageId’: ‘$(uuidgen)’,
‘text’: ‘Hello world!’,
‘representative’: {
‘avatarImage’: ‘https://developers.google.com/identity/images/g-logo.png’,
‘displayName’: ‘Chatbot’,
‘representativeType’: ‘BOT’
}
}

Tia!

How you got access to GMB api?

Created a partner account. That part was pretty simple. I am still waiting on approval before I can launch, but testing and development are still available.

Can you help me with this process?

Google has been migrating GBM since March 2022, and it does not appear that everything is quite done yet. So some of the Google doc is outdated, but I followed the information at the below link and was able to get things setup fairly easy, although there was some confusion at first. For instance, you will need a service account but with GBM you no longer set the service account up through Google Cloud API console.

You may be required to setup a developers account, but that is fairly easy also.

Keep in mind when creating a partner account that they require actual company domain emails, and not user gmail account emails for verification.

1 Like

Update

I could be wrong but,…

From what I gather there does not appear to be a current solution for Bubble,

because Google has migrated GBM to its own API away from Google Cloud APIs, it is no longer setup for Oauth2.0, there is no longer a scope to follow and you can no longer setup a redirect uri.

I guess for now I’ll have to keep answering my own GBM’s. Again, I could be wrong, but I have spent two days looking into this and that’s the best conclusions I could assert with my current knowledge base.

Update 2

When you create a business messages partner account, Google creates a project for you in the Google Cloud API Console. However, that project is not accessible to you in the Google Cloud Console. It appears that is now only ran on Googles backend, and through the Google Communications Developer Console.

If you want to update your redirect url, you can here via the API Autentica con OAuth  |  Business Messages  |  Google for Developers

But you will need the scope.

After looking into this some more, it would appear that the scope is https://www.googleapis.com/auth/businessmessages. Duh… It’s actually right there in the call.

However, if you try to obtain authentication using this scope, you will be met with an error that says you do not have access to the scope.

I assume this is because Google has not verified my agent and activated the scope in our API console. You used to be able to do this yourself when the API was in the Google Cloud Console. Much of Googles documentation still points to the old way of enabling the GBM API.

I could wait to see if I am correct once my agent has been verified, and then try the authentication and call.

However, in the current GBM documentation it says that once an agent is verified the agents redirect url may not be changed.

I reached out to Googles Business Communications team about this.