← Blog

·

How to integrate the WhatsApp API using AI (Claude Code, Cursor) from the documentation

Updated on November 10, 2026

To integrate the WhatsApp Business API using AI, give the assistant the official documentation as context (the docs’ llms.txt file, Markdown versions of the pages or the docs search MCP server), ask for one small, specific task at a time and review the generated code before deploying, especially the token, webhook signature, idempotency and retries. Without the docs in context, models tend to mix old API versions, unofficial libraries and fields that don’t exist.

This guide shows how to set up context in Claude Code and Cursor, sample prompts for the three parts of an integration and a security review checklist.

Why AI gets it wrong without the docs

Coding assistants answer from what they learned in training and what you put in context. With the WhatsApp API, that leads to predictable mistakes:

  • Outdated versions and routes. The Graph API changes versions often, and pricing and template rules have changed several times in recent years.
  • Mixing in unofficial APIs. Libraries that automate WhatsApp Web, such as Baileys, appear in many public examples and have nothing to do with the official WhatsApp API.
  • Invented fields. The model fills the JSON with plausible names the API rejects.
  • Unsafe shortcuts. A hard-coded token, a webhook with no signature check, retrying every error.

The fix isn’t longer prompts. It’s putting the right documentation in context and reviewing the output carefully.

Step 1: give the assistant the docs as context

Many documentation sites now publish an llms.txt file: a Markdown index with the title, description and link of every page, meant to be read by models. Before you start, check whether the docs you’ll use offer one.

Vectalk’s documentation, for example, offers these formats, checked on November 10, 2026:

FormatAddressWhen to use
Indexhttps://docs.vectalk.com.br/llms.txtLet the assistant discover which pages exist and open only what it needs
Full documentationhttps://docs.vectalk.com.br/llms-full.txtSave it in the repo and attach the whole thing to context
Single pageThe page URL ending in .md, e.g. https://docs.vectalk.com.br/quickstart.mdFor one specific task, such as sending a template or registering a webhook
Docs search MCP serverhttps://docs.vectalk.com.br/mcpLet the assistant search the docs on its own during the task

If you integrate directly with Meta, the source of truth is the Cloud API documentation on developers.facebook.com. Save the pages you’ll use (sending messages, webhooks, error codes) and hand them to the assistant.

In Claude Code

Claude Code reads a CLAUDE.md file at the project root at the start of every session, and can also read an AGENTS.md, according to the Claude Code memory docs. Use that file to pin the integration rules and point to the documentation:

mkdir -p docs/vendor
curl -sS https://docs.vectalk.com.br/llms-full.txt -o docs/vendor/vectalk-llms-full.txt

cat > CLAUDE.md <<'EOF'
## WhatsApp integration
- Source of truth: docs/vendor/vectalk-llms-full.txt and https://docs.vectalk.com.br/llms.txt.
- Don't invent endpoints or fields: cite the doc page for every new call.
- Sending: POST https://apis.vectalk.com.br/api/messages with Authorization: Bearer.
- Token only in an environment variable (WA_TOKEN). Never in code, logs or tests.
- Don't use unofficial WhatsApp libraries (Baileys, whatsapp-web.js, etc.).
- Retry only transient errors; parameter errors are never retried.
EOF

To let the assistant look things up on demand, add the docs search MCP server. The claude mcp add --transport http command registers remote servers, per the Claude Code MCP docs:

claude mcp add --transport http vectalk-docs https://docs.vectalk.com.br/mcp

This server only searches the public docs; it doesn’t send messages. If you want an agent to send WhatsApp messages, that’s a different setup, covered in WhatsApp MCP server.

In Cursor

In Cursor, project rules live in .cursor/rules as .mdc files with description, globs and alwaysApply in the frontmatter; if you prefer plain Markdown, use AGENTS.md, per Cursor’s rules documentation. The same content as the CLAUDE.md above works as a rule.

To attach the docs to a conversation, @-mention the saved file, for example @docs/vendor/vectalk-llms-full.txt. Remote MCP servers are configured in mcp.json with a url field, per Cursor’s MCP documentation:

{
  "mcpServers": {
    "vectalk-docs": {
      "url": "https://docs.vectalk.com.br/mcp"
    }
  }
}

Want to try it while you read? Create a Vectalk account and send your first message through the official API. Create free account →

Step 2: ask for one piece at a time

