วิธีส่งข้อความในช่อง API
เนื่องจาก API Channel ไม่รองรับการสร้างผู้ติดต่อโดยไม่ได้ระบุชัดเจน LivedDesk ใช้ API Channel ใน 3 ขั้นตอน:
- สร้างผู้ติดต่อ
- สร้างการสนทนาโดยใช้ข้อมูลผู้ติดต่อ
- ส่งข้อความ
สร้างผู้ติดต่อ
จุดปลายทาง API
https://livedesk-api.engagelab.com/api/v2/accounts/contacts
ตัวอย่างคำขอ
curl -X POST https://livedesk-api.engagelab.com/api/v2/accounts/contacts \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)' \
{
"inbox_id": 407,
"name": "Test", // Optional
"email": "alice@acme.inc",
"phone_number": "+123456789",
"avatar_url": "https://example.com/avatar.png",
"identifier": "1234567890",
}
curl -X POST https://livedesk-api.engagelab.com/api/v2/accounts/contacts \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)' \
{
"inbox_id": 407,
"name": "Test", // Optional
"email": "alice@acme.inc",
"phone_number": "+123456789",
"avatar_url": "https://example.com/avatar.png",
"identifier": "1234567890",
}
โค้ดนี้โชว์เป็นหน้าต่างลอย
Headers ของคำขอ
| Field | Type | Description |
|---|---|---|
| Authorization | string | ใช้ Authorization: Basic base64(API Key:API Secret) สำหรับการตรวจสอบสิทธิ์ โปรดไปที่หน้า API Key เพื่อรับ API Key และ API Secret และเชื่อมโยงด้วยอักขระโคลอนก่อนเข้ารหัส Base64. |
| Content-Type | application/json | ประเภทข้อมูล ใช้ application/json สำหรับข้อความตัวธรรมดา. |
พารามิเตอร์ Body ของคำขอ
| Field | Type | Required | Description |
|---|---|---|---|
| inbox_id | String | Yes | channel ID. ตรงกับ Channel ID ใน "Project Settings-Channels-Specific channel-Settings". |
| name | String | No | ชื่อผู้ติดต่อ. |
| String | No | ที่อยู่อีเมล. | |
| phone_number | String | No | วิธีการติดต่อ. |
| avatar_url | String | No | ลิงก์ไฟล์แนบ. |
| identifier | String | No | ตัวระบุผู้ใช้. |
ตัวอย่างการตอบกลับ
{
"payload": {
"contact": {
"additional_attributes": {},
"availability_status": "offline",
"email": null,
"id": 2219259,
"name": "Test",
"phone_number": null,
"blocked": false,
"identifier": null,
"thumbnail": "",
"custom_attributes": {},
"created_at": 1766571703,
"contact_inboxes": []
},
"contact_inbox": {
"inbox": null,
"source_id": null
}
}
}
{
"payload": {
"contact": {
"additional_attributes": {},
"availability_status": "offline",
"email": null,
"id": 2219259,
"name": "Test",
"phone_number": null,
"blocked": false,
"identifier": null,
"thumbnail": "",
"custom_attributes": {},
"created_at": 1766571703,
"contact_inboxes": []
},
"contact_inbox": {
"inbox": null,
"source_id": null
}
}
}
โค้ดนี้โชว์เป็นหน้าต่างลอย
พารามิเตอร์การตอบกลับ
| Field | Type | Required | Description |
|---|---|---|---|
| additional_attributes | Object | No | คุณลักษณะเพิ่มเติม. |
| availability_status | String | No | สถานะออนไลน์ โดยค่าเริ่มต้นเป็น offline. |
| String | No | ที่อยู่อีเมล. | |
| id | String | No | รหัสผู้ติดต่อ. |
| name | String | No | ชื่อ |
| phone_number | String | No | เบอร์โทรศัพท์. |
| blocked | String | No | ไม่ว่าถูกล็อคหรือไม่ โดยค่าเริ่มต้นเป็น false. |
| identifier | String | No | ตัวระบุผู้ใช้. |
| thumbnail | String | No | ตัวระบุผู้ใช้. |
| custom_attributes | String | No | คุณลักษณะลูกค้า. |
| created_at | String | No | timestamp การสร้าง. |
| contact_inboxes | Array | No | ตัวระบุผู้ใช้. |
| inbox | String | No | channel channel. |
| source_id | String | No | Source ID. |
สร้างการสนทนา
จุดปลายทาง API
https://livedesk-api.engagelab.com/api/v2/accounts/conversations
ตัวอย่างคำขอ
curl -X POST https://livedesk-api.engagelab.com/api/v2/accounts/conversations \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)' \
{
"inbox_id": 407, // Required
"contact_id": 2219256, // Either contact_id or source_id can be passed, but it must correctly identify the sender
"source_id": "123456789"
}
curl -X POST https://livedesk-api.engagelab.com/api/v2/accounts/conversations \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)' \
{
"inbox_id": 407, // Required
"contact_id": 2219256, // Either contact_id or source_id can be passed, but it must correctly identify the sender
"source_id": "123456789"
}
โค้ดนี้โชว์เป็นหน้าต่างลอย
Headers ของคำขอ
| Field | Type | Description |
|---|---|---|
| Authorization | string | ใช้ Authorization: Basic base64(API Key:API Secret) สำหรับการตรวจสอบสิทธิ์ โปรดไปที่หน้า API Key เพื่อรับ API Key และ API Secret และเชื่อมโยงด้วยอักขระโคลอนก่อนเข้ารหัส Base64. |
| Content-Type | application/json | ประเภทข้อมูล ใช้ application/json สำหรับข้อความตัวธรรมดา. |
พารามิเตอร์ Body ของคำขอ
| Field | Type | Required | Description |
|---|---|---|---|
| inbox_id | String | Yes | channel ID. เหมือนกับ ID ที่ใช้ในอินเทอร์เฟซการสร้างผู้ติดต่อ. |
| contact_id | String | No | รหัสผู้ติดต่อ. id จากการตอบกลับของอินเทอร์เฟซการสร้างผู้ติดต่อ |
| source_id | String | No | Source ID. |
ตัวอย่างการตอบกลับ
{
"meta": {
"sender": {
"additional_attributes": {},
"availability_status": "offline",
"email": null,
"id": 2219256,
"name": "Test",
"phone_number": null,
"blocked": false,
"identifier": null,
"thumbnail": "",
"custom_attributes": {},
"created_at": 1766571624
},
"channel": "Channel::Api",
"hmac_verified": false
},
"id": 40,
"messages": [],
"account_id": 17623000010928,
"uuid": "660ce36f-46bb-4153-948c-8a26e6dab634",
"inbox_id": 407,
"additional_attributes": {},
"agent_last_seen_at": 0,
"assignee_last_seen_at": 0,
"can_reply": true,
"contact_last_seen_at": 0,
"custom_attributes": {},
"labels": [],
"muted": false,
"snoozed_until": null,
"status": "open",
"priority": null,
"conversation_category": "chat",
"chat_mode": "private_chat",
"is_forum": false,
"created_at": 1766572062,
"updated_at": 1766572062.5803902,
"timestamp": 1766572062,
"first_reply_created_at": 0,
"unread_count": 0,
"last_non_activity_message": null,
"last_activity_at": 1766572062,
"waiting_since": 1766572062,
"sla_policy_id": null,
"ticket_id": null,
"over_limit": false,
"content_preview": {
"content": null,
"message_type": null,
"created_at": null
},
"platform": {
"channel_type": "Channel::Api",
"inbox_name": "JennyApi",
"inbox_id": 407
},
"account_info": {
"contact_name": "Test",
"contact_email": null,
"contact_phone": null,
"contact_id": 2219256,
"contact_avatar": ""
},
"assignment": {
"assignee_id": null,
"assignee_name": null,
"assignee_email": null,
"team_id": null,
"team_name": null
}
}
{
"meta": {
"sender": {
"additional_attributes": {},
"availability_status": "offline",
"email": null,
"id": 2219256,
"name": "Test",
"phone_number": null,
"blocked": false,
"identifier": null,
"thumbnail": "",
"custom_attributes": {},
"created_at": 1766571624
},
"channel": "Channel::Api",
"hmac_verified": false
},
"id": 40,
"messages": [],
"account_id": 17623000010928,
"uuid": "660ce36f-46bb-4153-948c-8a26e6dab634",
"inbox_id": 407,
"additional_attributes": {},
"agent_last_seen_at": 0,
"assignee_last_seen_at": 0,
"can_reply": true,
"contact_last_seen_at": 0,
"custom_attributes": {},
"labels": [],
"muted": false,
"snoozed_until": null,
"status": "open",
"priority": null,
"conversation_category": "chat",
"chat_mode": "private_chat",
"is_forum": false,
"created_at": 1766572062,
"updated_at": 1766572062.5803902,
"timestamp": 1766572062,
"first_reply_created_at": 0,
"unread_count": 0,
"last_non_activity_message": null,
"last_activity_at": 1766572062,
"waiting_since": 1766572062,
"sla_policy_id": null,
"ticket_id": null,
"over_limit": false,
"content_preview": {
"content": null,
"message_type": null,
"created_at": null
},
"platform": {
"channel_type": "Channel::Api",
"inbox_name": "JennyApi",
"inbox_id": 407
},
"account_info": {
"contact_name": "Test",
"contact_email": null,
"contact_phone": null,
"contact_id": 2219256,
"contact_avatar": ""
},
"assignment": {
"assignee_id": null,
"assignee_name": null,
"assignee_email": null,
"team_id": null,
"team_name": null
}
}
โค้ดนี้โชว์เป็นหน้าต่างลอย
พารามิเตอร์การตอบกลับ
| Field | Type | Required | Description |
|---|---|---|---|
| meta | Object | No | วัตถุเมตาดาต้า. |
| sender | Object | No | ข้อมูลผู้ส่ง. |
| additional_attributes | Object | No | คุณลักษณะเพิ่มเติม. |
| availability_status | String | No | สถานะความพร้อม. |
| Null | No | อีเมล. | |
| id | Number | No | รหัสผู้ติดต่อ. |
| name | String | No | ชื่อผู้ส่ง. |
| phone_number | Null | No | เบอร์โทรศัพท์. |
| blocked | Boolean | No | ไม่ว่าถูกบล็อกหรือไม่. |
| identifier | Null | No | ตัวระบุคุณลักษณะผู้ใช้. |
| thumbnail | String | No | ภาพขนาดเล็ก. |
| custom_attributes | Object | No | คุณลักษณะกำหนดเอง. |
| created_at | Number | No | timestamp การสร้างการสนทนา. |
| channel | String | No | ประเภทช่อง. |
| hmac_verified | Boolean | No | สถานะการตรวจสอบ HMAC. |
| id | Number | No | รหัสการสนทนา. |
| messages | Array | No | อาร์เรย์ข้อความ. |
| account_id | Number | No | Project ID |
| uuid | String | No | ตัวระบุที่ไม่ซ้ำกัน. |
| inbox_id | Number | No | Channel ID. |
| additional_attributes | Object | No | คุณลักษณะเพิ่มเติม. |
| agent_last_seen_at | Number | No | เวลาที่ agent ประมวลผลครั้งสุดท้าย. |
| assignee_last_seen_at | Number | No | เวลาที่ assignee ประมวลผลครั้งสุดท้าย. |
| can_reply | Boolean | No | ไม่ว่าสามารถตอบได้หรือไม่. |
| contact_last_seen_at | Number | No | เวลาที่ผู้ติดต่อเห็นครั้งสุดท้าย. |
| custom_attributes | Object | No | คุณลักษณะกำหนดเอง. |
| labels | Array | No | อาร์เรย์ป้ายกำกับ. |
| muted | Boolean | No | ไม่ว่าถูกปิดเสียงหรือไม่. |
| snoozed_until | Null | No | จนถึงเวลาที่ถูกหยุดชั่วคราว. |
| status | String | No | สถานะ. |
| priority | Null | No | ความสำคัญ. |
| conversation_category | String | No | หมวดหมู่การสนทนา. |
| chat_mode | String | No | โหมดแชท. |
| is_forum | Boolean | No | ไม่ว่าเป็นฟอรั่มหรือไม่. |
| created_at | Number | No | timestamp การสร้าง. |
| updated_at | Number | No | timestamp การอัปเดต. |
| timestamp | Number | No | timestamp. |
| first_reply_created_at | Number | No | เวลาการสร้างการตอบกลับครั้งแรก. |
| unread_count | Number | No | จำนวนไม่อ่าน. |
| last_non_activity_message | Null | No | ข้อความไม่เกี่ยวกับกิจกรรมครั้งสุดท้าย. |
| last_activity_at | Number | No | เวลากิจกรรมครั้งสุดท้าย. |
| waiting_since | Number | No | เวลาเริ่มต้นการรอ. |
| sla_policy_id | Null | No | รหัสนโยบาย SLA. |
| ticket_id | Null | No | รหัสตั๋ว. |
| over_limit | Boolean | No | ไม่ว่าจะเกินขีดจำกัดหรือไม่. |
| content_preview | Object | No | Preview เนื้อหา. |
| content_preview.content | Null | No | เนื้อหา preview. |
| content_preview.message_type | Null | No | ประเภทข้อความ. |
| content_preview.created_at | Null | No | เวลาการสร้าง. |
| platform | Object | No | ข้อมูลแพลตฟอร์ม. |
| channel_type | String | No | ประเภทช่อง. |
| inbox_name | String | No | ชื่อ inbox. |
| inbox_id | Number | No | รหัส inbox. |
| account_info | Object | No | ข้อมูลบัญชี. |
| contact_name | String | No | ชื่อผู้ติดต่อ. |
| contact_email | Null | No | อีเมลผู้ติดต่อ. |
| contact_phone | Null | No | เบอร์โทรผู้ติดต่อ. |
| contact_id | Number | No | รหัสผู้ติดต่อ. |
| contact_avatar | String | No | รูปประจำตัวผู้ติดต่อ. |
| assignment | Object | No | ข้อมูลการมอบหมาย. |
| assignee_id | Null | No | รหัสผู้รับมอบหมาย. |
| assignee_name | Null | No | ชื่อผู้รับมอบหมาย. |
| assignee_email | Null | No | อีเมลผู้รับมอบหมาย. |
| team_id | Null | No | รหัสทีม. |
| team_name | Null | No | ชื่อทีม. |
ส่งข้อความ
จุดปลายทาง API
https://livedesk-api.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages
ตัวอย่างคำขอ
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": "Customer service sends a message, is it normal?",
"private": false,
"message_type": "incoming",
"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": "Customer service sends a message, is it normal?",
"private": false,
"message_type": "incoming",
"content_attributes": {
"in_reply_to": 29
}
}'
โค้ดนี้โชว์เป็นหน้าต่างลอย
Headers ของคำขอ
| Field | Type | Description |
|---|---|---|
| Authorization | string | ใช้ Authorization: Basic base64(API Key:API Secret) สำหรับการตรวจสอบสิทธิ์ โปรดไปที่หน้า API Key เพื่อรับ API Key และ API Secret และเชื่อมโยงด้วยอักขระโคลอนก่อนเข้ารหัส Base64. |
| Content-Type | application/json | ประเภทข้อมูล ใช้ application/json สำหรับข้อความตัวธรรมดา. |
พารามิเตอร์ Body ของคำขอ
| Field | Type | Required | Description |
|---|---|---|---|
| content | String | No | channel ID. ตรงกับ Channel ID ใน "Project Settings-Channels-Specific channel-Settings". |
| private | String | No | ชื่อผู้ติดต่อ. |
| message_type | String | No | ประเภทข้อความ outgoing หรือ incoming. แทนการส่งของ客服หรือการส่งของผู้ใช้ตามลำดับ. ใช้ค่าเริ่มต้นเป็น outgoing หากไม่ส่ง. |
| %content_attributes | String | No | คุณลักษณะเนื้อหา. |
| in_reply_to | String | No | เนื้อหาการตอบกลับ. |

