วิธีส่งข้อความไปยัง API Channel
เนื่องจาก API Channel ไม่รองรับการสร้างผู้ติดต่อโดยอัตโนมัติ Livedesk จึงแบ่งการใช้งาน API Channel ออกเป็น 3 ขั้นตอน:
- สร้างผู้ติดต่อ
- สร้างบทสนทนาจากข้อมูลผู้ติดต่อ
- ส่งข้อความ
สร้างผู้ติดต่อ
API Endpoint
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", // ไม่บังคับ
"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", // ไม่บังคับ
"email": "alice@acme.inc",
"phone_number": "+123456789",
"avatar_url": "https://example.com/avatar.png",
"identifier": "1234567890"
}
โค้ดนี้โชว์เป็นหน้าต่างลอย
Request Headers
| Field | Type | Description |
|---|---|---|
| Authorization | string | ใช้ Authorization: Basic base64(API Key:API Secret) สำหรับการยืนยันตัวตน โปรดไปที่หน้าคีย์ API เพื่อรับ API Key และ API Secret จากนั้นเชื่อมต่อทั้งสองค่าด้วยเครื่องหมายโคลอน (:) ก่อนเข้ารหัสด้วย Base64 |
| Content-Type | application/json | ประเภทข้อมูล โดยใช้ application/json สำหรับข้อความทั่วไป |
Request Body Parameters
| Field | Type | Required | Description |
|---|---|---|---|
| inbox_id | String | Yes | ID ของช่องทาง ซึ่งตรงกับ Channel ID ใน Project Settings > Channels > Specific channel > Settings |
| name | String | No | ชื่อผู้ติดต่อ |
| String | No | ที่อยู่อีเมล | |
| phone_number | String | No | หมายเลขโทรศัพท์ |
| avatar_url | String | No | URL ของรูปโปรไฟล์ |
| 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
}
}
}
โค้ดนี้โชว์เป็นหน้าต่างลอย
Response Parameters
| Field | Type | Required | Description |
|---|---|---|---|
| additional_attributes | Object | No | คุณสมบัติเพิ่มเติม |
| availability_status | String | No | สถานะออนไลน์ ค่าเริ่มต้นคือ offline |
| String | No | ที่อยู่อีเมล | |
| id | String | No | ID ผู้ติดต่อ |
| 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 | เวลาที่สร้าง |
| contact_inboxes | Array | No | รายการกล่องข้อความของผู้ติดต่อ |
| inbox | String | No | ช่องทาง |
| source_id | String | No | Source ID |
สร้างบทสนทนา
API Endpoint
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, // จำเป็น
"contact_id": 2219256, // สามารถส่ง contact_id หรือ source_id อย่างใดอย่างหนึ่งได้ แต่ต้องระบุผู้ส่งให้ถูกต้อง
"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, // จำเป็น
"contact_id": 2219256, // สามารถส่ง contact_id หรือ source_id อย่างใดอย่างหนึ่งได้ แต่ต้องระบุผู้ส่งให้ถูกต้อง
"source_id": "123456789"
}
โค้ดนี้โชว์เป็นหน้าต่างลอย
Request Headers
| Field | Type | Description |
|---|---|---|
| Authorization | string | ใช้ Authorization: Basic base64(API Key:API Secret) สำหรับการยืนยันตัวตน โปรดไปที่หน้าคีย์ API เพื่อรับ API Key และ API Secret จากนั้นเชื่อมต่อทั้งสองค่าด้วยเครื่องหมายโคลอน (:) ก่อนเข้ารหัสด้วย Base64 |
| Content-Type | application/json | ประเภทข้อมูล โดยใช้ application/json สำหรับข้อความทั่วไป |
Request Body Parameters
| Field | Type | Required | Description |
|---|---|---|---|
| inbox_id | String | Yes | ID ของช่องทาง ซึ่งเป็นค่าเดียวกับ ID ที่ใช้ในอินเทอร์เฟซสร้างผู้ติดต่อ |
| contact_id | String | No | ID ผู้ติดต่อ ซึ่งคือ 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
}
}
โค้ดนี้โชว์เป็นหน้าต่างลอย
Response Parameters
| Field | Type | Required | Description |
|---|---|---|---|
| meta | Object | No | ออบเจ็กต์ข้อมูลเมตา |
| sender | Object | No | ข้อมูลผู้ส่ง |
| additional_attributes | Object | No | คุณสมบัติเพิ่มเติม |
| availability_status | String | No | สถานะความพร้อมใช้งาน |
| Null | No | อีเมล | |
| id | Number | No | ID ผู้ติดต่อ |
| name | String | No | ชื่อผู้ส่ง |
| phone_number | Null | No | หมายเลขโทรศัพท์ |
| blocked | Boolean | No | ถูกบล็อกหรือไม่ |
| identifier | Null | No | ตัวระบุแอตทริบิวต์ของผู้ใช้ |
| thumbnail | String | No | ภาพขนาดย่อ |
| custom_attributes | Object | No | คุณสมบัติที่กำหนดเอง |
| created_at | Number | No | เวลาที่สร้างบทสนทนา |
| channel | String | No | ประเภทช่องทาง |
| hmac_verified | Boolean | No | สถานะการตรวจสอบ HMAC |
| id | Number | No | ID บทสนทนา |
| messages | Array | No | อาร์เรย์ข้อความ |
| account_id | Number | No | ID โปรเจกต์ |
| uuid | String | No | ตัวระบุที่ไม่ซ้ำกัน |
| inbox_id | Number | No | ID ช่องทาง |
| additional_attributes | Object | No | คุณสมบัติเพิ่มเติม |
| agent_last_seen_at | Number | No | เวลาที่เอเจนต์ดูล่าสุด |
| assignee_last_seen_at | Number | No | เวลาที่ผู้รับมอบหมายดูล่าสุด |
| 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 | เวลาที่สร้าง |
| updated_at | Number | No | เวลาที่อัปเดต |
| timestamp | Number | No | การประทับเวลา |
| 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 | ID นโยบาย SLA |
| ticket_id | Null | No | ID ทิกเก็ต |
| over_limit | Boolean | No | เกินขีดจำกัดหรือไม่ |
| content_preview | Object | No | ตัวอย่างเนื้อหา |
| content_preview.content | Null | No | เนื้อหาตัวอย่าง |
| content_preview.message_type | Null | No | ประเภทข้อความ |
| content_preview.created_at | Null | No | เวลาที่สร้าง |
| platform | Object | No | ข้อมูลแพลตฟอร์ม |
| channel_type | String | No | ประเภทช่องทาง |
| inbox_name | String | No | ชื่อกล่องข้อความ |
| inbox_id | Number | No | ID กล่องข้อความ |
| account_info | Object | No | ข้อมูลบัญชี |
| contact_name | String | No | ชื่อผู้ติดต่อ |
| contact_email | Null | No | อีเมลผู้ติดต่อ |
| contact_phone | Null | No | หมายเลขโทรศัพท์ของผู้ติดต่อ |
| contact_id | Number | No | ID ผู้ติดต่อ |
| contact_avatar | String | No | รูปโปรไฟล์ผู้ติดต่อ |
| assignment | Object | No | ข้อมูลการมอบหมาย |
| assignee_id | Null | No | ID ผู้รับมอบหมาย |
| assignee_name | Null | No | ชื่อผู้รับมอบหมาย |
| assignee_email | Null | No | อีเมลผู้รับมอบหมาย |
| team_id | Null | No | ID ทีม |
| team_name | Null | No | ชื่อทีม |
ส่งข้อความ
API Endpoint
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": "ฝ่ายบริการลูกค้าส่งข้อความ แบบนี้ปกติไหม?",
"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": "ฝ่ายบริการลูกค้าส่งข้อความ แบบนี้ปกติไหม?",
"private": false,
"message_type": "incoming",
"content_attributes": {
"in_reply_to": 29
}
}'
โค้ดนี้โชว์เป็นหน้าต่างลอย
Request Headers
| Field | Type | Description |
|---|---|---|
| Authorization | string | ใช้ Authorization: Basic base64(API Key:API Secret) สำหรับการยืนยันตัวตน โปรดไปที่หน้าคีย์ API เพื่อรับ API Key และ API Secret จากนั้นเชื่อมต่อทั้งสองค่าด้วยเครื่องหมายโคลอน (:) ก่อนเข้ารหัสด้วย Base64 |
| Content-Type | application/json | ประเภทข้อมูล โดยใช้ application/json สำหรับข้อความทั่วไป |
Request Body Parameters
| Field | Type | Required | Description |
|---|---|---|---|
| content | String | No | เนื้อหาข้อความ |
| private | String | No | กำหนดว่าเป็นข้อความภายในหรือไม่ |
| message_type | String | No | ประเภทข้อความ: outgoing หรือ incoming โดยใช้แทนข้อความที่ส่งจากฝ่ายบริการลูกค้าหรือผู้ใช้ตามลำดับ ค่าเริ่มต้นคือ outgoing หากไม่ได้ระบุ |
| content_attributes | String | No | คุณสมบัติของเนื้อหา |
| in_reply_to | String | No | ID ของข้อความที่ต้องการตอบกลับ |










