วิธีส่งข้อความไปยัง API Channel
เนื่องจาก API Channel ไม่รองรับการสร้าง Contact โดยอัตโนมัติ การส่งข้อความผ่าน LiveDesk API Channel จึงประกอบด้วย 3 ขั้นตอนดังต่อไปนี้:
- สร้าง Contact
- สร้าง Conversation โดยใช้ข้อมูล Contact
- ส่งข้อความ
สร้าง Contact
URL คำขอ
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"
}
โค้ดนี้โชว์เป็นหน้าต่างลอย
ส่วนหัวคำขอ
| Field | Type | Description |
|---|---|---|
| Authorization | string | ยืนยันตัวตนด้วย Authorization: Basic base64(API Key:API Secret) ไปที่หน้า API Keys เพื่อรับ API Key และ API Secret จากนั้นเชื่อมค่าทั้งสองด้วยเครื่องหมายโคลอน (:) และเข้ารหัสด้วย Base64 |
| Content-Type | application/json | ประเภทข้อมูล ใช้ application/json สำหรับข้อความตัวอักษรทั่วไป |
พารามิเตอร์เนื้อหาคำขอ
| Field | Type | Required | Description |
|---|---|---|---|
| inbox_id | String | Yes | ID ของ Channel ซึ่งตรงกับ Channel ID ใน Project Settings > Channels > Specific Channel > Settings |
| name | String | No | ชื่อ Contact |
| String | No | ที่อยู่อีเมล | |
| phone_number | String | No | หมายเลขโทรศัพท์ของ Contact |
| 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
}
}
}
โค้ดนี้โชว์เป็นหน้าต่างลอย
พารามิเตอร์การตอบกลับ
| Field | Type | Required | Description |
|---|---|---|---|
| additional_attributes | Object | No | แอตทริบิวต์เพิ่มเติม |
| availability_status | String | No | สถานะออนไลน์ ค่าเริ่มต้นคือ offline |
| String | No | ที่อยู่อีเมล | |
| id | String | No | ID ของ Contact |
| name | String | No | ชื่อ |
| phone_number | String | No | หมายเลขโทรศัพท์ |
| blocked | String | No | ระบุว่า Contact ถูกบล็อกหรือไม่ ค่าเริ่มต้นคือ false |
| identifier | String | No | ตัวระบุผู้ใช้ |
| thumbnail | String | No | URL ของภาพขนาดย่อ |
| custom_attributes | String | No | แอตทริบิวต์แบบกำหนดเอง |
| created_at | String | No | เวลาที่สร้างในรูปแบบ Timestamp |
| contact_inboxes | Array | No | Inbox ของ Contact |
| inbox | String | No | Inbox ของ Channel |
| source_id | String | No | ID ของ Source |
สร้าง Conversation
URL คำขอ
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"
}
โค้ดนี้โชว์เป็นหน้าต่างลอย
พารามิเตอร์ส่วนหัวคำขอ
| Field | Type | Description |
|---|---|---|
| Authorization | string | ยืนยันตัวตนด้วย Authorization: Basic base64(API Key:API Secret) ไปที่หน้า API Keys เพื่อรับ API Key และ API Secret จากนั้นเชื่อมค่าทั้งสองด้วยเครื่องหมายโคลอน (:) และเข้ารหัสด้วย Base64 |
| Content-Type | application/json | ประเภทข้อมูล ใช้ application/json สำหรับข้อความตัวอักษรทั่วไป |
พารามิเตอร์เนื้อหาคำขอ
| Field | Type | Required | Description |
|---|---|---|---|
| inbox_id | String | Yes | ID ของ Channel ซึ่งเป็น ID เดียวกับที่ใช้ใน API สร้าง Contact |
| contact_id | String | No | ID ของ Contact ซึ่งเป็นค่า id ที่ส่งกลับมาในผลลัพธ์จาก API สร้าง Contact |
| source_id | String | No | ID ของ Source |
ตัวอย่างการตอบกลับ
{
"meta": {
"sender": {
"additional_attributes": {},
"availability_status": "offline",
"email": null,
"id": 2219256,
"name": "wjTest",
"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": "wjTest",
"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": "wjTest",
"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": "wjTest",
"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 | ID ของ Contact |
| name | String | No | ชื่อผู้ส่ง |
| phone_number | Null | No | หมายเลขโทรศัพท์ |
| blocked | Boolean | No | ระบุว่า Contact ถูกบล็อกหรือไม่ |
| identifier | Null | No | ตัวระบุผู้ใช้ |
| thumbnail | String | No | ภาพขนาดย่อ |
| custom_attributes | Object | No | แอตทริบิวต์แบบกำหนดเอง |
| created_at | Number | No | เวลาที่สร้าง Conversation ในรูปแบบ Timestamp |
| channel | String | No | ประเภท Channel |
| hmac_verified | Boolean | No | สถานะการตรวจสอบ HMAC |
| id | Number | No | ID ของ Conversation |
| messages | Array | No | อาร์เรย์ข้อความ |
| account_id | Number | No | ID ของ Project |
| uuid | String | No | ตัวระบุที่ไม่ซ้ำกัน |
| inbox_id | Number | No | ID ของ Channel |
| additional_attributes | Object | No | แอตทริบิวต์เพิ่มเติม |
| agent_last_seen_at | Number | No | เวลาที่ Agent ดูหรือจัดการ Conversation ครั้งล่าสุด |
| assignee_last_seen_at | Number | No | เวลาที่ผู้รับผิดชอบดูหรือจัดการ Conversation ครั้งล่าสุด |
| can_reply | Boolean | No | ระบุว่าสามารถส่งการตอบกลับได้หรือไม่ |
| contact_last_seen_at | Number | No | เวลาที่ Contact ถูกพบล่าสุด |
| custom_attributes | Object | No | แอตทริบิวต์แบบกำหนดเอง |
| labels | Array | No | อาร์เรย์ของ Label |
| muted | Boolean | No | ระบุว่า Conversation ถูกปิดเสียงหรือไม่ |
| snoozed_until | Null | No | เวลาที่ Conversation จะสิ้นสุดการพักการแจ้งเตือน |
| status | String | No | สถานะ |
| priority | Null | No | ลำดับความสำคัญ |
| conversation_category | String | No | หมวดหมู่ของ Conversation |
| 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 | ID ของนโยบาย SLA |
| ticket_id | Null | No | ID ของ Ticket |
| 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 | ประเภท Channel |
| inbox_name | String | No | ชื่อ Inbox |
| inbox_id | Number | No | ID ของ Inbox |
| account_info | Object | No | ข้อมูล Account |
| contact_name | String | No | ชื่อ Contact |
| contact_email | Null | No | อีเมลของ Contact |
| contact_phone | Null | No | หมายเลขโทรศัพท์ของ Contact |
| contact_id | Number | No | ID ของ Contact |
| contact_avatar | String | No | อวาตาร์ของ Contact |
| 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 | ชื่อทีม |
ส่งข้อความ
URL คำขอ
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
}
}'
โค้ดนี้โชว์เป็นหน้าต่างลอย
ส่วนหัวคำขอ
| Field | Type | Description |
|---|---|---|
| Authorization | string | ยืนยันตัวตนด้วย Authorization: Basic base64(API Key:API Secret) ไปที่หน้า API Keys เพื่อรับ API Key และ API Secret จากนั้นเชื่อมค่าทั้งสองด้วยเครื่องหมายโคลอน (:) และเข้ารหัสด้วย Base64 |
| Content-Type | application/json | ประเภทข้อมูล ใช้ application/json สำหรับข้อความตัวอักษรทั่วไป |
พารามิเตอร์เนื้อหาคำขอ
| Field | Type | Required | Description |
|---|---|---|---|
| content | String | Yes | เนื้อหาข้อความ |
| private | Boolean | No | ระบุว่าเป็นข้อความส่วนตัวหรือไม่ ค่าเริ่มต้นคือ false |
| message_type | String | No | ประเภทข้อความ: outgoing หรือ incoming โดยหมายถึงข้อความที่ส่งโดยเจ้าหน้าที่บริการลูกค้าและผู้ใช้ตามลำดับ หากไม่ระบุ ค่าเริ่มต้นคือ outgoing |
| content_attributes | String | No | แอตทริบิวต์ของเนื้อหา |
| in_reply_to | String | No | เนื้อหาที่ต้องการตอบกลับ |










