Skip to main content
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.
A contact’s state persists across messages. If a contact stops mid-conversation and comes back later, they resume in the same state.

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 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.
1

Browse your commit history

Click the History icon in the header, just right of the Paige logo, to see every commit with its timestamp.
2

Inspect a commit

Click any commit to see what changed — which files were added, modified, or deleted.
3

Restore a commit

Click Restore this version to roll your working copy back to that point. A new commit is created for the restore, so you never lose history — and your live bot is unaffected until you deploy.
Commits are created automatically on every save. You don’t need to do anything to enable version history — it is always on.

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 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)
  • Carousels
  • Location requests
  • WhatsApp Flows
  • Message templates
  • Anything in your Storage, by name
Some things your bot can receive but not send: customers can send you voice notes (transcribed automatically for your bot to read) and videos, but there’s no helper to send either back.

Tagging a contact from your bot

Your bot learns things about people as it talks to them — who bought, who asked about pricing, who abandoned a booking halfway. paige.tag() lets it write that down as a tag, which you can then build a segment and a broadcast on.
Pass a phone number (or a BSUID with identifierType), and any combination of tags to add and remove. Ask the Code Agent for it in plain language — “tag them as bought once the order goes through” — and it writes this for you. Three things worth knowing:
  • It never throws. A tagging problem is logged and the call resolves as unsuccessful, so a tag that fails can’t take down the reply your customer is waiting for. That is deliberate: labelling someone is never more important than answering them.
  • It tags people who already exist. An unknown number is reported as not found, never created — your contact list doesn’t quietly grow from a typo in a tag call.
  • Tags land immediately. A contact your bot tags this second is matched by a segment built on that tag, and shows up in the Contacts list and the Conversations thread header without a refresh.
Bot code written before this used a different, blunter helper that replaced a contact’s whole tag list at once. It still works so existing bots keep running, but paige.tag() is what you want — it adds and removes individual tags instead of overwriting whatever else the contact had.

Archiving and assigning chats from your bot

Your rules for the Conversations tab can live in your bot. Four helpers handle it. Ask the Code Agent in plain language — “archive the chat once the welcome message is sent” — and it writes this for you. sendTo is the identifier your handler already sends to, a phone number or a BSUID. Paige tells them apart.
Worth knowing:
  • They never throw. Each one resolves to true if it worked or the chat was already that way, and false if nothing changed, with the reason in your logs. A chat rule can’t break a conversation.
  • Call them after the reply has gone. Each can wait up to 10 seconds if Paige is unreachable, and your customer’s reply shouldn’t wait with it.
  • Assign by email, and only once. The person has to be on the project. Assigning notifies them, so do it when the condition first becomes true rather than on every message.
  • An archived chat stays archived when the customer writes again. To bring it back on a reply, call paige.unarchive(sendTo) after your bot has answered.
  • If your code sets the handover state itself, call paige.unarchive and then paige.unassign. Paige doesn’t hear about a state your code writes, so your code does what a handover means.
  • In the Preview panel they do nothing and return true. On Paige Dev they’re real.