Conversations
Send a customer's message to one of your agents from your own server, and get the agent's reply in the same response. Use it to put your agent inside your app, booking system or website backend.
The Conversation object
Returned by the conversations endpoints.
{ "reply": "Early check-in from 11am is possible when your room is ready. I've noted your request for Friday.", "externalId": "guest-48213", "conversationId": "6710b3e2c4a1f09d8e7b6a52", "toolsCalled": [ "check_room_availability" ], "workflowCompleted": false }
Send a message to an agent
Requires `conversations:write`. Sends one customer message to an agent and waits for the reply. The agent answers the way it does on every other channel, with the same persona, knowledge, playbooks and tools. The conversation appears in your Inbox. Send the same `externalId` with each message from one customer so the agent remembers what was said. If you leave it out, use the `externalId` from the response on the next message. Messages with the same `externalId` stay in one conversation while they keep coming. After 30 minutes with no messages, the next one starts a new conversation, with a new `conversationId`. A reply can take several seconds when the agent looks things up or uses tools. Allow up to two minutes before your HTTP client gives up. Call this from your server, never from a browser or mobile app, because the API key would be exposed.
curl https://api.trycareflow.com/v1/conversations/messages \ -H "Authorization: Bearer sk_live_••••" \ -d assistantId=66f1c2a9e4b0f1a2b3c4d5e6 \ -d message=Can I check in before 2pm on Friday? \ -d externalId=guest-48213
const Conversation = await careflow.conversations.create({ assistantId: '66f1c2a9e4b0f1a2b3c4d5e6', message: 'Can I check in before 2pm on Friday?', externalId: 'guest-48213', })
{ "code": "SUCCESS", "message": "ok", "data": { "reply": "Early check-in from 11am is possible when your room is ready. I've noted your request for Friday.", "externalId": "guest-48213", "conversationId": "6710b3e2c4a1f09d8e7b6a52", "toolsCalled": [ "check_room_availability" ], "workflowCompleted": false } }
{ "code": "ERROR", "message": "invalid_request", "error": "assistantId and message are required" }
{ "code": "ERROR", "message": "unauthorized", "error": "invalid or revoked API key" }
{ "code": "ERROR", "message": "insufficient_scope", "error": "this API key needs the conversations:write scope" }
{ "code": "ERROR", "message": "not_found", "error": "assistant not found for this API key" }
{ "code": "ERROR", "message": "too_many_requests", "error": "You have exceeded the rate limit for api. Please try again in 12s." }
{ "code": "ERROR", "message": "upstream_error", "error": "the assistant could not process this message; retry shortly" }
{ "code": "ERROR", "message": "service_unavailable", "error": "key lookup failed" }