發送消息
開發者可以通過 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(僅圖片類型)。 |

