Corteksa

Build a Messaging App

Build a Messaging App

An end-to-end walkthrough: a working WhatsApp inbox on top of Corteksa — connect a number, list conversations, send, and go live with real-time updates. Combines the Messaging feature end to end.

What you'll build

A single-page inbox where an agent picks a conversation, reads history, sends a reply, and sees delivery status update live.

Prerequisites

  • An admin account with chat read + update on the WAHA provider.
  • Base URL https://<workspace>.corteksa.com/api/v1 and a login JWT.

1. Connect a session (once)

WAHA connects by QR:

curl -X POST "$BASE/messaging/sessions/WAHA/connect" -H "Authorization: Bearer $JWT"
# → returns a QR to scan; watch session.status.updated for "connected"

Other providers connect via OAuth (/messaging/facebook/oauth/authorize, …).

2. List conversations

curl "$BASE/messaging/chats/all?limit=25" -H "Authorization: Bearer $JWT"

Render the list. Filter by session_slugs, label_slugs, object_slugs, or search as your UI needs.

3. Load a conversation

curl "$BASE/messaging/messages/$CHAT_SLUG?page=1&limit=25" -H "Authorization: Bearer $JWT"

4. Send a reply

curl -X POST "$BASE/messaging/messages/send/$CHAT_SLUG/text" \
  -H "Authorization: Bearer $JWT" -H "Content-Type: application/json" \
  -d '{ "body": "On it!", "front_id": "tmp-42" }'

Render optimistically using front_id.

5. Go live

const socket = io(`${WS_HOST}/messaging/events`, { auth: { token: jwt } });
socket.on('message', (e) => append(e.payload));            // inbound + your echo
socket.on('message-ack', (e) => setStatus(e));             // sent → delivered → read
socket.on('session.status.updated', (e) => setSession(e)); // reconnect prompts

Reconcile your optimistic bubble when the message event arrives with the same front_id.

You're done

You have a live inbox. To harden it, follow Messaging › Best Practices (async sends, pagination, permission-aware UI) and handle failures with Troubleshooting.

On this page