> ## Documentation Index
> Fetch the complete documentation index at: https://howto.paigeme.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How your Paige WhatsApp bot code works and is deployed

> Your bot is a Node.js/Express app that runs on Paige's infrastructure. It receives WhatsApp messages, processes them using a state machine, and sends replies.

Every Paige project has a bot codebase — a Node.js/Express application that runs on Paige's managed infrastructure. The code receives incoming WhatsApp messages through a webhook, decides how to respond based on the current conversation state, and sends replies back via the WhatsApp Cloud API. You never manage servers or deployments; Paige handles all of that automatically.

## The state machine pattern

Your bot tracks each contact's position in the conversation using a **state**. The state is a string stored in the database for every contact, and it determines which block of code handles their next message.

There are two types of states:

* **SEND-STATE** — sends a message or interactive UI, then transitions the contact into an AWAIT state.
* **AWAIT-STATE** — receives the user's response and processes it. It may send a reply and transition to another state, or stay in the same state.

You can add as many states as your bot needs. The Code Agent will create the right ones for you when you describe a new flow in plain language.

<Note>
  A contact's state persists across messages. If a contact stops mid-conversation and comes back later, they resume in the same state.
</Note>

## The starter template

When you create a new project, Paige loads a production-ready starter template that handles the plumbing for you. Out of the box it gives you:

* A pre-wired webhook handler with the state machine ready to extend
* Helpers for sending every WhatsApp message type
* Helpers for reading and writing your project's database
* Logging built in for debugging
* A space for AI context documents (knowledge base)

Your project's Postgres database is connected automatically — there is no connection string to configure.

## The Code Agent

You build and edit your bot through Paige's AI chat interface. The Code Agent understands your project's full codebase and uses a built-in toolset on your behalf — it can read and edit project files, manage the database schema and data, create and publish WhatsApp Flows, and create message templates, all without you leaving the conversation.

For details on how to prompt the agent and what it can do, see the [Code Agent](/agents/code-agent) page.

## Version history (commits)

Every time you save changes to your bot code, Paige creates a commit. Commits are snapshots of your entire codebase at a point in time.

<Steps>
  <Step title="Browse your commit history">
    Open the **Version History** panel in the editor to see a list of all commits with timestamps.
  </Step>

  <Step title="Inspect a commit">
    Click any commit to see what changed — which files were added, modified, or deleted.
  </Step>

  <Step title="Restore a commit">
    Click **Restore** on any commit to roll your codebase back to that point. A new commit is created for the restore so you never lose history.
  </Step>
</Steps>

<Tip>
  Commits are created automatically on every save. You don't need to do anything to enable version history — it is always on.
</Tip>

## Live testing

You can test your bot in real time using **Paige Dev** — a shared WhatsApp number maintained by Paige. Scan the QR code or open the link from your project dashboard to start a conversation with your bot running the current code. Live testing does not require you to have your own WhatsApp number connected.

## Message types your bot can send

Your bot can send any of the following message types using built-in messaging helpers:

* Plain text
* Interactive buttons (up to 3)
* List menus with sections
* URL buttons
* Images with captions
* Documents (PDF and others)
* Location requests
* Voice notes (with automatic transcription on receipt)
* Message templates
