How your agent hears new messages
Your agent cannot be phoned when a message arrives. So it does the next best thing: it asks DMWire to tell it as soon as someone writes, and waits on the line.
The idea in one paragraph
Your agent calls wait_for_messages. DMWire holds that call open until a new message arrives on one of your connected accounts, then answers at once with the new messages and a cursor. The cursor is a bookmark: it marks the last message the agent has seen. The agent handles the messages, then calls wait_for_messages again with that cursor, and DMWire waits for the next one. If nothing arrives for a while, the call comes back empty with the same bookmark, and the agent simply asks again.
What your agent does, step by step
- Call
wait_for_messages(no cursor the very first time: it starts from now). - Get back
messages(maybe empty) and acursor. - For each message: decide what to do, reply with
send_messageif needed. - Call
wait_for_messagesagain, passing thecursorfrom step 2. Repeat.
You do not have to write any of this. Telling your agent "keep listening to my WhatsApp and answer questions about X" is enough; the tool description explains the loop to it.
Answer like a person texts
People do not answer a chat with one long block. They send a short message, then another: the first one answers, the next adds the detail or asks the question. Your agent can reply the same way.
DMWire sends each send_message call as exactly one message and never splits your text. So a reply in three short messages is three calls, one after the other:
{"to": {"phone": "+447700900456"}, "text": "Hi Maria, yes we do!"}
{"to": {"phone": "+447700900456"}, "text": "8 is taken, but 19:30 and 20:30 are still free."}
{"to": {"phone": "+447700900456"}, "text": "Which one should I book for you?"}A blank line inside one text stays inside that one message. Keep a reply to two or three messages: DMWire sends at most 3 messages to one person until they write back, then refuses the next with loop_guard (429). The same works on LinkedIn: a reply can be 2 or 3 messages sent within a few minutes, and only a follow-up to a person who has not answered waits 24 hours (linkedin_gap, 429). Each message also counts as one send toward the daily limit. Tell your agent once, for example "answer in two or three short messages, like a person texting", and it calls send_message once per message.
A real call
With no new messages, after the 5 second timeout:
curl "https://api.dmwire.ai/v1/messages/wait?timeout_s=5" \
-H "X-API-Key: $DMWIRE_API_KEY"{
"messages": [],
"cursor": "2026-10-17T03:52:22.191Z|"
}The same through MCP:
curl \
-X POST https://mcp.dmwire.ai/mcp \
-H "X-API-Key: $DMWIRE_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {"name": "wait_for_messages", "arguments": {"timeout_s": 5}}}'{
"result": {
"content": [
{
"type": "text",
"text": "HTTP 200\n{\"messages\":[],\"cursor\":\"2026-10-17T03:52:31.742Z|\"}"
}
],
"isError": false
},
"jsonrpc": "2.0",
"id": 4
}When messages arrive, each one comes with its id, the account it arrived on, the channel, the contact and the text or media. The contact carries its id, name and the identity its channel uses: phone, email (email only), instagram_id, messenger_id, telegram_user_id, line_user_id, viber_user_id, linkedin_url (LinkedIn) or external_id (the custom channel), plus telegram_username on Telegram. Fields the contact does not have are null, and each one is the same key send_message takes under to, so your agent can answer the sender directly.
Each message also has a chat_id: the chat it is in, a 1:1 chat or a group. It equals contact.id. Pass it to wait_for_messages, list_messages or search_messages to stay in one chat, to mark_read to mark the chat read, and give a message's own id to send_message as reply_to to quote it. See Chats, history, search and read.
Settings
| Setting | What it does |
|---|---|
cursor | The bookmark from the last call. Always pass it back, or you may miss or repeat messages. |
timeout_s | How long to wait when nothing arrives: 0 to 55 seconds, 25 by default. |
account_id | Only listen to one account. Leave it out to hear all of them. |
chat_id | Only listen to one chat, from list_chats or a message's chat_id. |
Up to 50 messages come back per call. At most 2 waits can be open at the same time per account; a third is refused with wait_concurrency (HTTP 429).
When your agent is not running
wait_for_messages only works while your agent is running. Messages that arrive while it is closed are not lost: they are stored, and an agent that kept its last cursor gets them on its next call. An agent that starts fresh, without a cursor, starts from now.
If you need something to react even when no agent is open (a ping to your own server, an automation tool), use webhooks instead. They push every message to an address you choose.
wait_for_messages or webhooks?
| wait_for_messages | Webhooks | |
|---|---|---|
| Needs a server of your own | No | Yes, a public https address |
| Works while your agent is closed | Catches up with its cursor | Yes, delivered as they happen |
| Best for | Claude, OpenClaw and other agents | Automations, your own backend |
Last checked against the live service on 2026-10-23.