View Categories

Connecting Dialogflow CX to Baat

4 min read

This guide walks you through connecting a Google Dialogflow CX agent to your Baat workspace. Once connected, every incoming WhatsApp message is forwarded to your Dialogflow CX agent for intent detection and response generation — no separate webhook wiring required on your end.

Plan requirement: The Dialogflow CX integration is available on the Growth plan and above. If you don’t see the Integrations menu, upgrade your plan first.

Prerequisites #

  • A Google Cloud project with the Dialogflow CX API enabled
  • A Dialogflow CX agent already created in that project (see below if you haven’t created one yet)
  • A GCP service account with the Dialogflow API Client role and a downloaded JSON key
  • Your agent’s Project ID, Agent ID, and Region handy

Step 1 — Enable the Dialogflow CX API in GCP #

  1. Open the Google Cloud Console and select your project.
  2. Go to APIs & Services → Library.
  3. Search for Dialogflow API and click Enable.
The “Dialogflow API” entry in the library covers both ES and CX — enabling it once activates both.

Step 2 — Create a service account and download the JSON key #

  1. In GCP Console go to IAM & Admin → Service Accounts.
  2. Click Create Service Account. Give it a descriptive name such as baat-dialogflow.
  3. On the “Grant access” step, assign the role Dialogflow API Client (roles/dialogflow.client). This is the minimum role needed — it allows session creation and detectIntent calls but nothing destructive.
  4. Click Done.
  5. Find the new service account in the list, click its name, then go to the Keys tab.
  6. Click Add Key → Create new key → JSON. A .json file downloads to your computer.
Keep this file private. The JSON key grants API access to your GCP project. Do not commit it to version control or share it publicly.

Step 3 — Note your Dialogflow CX agent details #

You need three values from the Dialogflow CX console:

Value Where to find it Example
Project ID GCP Console → top of the page next to the project name, or in the JSON key file as "project_id" my-company-prod
Agent ID Dialogflow CX console → select your agent → Agent Settings → the UUID in the page URL or under “Agent ID” a1b2c3d4-e5f6-...
Region Shown when you created the agent (e.g. us-central1, asia-south1). Also visible in the agent URL: dialogflow.cloud.google.com/#/.../asia-south1/... us-central1
Region tip for India: If your customers are primarily in India, choose asia-south1 (Mumbai) when creating the Dialogflow CX agent. This keeps round-trip latency under ~80 ms versus 200–300 ms for us-central1. The region cannot be changed after the agent is created.

Step 4 — Connect in Baat #

  1. In your Baat dashboard, go to Settings → Integrations → Dialogflow CX.
  2. Fill in the following fields:
    • GCP Project ID — the project that owns the agent
    • Agent ID — the UUID of your Dialogflow CX agent
    • Region — must match the region the agent was created in
    • Service Account JSON — paste the full contents of the JSON key file you downloaded in Step 2
  3. Click Connect.

Baat validates the credentials by making a test detectIntent call. If the credentials are valid and the agent is reachable you will see a green Connected status. If validation fails, a descriptive error is shown (see Troubleshooting below).

Step 5 — Test the connection #

Send a WhatsApp message to your connected number from a test phone. Watch the Baat Shared Inbox — the incoming message should appear, and within a second or two the Dialogflow CX response should be delivered back to the test phone.

You can also use the Test button on the Integrations page. Enter any text and Baat will call detectIntent and show you the raw response from Dialogflow CX.

How Baat routes messages to Dialogflow CX #

Once connected, the flow for every inbound WhatsApp message is:

  1. WhatsApp delivers the message to Baat via the Cloud API webhook.
  2. Baat calls the Dialogflow CX detectIntent REST API using the credentials you provided.
  3. The session ID sent to Dialogflow is derived from the customer’s WhatsApp phone number — so each customer gets a persistent Dialogflow session, and context carries across messages.
  4. Dialogflow CX returns fulfillment messages (text, custom payload, or a mix).
  5. Baat delivers the responses to WhatsApp in order.

Text responses from Dialogflow are sent as plain WhatsApp text messages. To send interactive messages (buttons, lists, Flows), use a Custom Payload response in Dialogflow CX with the BAAT_WAC_API wrapper — see Sending Interactive WhatsApp Messages from Dialogflow CX.

Routing: which messages go to Dialogflow? #

By default, all messages on your WhatsApp number are forwarded to Dialogflow CX once the integration is active. You can optionally configure routing rules in Baat to send only certain conversations to Dialogflow (for example, exclude conversations that are already assigned to a human agent). See Settings → Integrations → Dialogflow CX → Routing for options.

Troubleshooting #

Error / symptom Likely cause Fix
Invalid credentials on Connect Service account JSON is malformed, or the account has been deleted Re-download the JSON key from GCP and paste the fresh copy
Permission denied on Connect Service account is missing the Dialogflow API Client role In GCP IAM, add roles/dialogflow.client to the service account
Agent not found Project ID, Agent ID, or Region does not match the agent in GCP Open Dialogflow CX console, copy all three values again carefully — the Agent ID is a UUID, not the display name
Messages arrive in Baat but no reply is sent Dialogflow CX agent has no matched intent for the test input, or the default welcome intent is not enabled Open the Dialogflow CX console, go to Test Agent, send the same message, and check what intent (if any) fires. Add a Default Fallback intent with a response if missing.
Dialogflow replies but WhatsApp shows nothing Custom payload JSON is malformed Check the Baat activity log for the conversation. If the payload failed validation you will see an error alongside the attempted response. Validate your JSON against the interactive messages article.
High latency (>2 s responses) Agent region is us-central1 but users are in India Unfortunately region cannot be changed on an existing agent — create a new agent in asia-south1 and migrate your intents via the Dialogflow CX export/import feature

Disconnecting the integration #

Go to Settings → Integrations → Dialogflow CX and click Disconnect. Baat immediately stops forwarding messages to Dialogflow. Existing conversations in the inbox are unaffected. You can reconnect at any time by filling in the credentials again.

Disconnecting does not delete the Dialogflow CX agent or the GCP service account. You can safely revoke the JSON key from GCP after disconnecting if you no longer need the integration.