发送消息
开发者可以通过 API 向指定会话发送消息。
请求方式
POST
调用地址
https://livedesk-api.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages
调用验证
详情参见 API 概述的鉴权方式说明。
普通文字请求
请求示例
curl -X POST 'https://livedesk-api.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages' \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)' \
-d '{
"content": "客服发送消息,正常吗",
"private": false,
"content_attributes": {
"in_reply_to": 29
}
}'
curl -X POST 'https://livedesk-api.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages' \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)' \
-d '{
"content": "客服发送消息,正常吗",
"private": false,
"content_attributes": {
"in_reply_to": 29
}
}'
โค้ดนี้โชว์เป็นหน้าต่างลอย
请求头
| 字段 | 类型 | 描述 |
|---|---|---|
| Authorization | string | 使用 Authorization: Basic base64(API Key:API Secret) 进行身份验证。请前往 API 密钥页面 获取 API Key 和 API Secret,并将两者以冒号连接后进行 Base64 编码。 |
| Content-Type | application/json | 数据类型,普通文字消息使用 application/json。 |
路径参数
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
| conversation_id | string | 是 | 会话ID。 |
请求体参数
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
| content | String | 是 | 消息内容。 |
| private | Boolean | 否 | 是否为私信,默认为 false。 |
| content_attributes | Object | 否 | 内容属性,如回复某条消息时使用 in_reply_to 字段指定消息ID。 |
普通文字响应示例
成功响应
{
"id": 3030,
"content": "客服发送消息,正常吗",
"inbox_id": 79,
"conversation_id": 141,
"message_type": 1,
"content_type": "text",
"status": "sent",
"content_attributes": {},
"created_at": 1762331029,
"private": false,
"source_id": null,
"sorting_id": 4,
"sender": {
"id": 3,
"name": "TEST",
"available_name": "TEST",
"avatar_url": "",
"type": "user",
"availability_status": "offline",
"thumbnail": ""
}
}
{
"id": 3030,
"content": "客服发送消息,正常吗",
"inbox_id": 79,
"conversation_id": 141,
"message_type": 1,
"content_type": "text",
"status": "sent",
"content_attributes": {},
"created_at": 1762331029,
"private": false,
"source_id": null,
"sorting_id": 4,
"sender": {
"id": 3,
"name": "TEST",
"available_name": "TEST",
"avatar_url": "",
"type": "user",
"availability_status": "offline",
"thumbnail": ""
}
}
โค้ดนี้โชว์เป็นหน้าต่างลอย
响应参数
| 字段 | 类型 | 描述 |
|---|---|---|
| id | Int | 消息ID。 |
| content | String | 消息内容。 |
| inbox_id | Int | 收件箱ID。 |
| conversation_id | Int | 会话ID。 |
| message_type | Int | 消息类型。 |
| content_type | String | 内容类型。 |
| status | String | 消息状态,如 "sent"、"delivered" 等。 |
| content_attributes | Object | 内容属性。 |
| created_at | Int | 消息创建时间戳。 |
| private | Boolean | 是否为私信。 |
| source_id | Int | 来源ID。 |
| sorting_id | Int | 排序ID。 |
| sender | Object | 发送者信息 |
| id | Int | 发送者ID。 |
| name | String | 发送者名称。 |
| available_name | String | 发送者显示名称。 |
| avatar_url | String | 发送者头像URL。 |
| type | String | 发送者类型(如 user)。 |
| availability_status | String | 发送者在线状态(如 offline)。 |
| thumbnail | String | 发送者缩略图。 |
图片/音频等文件请求
请求示例
curl -X POST "https://livedesk.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages" \
-H "Authorization: Basic base64(api_key:api_secret)" \
-F "attachments[]=@attachments[]=@/path/to/your/file.jpg" \
-F "content=详细图片如下"
curl -X POST "https://livedesk.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages" \
-H "Authorization: Basic base64(api_key:api_secret)" \
-F "attachments[]=@attachments[]=@/path/to/your/file.jpg" \
-F "content=详细图片如下"
โค้ดนี้โชว์เป็นหน้าต่างลอย
路径参数
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
| conversation_id | string | 是 | 会话ID。 |
图片/音频等文件响应示例
成功响应
{
"id": 3031,
"content": "详细图片如下",
"inbox_id": 79,
"conversation_id": 141,
"message_type": 1,
"content_type": "text",
"status": "sent",
"content_attributes": {},
"created_at": 1762331762,
"private": false,
"source_id": null,
"sorting_id": 5,
"sender": {
"id": 3,
"name": "Wenjie Yu",
"available_name": "Wenjie Yu",
"avatar_url": "",
"type": "user",
"availability_status": "offline",
"thumbnail": ""
},
"attachments": [
{
"id": 199,
"message_id": 3031,
"file_type": "image",
"account_id": 14,
"extension": null,
"data_url": "https://livedesk.engagelab.com/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBamNUIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--727ba7469d64f90790d242c743f254b5c9013fe1/android-icon-48x48.png",
"thumb_url": "https://livedesk.engagelab.com/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBamNUIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--727ba7469d64f90790d242c743f254b5c9013fe1/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBTU0lJY0c1bkJqb0dSVlE2RTNKbGMybDZaVjkwYjE5bWFXeHNXd2RwQWZvdyIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--63c890cbf173eb3dc92a8786fcc3e120c329852d/android-icon-48x48.png",
"file_size": 589136,
"width": null,
"height": null
}
]
}
{
"id": 3031,
"content": "详细图片如下",
"inbox_id": 79,
"conversation_id": 141,
"message_type": 1,
"content_type": "text",
"status": "sent",
"content_attributes": {},
"created_at": 1762331762,
"private": false,
"source_id": null,
"sorting_id": 5,
"sender": {
"id": 3,
"name": "Wenjie Yu",
"available_name": "Wenjie Yu",
"avatar_url": "",
"type": "user",
"availability_status": "offline",
"thumbnail": ""
},
"attachments": [
{
"id": 199,
"message_id": 3031,
"file_type": "image",
"account_id": 14,
"extension": null,
"data_url": "https://livedesk.engagelab.com/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBamNUIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--727ba7469d64f90790d242c743f254b5c9013fe1/android-icon-48x48.png",
"thumb_url": "https://livedesk.engagelab.com/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBamNUIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--727ba7469d64f90790d242c743f254b5c9013fe1/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBTU0lJY0c1bkJqb0dSVlE2RTNKbGMybDZaVjkwYjE5bWFXeHNXd2RwQWZvdyIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--63c890cbf173eb3dc92a8786fcc3e120c329852d/android-icon-48x48.png",
"file_size": 589136,
"width": null,
"height": null
}
]
}
โค้ดนี้โชว์เป็นหน้าต่างลอย
响应参数
| 字段 | 类型 | 描述 |
|---|---|---|
| id | Int | 消息ID。 |
| content | String | 消息内容。 |
| inbox_id | Int | 收件箱ID。 |
| conversation_id | Int | 会话ID。 |
| message_type | Int | 消息类型。 |
| content_type | String | 内容类型。 |
| status | String | 消息状态,如 "sent"、"delivered" 等。 |
| content_attributes | Object | 内容属性。 |
| created_at | Int | 消息创建时间戳。 |
| private | Boolean | 是否为私信。 |
| source_id | Int | 来源ID。 |
| sorting_id | Int | 排序ID。 |
| sender | Object | 发送者信息。 |
| id | Int | 发送者ID。 |
| name | String | 发送者名称。 |
| available_name | String | 发送者显示名称。 |
| avatar_url | String | 发送者头像URL。 |
| type | String | 发送者类型(如 user)。 |
| availability_status | String | 发送者在线状态(如 offline)。 |
| thumbnail | String | 发送者缩略图。 |
| attachments | Array | 附件信息列表。 |
| id | Int | 附件ID。 |
| message_id | Int | 所属消息ID。 |
| file_type | String | 文件类型(如 image)。 |
| account_id | Int | 账户ID。 |
| extension | String | 文件扩展名。 |
| data_url | String | 文件URL。 |
| thumb_url | String | 缩略图URL(仅图片类型)。 |
| file_size | Int | 文件大小(字节)。 |
| width | Int | 文件宽度(仅图片类型)。 |
| height | Int | 文件高度(仅图片类型)。 |










