Messages
Last updated 2026-02-13
const sent = await client.messages.send(
{
agentId,
sessionId: "chat-1",
message: "Hello",
metadata: {
correlationId: "req-1",
channel: {
type: "custom_ui", // or "slack" | "whatsapp_cloud"
},
},
},
"idem-001"
);
if (sent.status === "pending") {
const full = await client.messages.waitForResponse(sent.messageId);
console.log(full.response);
}
const completed = await client.messages.sendAndWait(
{ agentId, sessionId: "chat-1", message: "Hello again" },
{ completion: "poll" } // or { completion: "webhook" }
);
const one = await client.messages.get(sent.messageId);Key behaviors
send(...)can return:{ status: "responded", response: "..." }when runtime replies within the sync wait window{ status: "pending" }when runtime hasn't replied yet (cold start or queueing)
waitForResponse(...)pollsGET /v1/messages/:iduntil response or timeout.
Recommended production pattern
- Always provide an idempotency key on
send(...)if you might retry. - Prefer webhooks for completion if your product can handle async delivery.