curl --request POST \
--url https://api.chatling.ai/v3/conversations/{conversation}/messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"text": "Can I get a refund?"
}
'{
"object": "turn",
"message": {
"object": "message",
"id": "<string>",
"conversation_id": "<string>",
"author": {
"type": "user",
"id": "<string>",
"name": "<string>"
},
"type": "text",
"text": "<string>",
"data": {
"sources": [
{
"type": "webpage",
"title": "<string>",
"url": "<string>"
}
]
},
"attachments": [
{
"id": "<string>",
"type": "image",
"mime": "<string>",
"filename": "<string>",
"size": 123,
"url": "<string>",
"url_expires_at": "2023-11-07T05:31:56Z"
}
],
"is_note": true,
"sent_by_website": true,
"is_hidden": true,
"rating": "positive",
"created_at": "2023-11-07T05:31:56Z"
},
"replies": [
{
"object": "message",
"id": "<string>",
"conversation_id": "<string>",
"author": {
"type": "user",
"id": "<string>",
"name": "<string>"
},
"type": "text",
"text": "<string>",
"data": {
"sources": [
{
"type": "webpage",
"title": "<string>",
"url": "<string>"
}
]
},
"attachments": [
{
"id": "<string>",
"type": "image",
"mime": "<string>",
"filename": "<string>",
"size": 123,
"url": "<string>",
"url_expires_at": "2023-11-07T05:31:56Z"
}
],
"is_note": true,
"sent_by_website": true,
"is_hidden": true,
"rating": "positive",
"created_at": "2023-11-07T05:31:56Z"
}
],
"conversation": {
"id": "<string>",
"status": "open",
"mode": "ai",
"ended_at": "2023-11-07T05:31:56Z"
},
"reply_error": {
"code": "ai_reply_failed",
"message": "<string>"
}
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The API key is invalid or has been revoked.",
"param": null,
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "permission_error",
"code": "ai_credits_exhausted",
"message": "This project has run out of AI credits, so the agent can't reply.",
"param": null,
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "not_found_error",
"code": "resource_not_found",
"message": "No conversation with this ID exists, or this API key can't access it.",
"param": null,
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "invalid_request_error",
"code": "wrong_channel",
"message": "User messages can only be sent to API conversations. This conversation is on the web channel.",
"param": null,
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "invalid_request_error",
"code": "attachment_not_found",
"message": "One or more attachments were not found in this conversation, or were already sent. Upload them again.",
"param": "attachment_ids",
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}Send a user message
Sends a message as the user of an API channel conversation and returns the agent’s replies.
AI agents reply using their own AI settings, actions, and knowledge base. Chatbots don’t run their flow through the API. Instead, a chatbot answers from its knowledge base using the model, temperature, and instructions in ai, which is required for chatbots and not allowed for AI agents. These settings apply to that reply only and aren’t saved, so pass them with every message. A chatbot replies with one text message with its sources.
To send files to an AI agent, upload each file with Upload an attachment, then pass the IDs in attachment_ids. text is then optional. In ai mode, the AI agent sees the images, and each image is charged like an image sent in the chat widget. Chatbots don’t accept attachments.
All checks run before the message is saved, so a failed request saves nothing. Then the message is saved, resolved and closed conversations reopen, and in ai mode the agent replies. In live and pending_handoff modes, the message is saved for the team and replies is empty.
If the agent fails to reply after the message is saved, the response is still 201, with reply_error set. Retrying with the same Idempotency-Key returns this response without saving the message again.
With stream: true, the response is a text/event-stream, sent as soon as the user message is saved. Errors before that, such as conversation_ended, are regular JSON responses. A chatbot’s reply arrives in one reply.delta. If the client disconnects, the reply is still saved and charged, and retrying with the same Idempotency-Key returns the finished turn as JSON.
curl --request POST \
--url https://api.chatling.ai/v3/conversations/{conversation}/messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"text": "Can I get a refund?"
}
'{
"object": "turn",
"message": {
"object": "message",
"id": "<string>",
"conversation_id": "<string>",
"author": {
"type": "user",
"id": "<string>",
"name": "<string>"
},
"type": "text",
"text": "<string>",
"data": {
"sources": [
{
"type": "webpage",
"title": "<string>",
"url": "<string>"
}
]
},
"attachments": [
{
"id": "<string>",
"type": "image",
"mime": "<string>",
"filename": "<string>",
"size": 123,
"url": "<string>",
"url_expires_at": "2023-11-07T05:31:56Z"
}
],
"is_note": true,
"sent_by_website": true,
"is_hidden": true,
"rating": "positive",
"created_at": "2023-11-07T05:31:56Z"
},
"replies": [
{
"object": "message",
"id": "<string>",
"conversation_id": "<string>",
"author": {
"type": "user",
"id": "<string>",
"name": "<string>"
},
"type": "text",
"text": "<string>",
"data": {
"sources": [
{
"type": "webpage",
"title": "<string>",
"url": "<string>"
}
]
},
"attachments": [
{
"id": "<string>",
"type": "image",
"mime": "<string>",
"filename": "<string>",
"size": 123,
"url": "<string>",
"url_expires_at": "2023-11-07T05:31:56Z"
}
],
"is_note": true,
"sent_by_website": true,
"is_hidden": true,
"rating": "positive",
"created_at": "2023-11-07T05:31:56Z"
}
],
"conversation": {
"id": "<string>",
"status": "open",
"mode": "ai",
"ended_at": "2023-11-07T05:31:56Z"
},
"reply_error": {
"code": "ai_reply_failed",
"message": "<string>"
}
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The API key is invalid or has been revoked.",
"param": null,
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "permission_error",
"code": "ai_credits_exhausted",
"message": "This project has run out of AI credits, so the agent can't reply.",
"param": null,
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "not_found_error",
"code": "resource_not_found",
"message": "No conversation with this ID exists, or this API key can't access it.",
"param": null,
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "invalid_request_error",
"code": "wrong_channel",
"message": "User messages can only be sent to API conversations. This conversation is on the web channel.",
"param": null,
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "invalid_request_error",
"code": "attachment_not_found",
"message": "One or more attachments were not found in this conversation, or were already sent. Upload them again.",
"param": "attachment_ids",
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}Headers
Body
- Option 1
- Option 2
IDs of unsent files from Upload an attachment to send with the message, in the order they appear. In ai mode, the AI agent may accept fewer than 3 images. AI agents only.
1 - 3 elementsResponse
The saved user message and the agent's replies, as a turn object, or as a stream of events with stream: true.