Moving from Baileys or whatsapp-web.js to the Cloud API swaps three parts of your code. The linked-device session becomes an access token and a registered phone number ID. Event listeners become a webhook endpoint. Free-form outbound messages become approved templates whenever the 24-hour window is closed. Most of your business logic survives, but identifiers, groups and a few library features don’t map one to one. For what each library is and what its README says about WhatsApp’s terms, read Baileys and whatsapp-web.js vs the Cloud API first.
The mapping at a glance
| Concept | Baileys | whatsapp-web.js | Cloud API |
|---|---|---|---|
| Session | useMultiFileAuthState → state, saveCreds on creds.update |
LocalAuth, RemoteAuth or NoAuth |
Access token plus phone number ID |
| Linking | qr on connection.update, or requestPairingCode |
qr event, regenerated every 30 seconds |
Verify the number in WhatsApp Manager, then POST /<PHONE_NUMBER_ID>/register |
| Send text | sock.sendMessage(jid, { text }) |
client.sendMessage(chatId, 'text') or msg.reply() |
POST /<PHONE_NUMBER_ID>/messages with type: "text" |
| Incoming | messages.upsert with type === 'notify' |
message, message_create |
messages webhook, entry[].changes[].value.messages[] |
| Receipts | messages.update, readMessages([key]) |
message_ack, sendSeen |
Status webhooks: sent, delivered, read |
| User ID | @s.whatsapp.net, @lid |
@c.us, getContactLidAndPhone |
wa_id and from; BSUID in user_id and from_user_id |
| Outside 24 hours | Free-form | Free-form | Templates only (131047) |
| Groups | groupCreate, groupParticipantsUpdate |
createGroup, group events |
Groups API: OBA, 8 participants, invite link |
| Status | Post to status@broadcast |
isStatus on Message |
No documented equivalent |
| Broadcast lists | Send to an existing list | getBroadcasts() |
No equivalent |
Library sources: the Baileys README, baileys.wiki, the whatsapp-web.js Client docs (version 1.34.7) and the wwebjs guide, all accessed 2026-11-04.
Session and QR code become a token and a registered number
In Baileys you persist state from useMultiFileAuthState and save it on every creds.update. Since 7.x the store must also hold the lid-mapping, device-list and tctoken keys (Baileys v7 migration, accessed 2026-11-04). In whatsapp-web.js you choose an auth strategy and keep its folder or remote store alive.
The Cloud API has no session to restore. Each request carries a Bearer token, and the URL carries the phone number ID. Use a system user token for anything that runs unattended, as described in Cloud API access tokens.
Linking becomes registration. You verify the number in WhatsApp Manager, then register it with a 6-digit PIN. If two-step verification is already set, use that PIN (Meta registration, accessed 2026-11-04). This is Meta’s call with shell variables:
curl "https://graph.facebook.com/v26.0/$PHONE_NUMBER_ID/register" \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d '{ "messaging_product": "whatsapp", "pin": "212834" }'
Meta caps this endpoint at 10 requests per number in a 72-hour moving window, and returns error 133016 past that. Don’t put the call in a retry loop. Phone number registration and the two-step PIN covers the errors.
The number your library uses today
A number that runs a library session is in use on a WhatsApp app. To move it to the Cloud API alone, Meta says “you must first delete your WhatsApp account” (Meta migrate an existing number, accessed 2026-11-04). The existing message history is lost. After deletion, the number may take up to 3 minutes to become available.
Coexistence keeps the number in the WhatsApp Business app as well. It needs Business app version 2.24.17 or higher and runs through a Solution Partner or Tech Provider (Meta coexistence onboarding, accessed 2026-11-04). Up to 6 months of 1:1 chats sync, and group chats don’t. Throughput is fixed at 20 messages per second, and the app’s broadcast lists are disabled. Meta’s page doesn’t name consumer WhatsApp numbers as eligible. Details are in Business app coexistence with the Cloud API.
sendMessage becomes a POST to /messages
sock.sendMessage(jid, { text: 'hello' }) and client.sendMessage(chatId, 'hello') both become one HTTP request. This is Meta’s text sample with shell variables in place of the token and ID (Meta text messages, accessed 2026-11-04):
curl "https://graph.facebook.com/v26.0/$PHONE_NUMBER_ID/messages" \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d '{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "+16505551234",
"type": "text",
"text": {
"preview_url": true,
"body": "As requested, here'\''s the link to our latest product: https://www.meta.com/quest/quest-3/"
}
}'
The to field takes a phone number, not a JID, so strip @s.whatsapp.net or @c.us and send E.164 digits. The response returns messages[0].id, a wamid that means Meta accepted the message. Delivery arrives later. In whatsapp-web.js, sendMessage resolves to a Message object you can act on. On the Cloud API you store the wamid and wait for webhooks. Code for this step is in Send a WhatsApp message with Python.
msg.reply() has no single counterpart. You send to the from value of the incoming message, and quoting the original is a separate context field covered in reply context and reactions.
Event listeners become a webhook
Baileys pushes events through sock.ev.on('messages.upsert', ...), and whatsapp-web.js through client.on('message', ...). On the Cloud API, Meta posts JSON to your HTTPS endpoint. Incoming messages sit in entry[].changes[].value.messages[] with field: "messages". This is Meta’s text webhook sample (Meta text webhook, accessed 2026-11-04):
{
"object": "whatsapp_business_account",
"entry": [
{
"id": "102290129340398",
"changes": [
{
"value": {
"messaging_product": "whatsapp",
"metadata": {
"display_phone_number": "15550783881",
"phone_number_id": "106540352242922"
},
"contacts": [
{ "profile": { "name": "Sheena Nelson" }, "wa_id": "16505551234" }
],
"messages": [
{
"from": "16505551234",
"id": "wamid.HBgLMTY1MDM4Nzk0MzkVAgASGBQzQTRBNjU5OUFFRTAzODEwMTQ0RgA=",
"timestamp": "1749416383",
"type": "text",
"text": { "body": "Does it come in another color?" }
}
]
},
"field": "messages"
}
]
}
]
}
metadata.phone_number_id tells you which of your numbers received it, which replaces keeping one socket per number. The ready and connection.update handlers have no counterpart, because there is no connection to watch. Build the receiver from the Node.js and Express webhook guide.
Receipts move to the same endpoint. messages.update and message_ack become status webhooks for sent, delivered and read, matched by wamid. readMessages and sendSeen become a mark-as-read request, covered in mark as read and typing indicator.
JIDs and @lid become wa_id and BSUIDs
Baileys 7.x uses @lid by default, “an opaque per-user identifier WhatsApp assigns to anonymize phone numbers,” next to the phone-based @s.whatsapp.net (Baileys JIDs, accessed 2026-11-04). It resolves LID to phone “only if Baileys has previously seen the mapping.”
The Cloud API sends wa_id and from. Meta warns that “a WhatsApp user’s ID and phone number may not always match.” Webhooks also carry a business-scoped user ID in contacts[].user_id and messages[].from_user_id, in a format such as US.13491208655302741918. The phone number is left out unless you interacted with the user in the last 30 days or they’re in your contact book.
An @lid and a BSUID are both opaque, but they come from different systems. Neither the Baileys docs nor Meta’s pages cited here map one to the other, so don’t write a conversion. Store the phone number where you have it, add a BSUID column, and match old records on phone. Usernames and business-scoped user IDs and @lid vs JID cover both formats.
Free-form outbound becomes templates
A library session sends free-form text at any hour. The Cloud API opens a 24-hour customer service window when the user messages or calls you. “When the window closes, you can only send pre-approved template messages” (Meta send messages, accessed 2026-11-04). A free-form send outside it fails with 131047. Audit every place your code starts a conversation, such as reminders and follow-ups, and give each one a template. Error 131047 shows the fix. Marketing templates are also moving to their own endpoint, explained in the Marketing Messages API guide.
Groups, Status and broadcast lists
Groups exist on the Cloud API with tighter rules. The business must be an Official Business Account, and a group holds up to 8 participants (Meta Groups API, accessed 2026-11-04). People join through an invite link you send. Meta documents removing participants but not adding them, so groupParticipantsUpdate(jid, [...], 'add') has no confirmed equivalent. Groups aren’t available on Business app numbers, which rules out coexistence numbers. See the Groups API guide.
Posting to status@broadcast has no documented Cloud API counterpart. Broadcast lists have none either, and coexistence disables them in the app. Buttons and lists, deprecated in the whatsapp-web.js README, are supported on the Cloud API as interactive messages and templates.
Z-API Omni offers the QR connection and Meta’s official API in the same account, so some numbers can stay on QR while others move (View documentation).
Z-API Omni team