Connect Wati to ChatGPT: Automate WhatsApp Messaging & Campaigns
Learn how to connect Wati to ChatGPT using an auto-generated MCP server. Automate WhatsApp templates, support handoffs, and customer campaigns.
If you want to connect Wati to ChatGPT so your AI agents can orchestrate WhatsApp marketing campaigns, update customer CRM attributes, or triage inbound support conversations, you need a Model Context Protocol (MCP) server. This server acts as the translation layer between ChatGPT's JSON-RPC tool calls and Wati's underlying REST APIs.
If your team uses Claude, check out our guide on connecting Wati to Claude or explore our broader architectural overview on connecting Wati to AI Agents.
Giving a Large Language Model (LLM) raw read and write access to a high-volume WhatsApp Business API like Wati is a massive engineering undertaking. You either spend weeks building, hosting, and maintaining a custom MCP server to translate LLM JSON arguments into Wati's highly specific payload structures, or you use a managed infrastructure layer to dynamically generate a secure, authenticated MCP server URL.
This guide breaks down exactly how to use Truto to generate a secure MCP server for Wati, connect it natively to ChatGPT, and execute complex WhatsApp workflows using natural language.
Stop writing boilerplate API integration code. Let Truto generate secure, managed MCP servers for your AI agents in seconds. :::
The Engineering Reality of the Wati API
A custom MCP server is essentially a self-hosted integration layer. While the open MCP standard provides a predictable way for models to discover tools, implementing it against Wati's specific API quirks is notoriously difficult.
If you decide to build a custom MCP server for Wati, you own the entire API lifecycle. Here are the specific integration challenges you will face when mapping LLM function calls to Wati's endpoints:
The 24-Hour WhatsApp Session Window
Wati is built on top of the Meta WhatsApp Business API, meaning it inherits Meta's strict rules of engagement. You cannot simply send arbitrary text to a user at any time. If a user has interacted with your Wati number within the last 24 hours, the session is "open," and you can use standard session messaging (wati_conversations_send_session_message_v_1).
If the 24-hour window has expired, session messages will fail. You must instead fall back to a pre-approved template message (wati_message_templates_send). Your MCP server must expose both methods to the LLM, and you must carefully prompt your AI agent to catch session-expired errors and seamlessly pivot to sending a template.
Polymorphic Target Identifiers
Wati's API is highly flexible but heavily relies on polymorphic identifiers. Endpoints like wati_contacts_assign_teams, get_single_wati_contact_by_id, and conversation operators accept a dynamic target. The target could be a ContactId, a raw PhoneNumber, a BSUID, or a prefixed Channel:format identifier.
If you build a static MCP schema for Wati, you have to write middleware that infers which identifier type the LLM decided to emit, validates it against Wati's expected formats, and routes it to the correct query parameter or body field. If you skip this, the LLM will hallucinate invalid identifier structures and crash your agent.
Flat Input Namespaces vs Nested JSON
When an MCP client like ChatGPT calls a tool, all arguments arrive as a single, flat JSON object. However, Wati's API often requires specific arguments in the URL query string and others deeply nested in the HTTP body.
Truto's architecture solves this by dynamically reading the Wati OpenAPI documentation and splitting the flat LLM arguments into query parameters and body parameters using the schema's property keys. This allows the LLM to pass a flat object like {"whatsapp_number": "123", "messageText": "Hello"}, which Truto then intelligently maps to the correct HTTP locations before proxying the request to Wati.
Rate Limits and the 429 Reality
If you unleash an aggressive, multi-step LLM planner on a Wati workspace, you will hit rate limits.
A crucial architectural note: Truto proxies Wati rate limits directly. We do not automatically retry, throttle, or absorb 429 Too Many Requests errors. Instead, Truto normalizes Wati's rate limit information into standardized IETF headers (ratelimit-limit, ratelimit-remaining, and ratelimit-reset). When Wati returns a 429, Truto passes that error directly back to the caller. Your client or agent orchestrator is responsible for reading these headers and implementing backoff logic.
Generating a Wati MCP Server
Truto dynamically generates MCP tools based on Wati's documentation and resource configurations. A tool only appears in the MCP server if it has a corresponding documentation entry, ensuring the LLM only interacts with curated, well-described endpoints.
Every MCP server is scoped to a single integrated account (a specific connected instance of Wati for a single tenant) and relies on a cryptographic token embedded in the URL. There is no client-side configuration needed beyond passing this URL to ChatGPT.
You can generate this server via the Truto UI or programmatically via the API.
Method 1: Via the Truto UI
For internal tooling, quick prototypes, or one-off agent deployments, generating the server in the UI takes seconds:
- Log into your Truto dashboard and navigate to Integrated Accounts.
- Select your connected Wati account.
- Click the MCP Servers tab.
- Click Create MCP Server.
- Select your desired configuration. You can optionally restrict the server to specific tags (e.g.,
contacts,conversations) or specific HTTP methods (e.g.,read,write). - Copy the generated MCP server URL (it will look like
https://api.truto.one/mcp/a1b2c3d4...). Treat this URL as a sensitive credential.
Method 2: Via the Truto API
For production B2B SaaS applications where you need to spin up AI agents for hundreds of users dynamically, you generate the MCP server programmatically.
Send an authenticated POST request to the Truto API specifying the integrated_account_id:
curl -X POST https://api.truto.one/integrated-account/$INTEGRATED_ACCOUNT_ID/mcp \
-H "Authorization: Bearer $TRUTO_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Wati Marketing Agent MCP",
"config": {
"methods": ["read", "write", "custom"],
"tags": ["contacts", "broadcasts", "templates"]
}
}'Truto validates that the integration has tools available, generates a secure token, provisions the required KV storage mappings, and returns a ready-to-use URL:
{
"id": "mcp_12345abcd",
"name": "Wati Marketing Agent MCP",
"config": {
"methods": ["read", "write", "custom"],
"tags": ["contacts", "broadcasts", "templates"]
},
"expires_at": null,
"url": "https://api.truto.one/mcp/a1b2c3d4e5f67890"
}Connecting the MCP Server to ChatGPT
Once you have the Truto MCP server URL, you must register it with ChatGPT so the LLM can discover the available Wati tools via the JSON-RPC tools/list handshake.
Method 1: Via the ChatGPT UI (Custom Connectors)
If you are using a ChatGPT Pro, Plus, Business, Enterprise, or Education account, you can plug the MCP server directly into the web interface.
- In ChatGPT, click your profile and navigate to Settings -> Apps -> Advanced settings.
- Toggle Developer mode to ON.
- Under MCP servers / Custom connectors, click Add new server.
- Enter a descriptive name (e.g., "Wati Automation by Truto").
- Paste the Truto MCP URL into the Server URL field and click Add.
ChatGPT will immediately ping the endpoint, execute the initialize protocol, fetch the schemas, and populate your available tools.
Method 2: Via Local Configuration File
If you are running agents locally via a CLI interface, testing with custom orchestrators, or using an environment that relies on standard MCP config files (like Claude Desktop or custom LangGraph setups), you can use the official Server-Sent Events (SSE) wrapper.
Create an mcp-config.json file:
{
"mcpServers": {
"wati_truto": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-sse",
"--url",
"https://api.truto.one/mcp/a1b2c3d4e5f67890"
]
}
}
}When your agent boots up, it will execute this command, tunneling the local standard I/O into HTTP POST requests against the Truto proxy.
Hero Tools for Wati Automation
When ChatGPT connects to your Wati MCP server, Truto dynamically translates Wati's OpenAPI specs into descriptive snake_case tools. Below are the highest-leverage operations for building intelligent WhatsApp agents.
(Note: Truto auto-injects required LLM hints, such as limit and next_cursor instructions for paginated lists, directly into the JSON schemas).
wati_conversations_send_session_message_v_1
This is the core tool for real-time chat. It allows the LLM to send free-form text messages to an open WhatsApp session in Wati. The LLM must supply a valid whatsapp_number (or polymorphic target). Because this is a session message, it will fail if the user hasn't interacted in 24 hours.
"Send a WhatsApp message to +1234567890 saying 'Your support ticket has been updated. Can you confirm if the issue is resolved?' using the session messaging endpoint."
create_a_wati_message_template
Allows your agent to programmatically draft new WhatsApp message templates within a specific category and language. The LLM can generate the body, header, and interactive buttons based on a marketing prompt.
"Draft a new Wati message template named 'winter_sale_promo'. The category is MARKETING, language is en_US. Include a body offering 20% off and a call-to-action button saying 'Shop Now'."
wati_message_templates_send
The fallback tool for outbound campaigns and expired sessions. This sends pre-approved WhatsApp template messages to multiple recipients simultaneously. The LLM must provide the exact template_name, a broadcast_name, and the list of recipients.
"The session for +1987654321 is expired. Send them the 'appointment_reminder' template message instead under the broadcast name 'AI_Followup_Jan'."
wati_contacts_update_attributes_multi
Perfect for agents conducting data enrichment or lead qualification over chat. This tool updates custom attributes for multiple Wati contacts in a single request. The LLM parses the conversation, identifies key data points (like company size or budget), and updates the Wati CRM records.
"Update the custom attributes for contact +1122334455. Set their 'Lead Status' to 'Qualified' and 'Company Size' to '50-200' based on our chat history."
wati_conversations_assign_operator
Crucial for support triage. When the AI agent determines a customer is frustrated, or the query requires human intervention, this tool routes the conversation to a specific human operator by email or removes the bot assignment.
"The user is asking for a refund and seems upset. Assign this conversation to support@company.com so a human agent can take over."
list_all_wati_broadcasts
Allows the LLM to pull historical campaign data, filter it by date range, and analyze performance. Truto automatically injects pagination context so the LLM knows how to handle the next_cursor if the data exceeds the 100-item limit.
"List all Wati broadcasts created between January 1st and January 31st. Tell me how many campaigns we ran last month."
For the complete tool inventory, request body schemas, and pagination logic, visit the Wati Integration Page.
Workflows in Action
Once the tools are mapped, ChatGPT can chain them together to execute multi-step workflows. Here is how a standard natural language prompt translates into orchestrated API calls.
Scenario 1: Support Triage and Human Handoff
The User Prompt:
"Check the recent messages for phone number +15550199. If they are asking for a refund, update their contact attribute 'Risk Level' to 'High', send a session message apologizing for the delay, and assign the chat to human support."
The Execution Flow:
sequenceDiagram
participant User as ChatGPT (User Prompt)
participant TrutoMCP as Truto MCP Server
participant WatiAPI as Wati API
User->>TrutoMCP: Call wati_conversations_list_messages_v_1
TrutoMCP->>WatiAPI: GET /api/v1/getMessages/{target}
WatiAPI-->>TrutoMCP: Returns message history
TrutoMCP-->>User: JSON response (messages)
Note over User: LLM analyzes text, detects refund request.
User->>TrutoMCP: Call wati_contacts_update_attributes
TrutoMCP->>WatiAPI: POST /api/v1/updateContactAttributes
WatiAPI-->>TrutoMCP: Success
TrutoMCP-->>User: JSON response
User->>TrutoMCP: Call wati_conversations_send_session_message_v_1
TrutoMCP->>WatiAPI: POST /api/v1/sendSessionMessage
WatiAPI-->>TrutoMCP: Message Sent
TrutoMCP-->>User: JSON response
User->>TrutoMCP: Call wati_conversations_assign_operator
TrutoMCP->>WatiAPI: POST /api/v1/assignOperator
WatiAPI-->>TrutoMCP: Success
TrutoMCP-->>User: Task completedWhat happens:
- ChatGPT calls
wati_conversations_list_messages_v_1to pull the recent chat history for the target. - The model processes the text, confirms the user is requesting a refund, and formulates an apology.
- ChatGPT calls
wati_contacts_update_attributesto tag the user as "High" risk. - It executes
wati_conversations_send_session_message_v_1to send the apology. - Finally, it uses
wati_conversations_assign_operatorto route the ticket to the human queue.
Scenario 2: Lead Re-engagement with Templates
The User Prompt:
"Find the contact with ID 98765. I want to follow up with them about their abandoned cart. Send them a session message first. If the session has expired, fall back to sending the 'abandoned_cart_v2' template."
The Execution Flow:
- ChatGPT calls
wati_conversations_send_session_message_v_1using the target98765. - Wati rejects the request with a 400 series error indicating the 24-hour session window has expired.
- Truto passes this error directly back to ChatGPT.
- Recognizing the error matching its instructions, ChatGPT immediately pivots and calls
wati_message_templates_send. - It passes
abandoned_cart_v2as thetemplate_name, maps the recipient ID, and successfully dispatches the outbound WhatsApp template.
Security and Access Control
Exposing a production WhatsApp Business API to an LLM requires strict boundary setting. Truto's MCP servers allow you to tightly scope what ChatGPT can see and do at the moment of server creation:
- Method Filtering (
config.methods): Restrict the server to safe operations. Settingmethods: ["read"]ensures the LLM can onlygetorlistcontacts and broadcasts, completely stripping its ability tocreate,update, or send messages. - Tag Filtering (
config.tags): Wati endpoints are grouped by resource tags (e.g.,contacts,broadcasts,templates). Passingtags: ["contacts"]ensures the server only exposes contact management tools, hiding all conversation and billing endpoints from the model. - Extra Authentication (
require_api_token_auth): By default, possessing the MCP URL grants access. For higher security, enabling this flag forces the MCP client to also pass a valid Truto API Bearer token in the headers, adding a secondary layer of authentication. - Time-To-Live (
expires_at): You can generate temporary, short-lived MCP servers for contractors or temporary AI workflows by passing an ISO datetime. Truto's infrastructure will automatically revoke the credentials and destroy the server endpoint at the exact expiration time.
Final Thoughts
Integrating AI with WhatsApp requires more than just formatting JSON. You have to navigate polymorphic IDs, strict session windows, and complex pagination schemas. By leveraging Truto's auto-generated MCP servers, you eliminate the need to write custom integration code, handle API upgrades, or manage infrastructure.
Your engineering team can focus on designing the actual AI prompts and agent behavior, while Truto handles the translation layer between ChatGPT's function calls and Wati's REST architecture.
Ready to connect your AI agents to Wati? Let Truto handle the integration boilerplate so you can focus on building intelligent workflows. :::
FAQ
- How does ChatGPT authenticate with the Wati API?
- ChatGPT uses a secure Model Context Protocol (MCP) server URL generated by Truto. This single URL contains an encrypted token that routes requests to your specific Wati integrated account, handling the underlying API authentication automatically.
- Can I restrict ChatGPT to only read Wati contacts without sending messages?
- Yes. When generating the MCP server in Truto, you can apply method filtering (e.g., passing 'read' or specific tags) to ensure the LLM only has access to safe, read-only operations.
- Does Truto automatically handle Wati rate limits?
- No. Truto proxies the Wati API directly and normalizes rate limit data into standard IETF headers (ratelimit-limit, ratelimit-remaining, ratelimit-reset). If a 429 Too Many Requests error occurs, Truto passes it to the client, which is responsible for implementing retry and backoff logic.
- How do I deal with WhatsApp's 24-hour session window in ChatGPT?
- You must expose both the session messaging tools and the template messaging tools to ChatGPT. If an agent attempts a session message and receives a window-expired error, you can prompt the LLM to fallback to a pre-approved WhatsApp template tool.