Messages & Conversations
The Messages API lets you send a message to any contact, read back a conversation, correct or remove a message you already sent, react to one, pull a chat session, export a transcript, and mark chats read or unread, all without opening the inbox.
All paths on this page are relative to the base URL https://api.dmchamp.com/v1. Every request needs your API key (see Authentication); errors use the shared format in Errors & Pagination. The API Reference has every field, parameter and response for the endpoints below. Agencies add sub_account_id to a call to act on one of their client accounts.
How delivery works: sending does not wait for the message to arrive. The API accepts it, returns a message ID at once, and delivers it in the background on the contact’s channel (WhatsApp, SMS, Instagram and so on). To know whether it was delivered or read, listen for status updates with Webhooks instead of polling.
How conversations work
- A conversation belongs to a contact. Every message hangs off one contact, on that contact’s channel. You never pick a transport: WhatsApp contacts get WhatsApp, SMS contacts get SMS.
- Chat sessions cut a long history into readable conversations. A session opens on the first incoming message when none is open, and closes automatically 48 hours after the contact’s last incoming message (each new incoming message pushes the close out another 48 hours). The AI concluding a chat does not close the session; it only fires the Chat Concluded webhook.
- Notes are lines in a conversation that are never sent: context for your team and the AI.
- Changing a sent message (edit, delete, react) reaches the contact’s copy only on some channels. See Edit, delete and react to messages.
Endpoints
| Task | Method and path | Reference |
|---|---|---|
| Send by contact ID | POST /contacts/{contactId}/send-message |
Open in API Reference |
| Send by phone number or other identity | POST /contacts/send |
Open in API Reference |
| Send to a WhatsApp Web number directly | POST /whatsapp-web/send |
Open in API Reference |
| Log a note | POST /contacts/notes |
Open in API Reference |
| Get an AI reply draft | POST /contacts/{contactId}/draft-reply |
Open in API Reference |
| List a contact’s messages | GET /contacts/{contactId}/messages |
Open in API Reference |
| Download a message’s attachment | POST /chat-exports/media/download-url |
Open in API Reference |
| Recent sessions across all contacts | GET /chat-sessions/recent |
Open in API Reference |
| All sessions for one contact | GET /chat-sessions/{contactId} |
Open in API Reference |
| Read one session’s thread | GET /contacts/{contactId}/chat-sessions/{sessionId}/messages |
Open in API Reference |
| Edit a sent message | POST /contacts/{contactId}/messages/{messageId}/edit |
Open in API Reference |
| Delete one message | DELETE /contacts/{contactId}/messages/{messageId} |
Open in API Reference |
| Delete several messages | POST /contacts/{contactId}/messages/bulk-delete |
Open in API Reference |
| React with an emoji | POST /contacts/{contactId}/messages/{messageId}/react |
Open in API Reference |
| Rate or star a message | PATCH /contacts/{contactId}/messages/{messageId} |
Open in API Reference |
| Mark specific messages read | POST /contacts/{contactId}/messages/mark-read |
Open in API Reference |
| Mark the whole chat read | POST /contacts/{contactId}/mark-read |
Open in API Reference |
| Mark the whole chat unread | POST /contacts/{contactId}/mark-unread |
Open in API Reference |
| Export one contact’s chat | GET /chat-exports/{contactId} |
Open in API Reference |
| Export every recent conversation | GET /chat-exports/recent |
Open in API Reference |
| Email a transcript to the contact | POST /chat-exports/{contactId}/email |
Open in API Reference |
| Pause or resume the AI for a contact | PUT /contacts/{contactId} |
Open in API Reference |
| Flag contacts private (also pauses the AI) | POST /contacts/bulk-flag |
Open in API Reference |
| Create a contact before messaging | POST /contacts |
Open in API Reference |
| List conversations | GET /contacts |
Open in API Reference |
Send a message
There are two ways to send. Pick whichever fits how you identify the contact:
- By contact ID, when you already have it (you created the contact through the API, or got it from a webhook):
POST /contacts/{contactId}/send-message. - By contact identity, when you know the phone number, Instagram ID and so on but not the ID:
POST /contacts/send.
Both queue the message the same way and only find contacts that already exist. Neither creates one: an ID or identity nothing matches is a 404. To message someone for the first time, create the contact first with POST /contacts, or, on WhatsApp Web, use Send to a WhatsApp Web number directly, which creates the contact in the same call.
Send by contact ID
curl -X POST "https://api.dmchamp.com/v1/contacts/contact123/send-message?apiKey=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "body": "Hi! Your appointment is confirmed for tomorrow at 10:00." }'
{ "success": true, "messageId": "aB3dE5fG7hI9jK1lM2nO", "contactId": "contact123", "channel": "whatsapp", "message": "Message created successfully. Delivery is being processed." }
Good to know:
- Long bodies are split for you.
bodycan be up to 65,536 characters. A body longer than the channel allows in one message (1,500 on the WhatsApp Business API and SMS, 1,000 on Instagram, 2,000 on Messenger, 4,096 on Telegram and LinkedIn, 5,000 on LINE, 6,000 on TikTok, 7,000 on Viber, 65,536 on WhatsApp Web; no limit on email, the chat widget and custom channels) goes out as several messages in order, split at paragraph or sentence breaks. The response then carriesmessageIdsfor every part andautoSplit: true. mediaUrlattaches a file (image, audio, video, document).mediaContentTypeis worked out from the file extension when you leave it out (.mp3isaudio/mpeg,.pdfisapplication/pdf); set it for a URL without an extension.sendAsVoiceNote: true(audio only, WhatsApp only) delivers audio as a voice note, the play bubble. On WhatsApp Web audio that is not OGG/Opus is converted at send time; on the WhatsApp Business API only OGG/Opus arrives as a voice note and other formats arrive as an audio file. Other channels ignore it (Messenger plays audio as an audio clip, Telegram sends it as a file).human_reply: truemarks the message as written by a person on your team, not an integration. The AI then treats it as a teammate’s reply, and a reply the AI had queued for the contact’s last message is cancelled so the contact does not get two answers. It does not pause the AI; usepauseBotfor that (see Pause or resume the AI).clearIncompleteReply: truediscards a half-finished bot reply so it does not resume after your message.- LinkedIn: a message you send this way, or from the inbox, is delivered even while a person is handling the thread on the LinkedIn side. The AI’s own replies and follow ups are held back on such a thread; a held reply is removed from the chat rather than shown as failed, because nothing was sent and no credit is used. The AI’s last reply before it hands a thread to a person is still delivered.
- A contact on do-not-disturb or private, or on a channel that cannot receive outbound messages, is a
422.
Send by contact identity
POST /contacts/send takes the body plus either a contact_id, or a channel with the identity field for that channel. It answers 201 with message_id, contact_id and channel.
curl -X POST "https://api.dmchamp.com/v1/contacts/send?apiKey=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "channel": "whatsapp", "phone_number": "+31612345678", "body": "Hi! Your appointment is confirmed." }'
Which channels can be found by identity. Only six of the 14 sendable channels: whatsapp, whatsapp_web and sms by phone_number, instagram by instagram_id, messenger by messenger_id, and telegram by telegram_user_id. The other eight (instagram_private, chat-widget, custom, email, line, imessage, linkedin, viber) have no public identity to look up, so they need contact_id; sending channel alone is a 400 saying so. The same body splitting and 422 rules apply as above.
Sending on WhatsApp Web: variations and burst protection
Two things apply to the text when the contact is on WhatsApp Web:
- Spintax is expanded per send.
{Hi|Hello|Hey} there, quick questiongoes out as one of the three greetings, chosen for that send; the braces never reach the contact. Use it to give every contact a different opening from the same integration. Text without braces is sent as written. - Bursts of identical openers are refused. Once ten near-identical opening messages go out from one WhatsApp Web number within an hour to contacts who never wrote to you, further ones are not delivered. The send is still accepted (you get a
messageId), then the message is left withstatus: "failed"anderror_code: "opener_burst", with a customer readable reason. Retrying the same text does not help: vary the text, wait an hour, and send again. Replies inside existing conversations are never affected. Why: Identical openers get numbers restricted.
Send to a WhatsApp Web number directly
POST /whatsapp-web/send sends to a phone number on WhatsApp Web without looking a contact up first. A number that is not a contact yet becomes one in the same call, with the AI switched on, the same as any new contact. If the conversation should stay hand-written, switch the AI off for that contact after the send. An existing contact is reused as it is.
curl -X POST "https://api.dmchamp.com/v1/whatsapp-web/send?apiKey=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "phoneNumber": "+31612345678", "message": "Hi Alex, your quote is ready." }'
{ "success": true, "queued": true, "contactId": "abc123" }
Good to know:
202means accepted, not delivered. Read the message’s status back with List a contact’s messages using the returnedcontactId.- Send
message,mediaUrl(a public file URL), or both.mediaContentTypeis worked out from the URL when left off, andsendAsVoiceNote: truesends audio as a voice note. fromPhoneNumberpicks which of your connected WhatsApp Web numbers sends; it defaults to the number the contact already belongs to.- Active hours apply. Outside them the send is held and goes out in the next allowed slot.
campaignIdtakes the active hours from that Agent instead of the account default (it must be an Agent on the same account);ignoreActiveHours: truesends straight away. - A second call for the same contact while one held send is still waiting is a
409, so a queue never stacks up behind one person. - Errors:
400 INVALID_PHONE_FORMAT(not international format,phoneNumbermissing, or bothmessageandmediaUrlmissing),400 CONTACT_DND,400 CONTACT_PRIVATE,404 CAMPAIGN_NOT_FOUND(no Agent matchescampaignId),403 CAMPAIGN_FORBIDDEN(that Agent belongs to another account), and402when the account has no credits left or no WhatsApp Web number is connected. On top of these, like every route, it answers403 key_scope_deniedor403 key_read_onlywhen a scoped key does not cover it (see Key scopes).
Log a note into a conversation
POST /contacts/notes adds a line to a contact’s conversation without sending it: a summary of a call your voice agent just made, a remark from your CRM, a note from a colleague. It works on every channel.
curl -X POST "https://api.dmchamp.com/v1/contacts/notes?apiKey=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"channel": "whatsapp",
"phone_number": "+31612345678",
"author": "Voice agent",
"body": "Voice call, 3:12. Asked about knee surgery waiting times, prefers a call back on Tuesday morning.",
"external_id": "call_8f2k1"
}'
What happens to a note:
- It shows in the inbox as a yellow Note card, with the
authorif you sent one, and appears in List a contact’s messages withtype: "note". - The AI reads it as part of the history, marked as an internal note, so its next reply takes it into account.
- It is never sent, costs no message credits and triggers nothing: no AI reply, automation, webhook, notification or unread badge. It does not pause the AI and does not count as a reply from your team.
- Find the contact as in Send by contact identity (
contact_id, orchannelplus identifier). It only goes to an existing contact; no match is a404. timestamp(epoch milliseconds, default now) places the note in the thread; use the call’s end time. More than 5 minutes in the future is a400.external_idmakes retries safe: the sameexternal_idfor the same contact does not add a second note, and the response carriesduplicate: true(status200instead of201).
Generate a reply draft with the AI
POST /contacts/{contactId}/draft-reply asks the agent that handles a conversation to write the next reply and gives you the text. Nothing is sent. It is the same draft the Generate Reply button writes: the agent uses its setup, its knowledge base and the conversation, and answers in the contact’s language. Use it to put a person or your own app between the AI and the contact, then send the approved text with Send by contact ID.
curl -X POST "https://api.dmchamp.com/v1/contacts/contact123/draft-reply?apiKey=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "instruction": "Offer Tuesday at 3pm for the consultation" }'
{ "success": true, "contact_id": "contact123", "draft": "Hi Sara, Tuesday at 3pm works for the consultation. Shall I put you down for it?" }
- The body is optional.
instructionis a one time direction, the same as long-pressing Generate Reply.purpose: "faq_answer"writes a short standalone answer to the contact’s question for a knowledge base FAQ instead of a chat reply. - The draft comes from the agent assigned to the contact, or, with none assigned, the agent that would answer its next message.
- While drafting the agent can look things up (its custom functions and read only lookups) so the draft is accurate. Actions such as a booking or a contact field update are not done while drafting: they come back as
pending_actionswith adraft_id, and they run only when you send the draft with Send Message and passgenerated_draft_id. The contact sees nothing until you send. - A draft costs the same credits as one AI reply from that agent, and nothing when your own AI key is connected and the agent is on the Pro tier. Max and Mini drafts are always billed in credits.
400: the conversation has no messages yet, credits ran out, or there is no agent to draft from (errorsays which).404: the contact does not exist, or a team member’s key cannot see it. The key needs permission to edit messages.- Over MCP, the same action is the
generate_reply_drafttool.
Read a conversation
List a contact’s messages
GET /contacts/{contactId}/messages returns messages newest first, with a next_cursor that returns older ones.
curl "https://api.dmchamp.com/v1/contacts/contact123/messages?limit=50&direction=inbound&apiKey=YOUR_API_KEY"
- Filtered pages can be short.
filter(text,media,tool_use) anddirectionare applied to each page after it is read, so a page can hold fewer thanlimititems. Keep paging untilnext_cursorisnull. - Deleted messages stay in the list with
is_deleted: trueand an emptybodyandmedia_url.
Message fields
The full schema is in the API Reference. The fields with behaviour worth knowing:
body: for a message with an attachment it starts with a bracketed note of what arrived, then any caption, for example[THE CONTACT UPLOADED AN IMAGE] Here is my CVor[THE CONTACT UPLOADED A VOICE NOTE] - [TRANSCRIPTION: ...]. Voice notes and videos include the transcription.type:nullfor plain text,tool_usefor the assistant’s tool activity,notefor a logged note.media_urlstops working 7 days after the message arrived, on every channel. Get a fresh link with Download a message’s attachment.bot_replyistruefor AI generated messages.score(1,-1,0) andis_importantare your own ratings and stars.reactionsis always an array (empty when none), from either side;from_meistruefor yours.faq_ids_usedlists the knowledge base FAQs the AI used for that reply. The same list is on every part of a reply sent in several parts. It is empty for inbound messages, messages sent by people, automatic follow ups, replies that did not draw on a specific FAQ and AI replies sent before 25 September 2026.faqs_usedadds each FAQ’squestion,nullwhen the FAQ has since been deleted.
Download a message’s attachment
POST /chat-exports/media/download-url gives a fresh download link for a message’s file (image, voice note, video, document), valid for 1 hour and fetchable without an API key. Use it to file attachments elsewhere, or when a media_url on a message or a New Message webhook no longer opens. Find messages with attachments by listing with filter=media.
curl -X POST "https://api.dmchamp.com/v1/chat-exports/media/download-url?apiKey=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "messagePath": "contacts/contact123/messages/aB3dE5fG7hI9jK1lM2nO" }'
{ "success": true, "data": { "url": "https://storage.example.com/...", "expiresInMs": 3600000 } }
- Call it again for a new link once it expires.
400also covers a message with no attachment that can be fetched this way: some older attachments are stored at the channel provider and cannot be re-issued, and a shared Instagram reel or post is a link to Instagram, not a file.403: the contact is not on your account.404: no such message on that contact.- Over MCP, the same action is the
get_chat_media_download_urltool.
List chat sessions
GET /chat-sessions/recent?hours=24 returns the sessions that started in the last X hours across every contact, newest first. GET /chat-sessions/{contactId} returns every session for one contact (no hours). Both take status (ChatSessionOpened or ChatSessionClosed), limit (up to 100) and includeMessages=true, which adds the messages to every session but makes the response much larger.
curl "https://api.dmchamp.com/v1/chat-sessions/recent?hours=24&status=ChatSessionClosed&apiKey=YOUR_API_KEY"
The session ID field name differs. The recent list calls it
session_id(and adds the contact’s details, since sessions come from many contacts); the per-contact list calls itid. Either is the{sessionId}you pass below.
Fetch a chat-session thread
GET /contacts/{contactId}/chat-sessions/{sessionId}/messages returns one session’s full thread, oldest first, with the session’s status, start and end times and a readable tag. Messages use the same fields as the list above.
Edit, delete and react to messages
These change a message after it was sent. What reaches the contact depends entirely on the channel:
| Action | Channels that change the contact’s copy | Time limit |
|---|---|---|
| Edit a sent message | Chat widget, WhatsApp Web (text messages only), Telegram, LinkedIn | None on the chat widget, 15 minutes on WhatsApp Web, 48 hours on Telegram, 60 minutes on LinkedIn |
| Delete for everyone | Chat widget, WhatsApp Web, Telegram, LinkedIn | 60 minutes on LinkedIn; the others have no published limit |
| React with an emoji | WhatsApp Web, Telegram, LinkedIn | None |
On every other channel (the WhatsApp Business API, SMS, Instagram, Messenger, email, LINE, custom channels) a delete still removes the message from your inbox but the contact keeps their copy, and editing or reacting is not possible.
Edit a message
curl -X POST "https://api.dmchamp.com/v1/contacts/contact123/messages/msg_1/edit?apiKey=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "body": "Sorry, I meant Thursday at 3pm." }'
{ "success": true, "contact_id": "contact123", "message_id": "msg_1", "edited": true, "edit_reason": "edit_dispatched" }
- The new
bodymust not be empty or longer than the channel allows in one message (the limits under Send by contact ID; 4,096 when the message has no channel). - An edit fails loudly. When the channel refuses, you get a
409and your copy stays as the contact has it, so the two sides never drift apart.edit_reasonsays why: the edit window closed, the channel is disconnected,media_not_editable(on WhatsApp Web only text messages can be edited, not the caption under a photo, video or file), or something else. - A deleted message, a channel with no edit, or a message past its channel’s window is a
400; the request never reaches the channel.
Delete one message
DELETE /contacts/{contactId}/messages/{messageId} removes your copy and, where the channel allows, pulls back the contact’s copy. It always answers 200 when the message existed, even if the contact’s copy could not be retracted, because your copy is gone. Read revoke_supported (can this channel retract at all), revoked (was the contact’s copy removed) and revoke_reason (why not, for example revoke_window_closed or already_deleted) to tell the user what happened.
Delete several messages at once
POST /contacts/{contactId}/messages/bulk-delete clears up to 500 messages (message_ids, alias messageIds) from your side only: bodies and attachments are emptied but nothing is retracted on the contact’s device. To pull a message back, delete it on its own.
React to a message
POST /contacts/{contactId}/messages/{messageId}/react puts your emoji on a message, or removes yours with "". The contact’s reactions are never touched. The emoji is one string with no spaces, at most 16 characters.
- Like an edit, it fails rather than show a reaction the contact never got.
422: it can never be delivered here (the channel has no reactions, the message has no channel side ID, or the emoji is outside the channel’s set).409: the channel was briefly unreachable; a retry may work. reactionsin the response is the full set now on the message, yours and the contact’s. On a409or422it comes back unchanged, so a client rendering from it never shows an undelivered reaction.
Rate or star a message
PATCH /contacts/{contactId}/messages/{messageId} sets score (1 thumbs up, -1 thumbs down, 0 clears) and/or is_important (a real boolean, not "true"). This is bookkeeping on your side; nothing reaches the contact. Send at least one of the two (else 400). Only what you send is written, so starring never clears a rating, and the response echoes only the fields you sent.
Mark messages as read
POST /contacts/{contactId}/messages/mark-readmarks specific messages read (message_ids, up to 500).POST /contacts/{contactId}/mark-readclears the unread badge for the whole conversation. No body.POST /contacts/{contactId}/mark-unreadputs the badge back, for example when a teammate opened a chat but is handing it back. It is an inbox only flag: it does not change when the conversation was last read, so no read receipt goes to the contact.
curl -X POST "https://api.dmchamp.com/v1/contacts/contact123/mark-read?apiKey=YOUR_API_KEY"
Export a conversation
Exports give a whole conversation as a readable transcript instead of paging through messages. Every export takes a filter of all (default), text, media or tool_use.
- One contact:
GET /chat-exports/{contactId}.format=txt(the default) returns a download link to a text transcript indata;format=jsonreturns the contact and its messages. The link is short lived: fetch the file right away and request a new export when you need it again. - Every recent conversation:
GET /chat-exports/recent?hours=24exports all contacts active in the last X hours (limitdefault 50, max 100).format=json(the default here) gives one entry per contact;format=txtreturns one text file with every conversation as a download. This pulls the full history of every matching contact, so keephoursandlimitmodest on busy accounts. - Email a transcript to the contact:
POST /chat-exports/{contactId}/email, the “email me this chat” flow from your own system. It goes to the contact’s stored email unless you passrecipient_email;viapickstransactional(a system email),email_channel(your connected email channel) orauto;noteadds a line of up to 1,000 characters above the transcript.omittedCountsays how many of the oldest messages were left out to keep the email a sensible length. A200means built and queued, not yet in their inbox.
curl "https://api.dmchamp.com/v1/chat-exports/contact123?format=json&apiKey=YOUR_API_KEY"
Pause or resume the AI for one contact
Set is_bot_active to false with PUT /contacts/{contactId} to stop the AI replying to one contact, and back to true to hand the conversation back. This is the takeover switch for when a person steps in; messages you send with the API still deliver while the AI is paused.
curl -X PUT "https://api.dmchamp.com/v1/contacts/contact123?apiKey=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "is_bot_active": false }'
Pausing as part of the reply. A person taking over can pause the AI in the same send instead of a second call: pauseBot: true on POST /contacts/{contactId}/send-message pauses the AI as the message goes out (the response then carries "botPaused": true), forcePauseBot: true pauses it even when the agent keeps the AI answering after a teammate replies (pauseBot: false keeps it on), clearIncompleteReply: true drops a half-finished bot reply, and human_reply: true marks it as a teammate’s reply and cancels a queued AI reply.
curl -X POST "https://api.dmchamp.com/v1/contacts/contact123/send-message?apiKey=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "body": "Hi, Sarah here, taking over from the assistant.", "pauseBot": true, "clearIncompleteReply": true, "human_reply": true }'
Flagging a contact as private with POST /contacts/bulk-flag also pauses the AI for them. See Contacts for every contact field.
Building your own inbox
Everything an inbox needs is on this page and in Contacts: list conversations with GET /contacts, read one with GET /contacts/{contactId}/messages or by session, reply with send-message, correct, delete, react and rate with the message endpoints, mark read or unread, export transcripts, and pause the AI with is_bot_active. For live updates, subscribe to the New Message, Replies, Human Alerted and Chat Concluded events with Webhooks rather than polling this API on a timer.
Errors on message endpoints
Message endpoints use the standard error envelope ({ "success": false, "error": "..." }).
400: a missing field or invalid parameter (limit,hours,filter,direction,status, amessage_idsarray that is empty or over 500, a bad cursor, an empty or too long editbody, ascoreoutside-1/0/1, an emoji with spaces or over 16 characters), or a message that cannot be edited at all.404: the contact, chat session or one of the message IDs was not found.409: the channel would not take the change right now and nothing was written (edit_reasonon an edit; a reaction may work on retry), or a held WhatsApp Web send already waits for that contact.422: the contact cannot receive outbound messages (do-not-disturb, private, unsupported channel), or a reaction can never be delivered here (reaction_reasonsays which).
The shared codes (401, 403, 429, 500) and retry guidance are in Errors & Pagination.
Next steps
- Webhooks: get delivery status updates pushed to you instead of polling.
- Contacts: create and look up the contacts you message.
- Appointments: book and manage appointments for your contacts.