A WhatsApp API integration has three parts: sending, the webhook and failure handling. Ask for one at a time, with explicit acceptance criteria. Prompts that work:

  1. Template send. “Using only the docs in docs/vendor, write a Node.js function sendTemplate(to, name, lang, params) that sends a template. Read the token from process.env.WA_TOKEN, use a 15-second timeout, return the wamid and throw an error with the API’s error.code on failure. Cite the doc page you used.”
  2. Webhook. “Write an Express endpoint POST /webhooks/whatsapp that returns 200 immediately, pushes the event to a queue and processes it later. Deduplicate by the message or status id. Write tests using the sample payloads from the webhooks page.”
  3. Failures and retries. “Classify API errors as transient or permanent based on the error codes table. Only transient ones get retried, with exponential backoff and a maximum number of attempts.”

Three habits help a lot: ask the assistant to cite the page it used, ask for tests built on the docs’ sample payloads and ask for a plan before code when the task touches more than one file. For the third part, the reference architecture is in queues, retries and idempotency and the queue code in WhatsApp API send queue with Redis and BullMQ.

Step 3: security-review the generated code

AI-generated code compiles, passes the happy-path test and can still have serious flaws. Check every item below before deploying:

ItemWhat to look forWhy it matters
TokenToken hard-coded in code, tests, console.log or error messagesWhoever has the token can send as your business and spend your balance
Webhook signatureWith Meta directly: HMAC SHA-256 of the raw body with the app secret, compared in constant timeWithout it, anyone can forge events
Raw bodyThe framework ran JSON.parse before validationThe signature won’t match a re-serialized body
IdempotencyDeduplication by id before processingMeta can redeliver the same event
RetriesRetrying parameter or policy errorsWaste, and a risk of being blocked
Webhook responseHeavy processing before returning 200Timeouts and redeliveries
Personal dataLogs with phone numbers and message contentUnnecessary exposure under privacy laws such as Brazil’s LGPD or the GDPR
DependenciesPackages you don’t recognize or that don’t existHallucinated names can be registered by third parties with malicious code
LibraryAn unofficial WhatsApp libraryIt isn’t the official API and can get the number banned

Signature validation, with examples in several languages, is covered in how to validate the webhook signature. On personal data: privacy laws apply to what you store in logs and databases; this guidance isn’t legal advice.

Two more practices:

  • Don’t paste the production token into the chat. Use environment variables and a test number during development.
  • Run the code against the real API before trusting it. One real send to your own number and one real webhook received are worth more than ten reviews. A hand-written reference project, such as the WhatsApp bot with Node.js, is useful for comparison.

How to do it with Vectalk

Vectalk’s documentation is ready for AI assistants: llms.txt, llms-full.txt, .md pages and a docs search MCP server at https://docs.vectalk.com.br/mcp. The API follows Meta’s Cloud API format: sends go to POST https://apis.vectalk.com.br/api/messages with a Bearer token, and events arrive in Meta’s webhook format, per the quickstart and the webhooks page. So code generated from Meta’s docs usually only needs a different base URL and token.

Use an instance token during development: it’s limited to one number and can be revoked in the dashboard at any time, per the tokens page. Vectalk has no built-in AI or chatbot in its dashboard; the code and the agent are yours. Sign up at apps.vectalk.com.br/register. If the integration will run in a mobile app, see also WhatsApp Business API in Flutter and FlutterFlow.

Frequently asked questions

Do I need the MCP server, or is llms.txt enough?

For most tasks, llms.txt or llms-full.txt saved in the repo is enough. MCP helps on long tasks where the assistant needs to search many pages without you pasting them one by one.

What’s the difference between llms.txt and llms-full.txt?

llms.txt is an index with a link to each page. llms-full.txt contains the entire documentation in a single file. The index uses less context; the full file avoids back-and-forth.

Can AI send WhatsApp messages on its own?

Yes, if you give it a sending tool, such as your own MCP server. That’s different from using AI to write the integration code, and it requires human confirmation, template controls and attention to Meta’s policies.

Does this work with assistants other than Claude Code and Cursor?

Yes. Any assistant that can read project files or URLs can use llms.txt. How you pin rules varies by tool, but AGENTS.md is read by several of them.

Is the generated code production-ready?

Not without review. Go through the security checklist, run tests with real payloads and do a real send before you ship.


Official sources checked on November 10, 2026: Claude Code: memory and CLAUDE.md, Claude Code: MCP, Cursor: rules, Cursor: MCP, Meta: webhooks, Meta: error codes, Vectalk: llms.txt, Vectalk: quickstart, Vectalk: webhooks, Vectalk: tokens.

Put your business on the official WhatsApp

Create your account, connect your number to the official API (you can keep the app with coexistence) and start serving customers and sending messages.