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.

Send a message to an agent
POST /v1/conversations/messages

The Conversation object

Returned by the conversations endpoints.

Attributes
replystring
The agent's answer, ready to show the customer. It can contain Markdown such as bold text, lists and links.
externalIdstring
The conversation key to send with the customer's next message: yours if you sent one, otherwise the one Careflow created.
conversationIdstring
Careflow's ID for the conversation, as shown in the Inbox. Empty in the rare case the conversation couldn't be recorded.
toolsCalledarray<string>
Names of the tools the agent used to answer, in order. Empty or `null` when it used none.
workflowCompletedboolean
`true` when this message finished the playbook the agent was following.
The Conversation object
{
  "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

POST https://api.trycareflow.com/v1/conversations/messages

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.

Parameters
assistantIdstringrequired
The ID of the agent that should answer. It's in the address bar when you open the agent in the dashboard. The agent must be in the same workspace as the API key.
messagestringrequired
What the customer said. Leading and trailing spaces are trimmed, and it can't be empty.
externalIdstringoptional
Your own ID for this customer or conversation, such as a user or booking number. Send the same value on every message to keep talking in the same conversation. Leave it out and Careflow creates one (like `conv_3f9a...`) and returns it.
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',
})
Response
{
  "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"
}