GuidesMessaging
Examples
Messaging — Examples
Copy-paste, working requests. BASE = https://<workspace>.corteksa.com/api/v1,
JWT = your admin login token.
Send a text message
cURL
curl -X POST "$BASE/messaging/messages/send/$CHAT_SLUG/text" \
-H "Authorization: Bearer $JWT" \
-H "Content-Type: application/json" \
-d '{ "body": "Hi 👋", "front_id": "tmp-2931" }'JavaScript (fetch)
await fetch(`${BASE}/messaging/messages/send/${chatSlug}/text`, {
method: 'POST',
headers: { Authorization: `Bearer ${jwt}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ body: 'Hi 👋', front_id: crypto.randomUUID() }),
});Node (axios)
await axios.post(`${BASE}/messaging/messages/send/${chatSlug}/text`,
{ body: 'Hi 👋' },
{ headers: { Authorization: `Bearer ${jwt}` } });Send an image (media)
Media is multipart/form-data with a files field (up to 10). type is
image | video | audio | document | file.
curl -X POST "$BASE/messaging/messages/send/$CHAT_SLUG/image" \
-H "Authorization: Bearer $JWT" \
-F "files=@/path/to/photo.jpg" \
-F "caption=Here you go"const form = new FormData();
form.append('files', fileInput.files[0]);
form.append('caption', 'Here you go');
await fetch(`${BASE}/messaging/messages/send/${chatSlug}/image`, {
method: 'POST',
headers: { Authorization: `Bearer ${jwt}` }, // no Content-Type — the browser sets the boundary
body: form,
});List a chat's messages (paginated)
curl "$BASE/messaging/messages/$CHAT_SLUG?page=1&limit=25" \
-H "Authorization: Bearer $JWT"Subscribe to real-time updates
import { io } from 'socket.io-client';
const socket = io(`${WS_HOST}/messaging/events`, {
auth: { token: jwt },
transports: ['websocket'],
});
socket.on('connected', () => console.log('live'));
socket.on('message', (e) => addMessage(e.payload)); // new inbound/outbound message
socket.on('message-ack', (e) => setStatus(e.messageSlug, e.acknowledgment));
socket.on('chat-read', (e) => markRead(e.chatSlug));
socket.on('error', (e) => console.warn('ws error', e));
// let the server know you're viewing a chat
socket.emit('seen', { sessionSlug, chatSlug });Reply to a message
Add replyTo (a message slug) to any send:
curl -X POST "$BASE/messaging/messages/send/$CHAT_SLUG/text" \
-H "Authorization: Bearer $JWT" -H "Content-Type: application/json" \
-d '{ "body": "Sure!", "replyTo": "msg-7f21c" }'