ส่งข้อความ

นักพัฒนาสามารถส่งข้อความไปยัง conversation ID ที่ระบุผ่าน API ได้

วิธีการร้องขอ

POST

URL สำหรับการร้องขอ

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   
    }
}'

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

พารามิเตอร์ส่วนหัวของคำขอ

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

พารามิเตอร์ Path

Field Type Required Description
conversation_id string Yes ID บทสนทนา

พารามิเตอร์ใน Request Body

Field Type Required Description
content String Yes เนื้อหาข้อความ
private Boolean No เป็นข้อความส่วนตัวหรือไม่ ค่าเริ่มต้นคือ false
content_attributes Object No คุณสมบัติของเนื้อหา เช่น ระบุ ID ของข้อความที่ตอบกลับผ่านฟิลด์ in_reply_to

ตัวอย่างการตอบกลับแบบข้อความ

ตัวอย่างการตอบกลับ

{ "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": ""
    }
}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

พารามิเตอร์การตอบกลับ

Field Type Description
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=รายละเอียดของรูปภาพมีดังนี้" 

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

พารามิเตอร์ Path

Field Type Required Description
conversation_id string Yes 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
        }
    ]
}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

พารามิเตอร์การตอบกลับ

Field Type Description
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 ความสูงของไฟล์ ใช้กับไฟล์ประเภทภาพเท่านั้น

ตัวอย่างคำขอข้อความเทมเพลต WhatsApp

ตัวอย่างคำขอ

curl -X POST 'https://livedesk.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages'\ -H 'Content-Type: application/json' \ -H 'Authorization: Basic base64(api_key:api_secret)'\ -d '{ "content": "ข้อความที่แสดงในหน้าต่างแชต", "message_type": "outgoing", "template_params": { "name": "order_update", "namespace": "optional_namespace", "language": "en_US", "category": "MARKETING", "processed_params": { "1": "John", "2": "shipped" }, "header_params": { "type": "text", "text_variables": { "1": "Order #456" } }, "footer_params": { "text_variables": { "1": "Acme Corp" } }, "button_params": [ { "index": 0, "sub_type": "url", "text": "track/12345" } ] } }'
              
              curl -X POST 'https://livedesk.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages'\
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)'\
-d '{
    "content": "ข้อความที่แสดงในหน้าต่างแชต",
    "message_type": "outgoing",
    "template_params": {
      "name": "order_update",
      "namespace": "optional_namespace",
      "language": "en_US",
      "category": "MARKETING",
      "processed_params": {
        "1": "John",
        "2": "shipped"
      },
      "header_params": {
        "type": "text",
        "text_variables": {
         "1": "Order #456" }
      },
      "footer_params": {
        "text_variables": { "1": "Acme Corp" }
      },
      "button_params": [
        {
          "index": 0,
          "sub_type": "url",
          "text": "track/12345"
        }
      ]
    }
  }'

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

พารามิเตอร์ Path

Field Type Required Description
conversation_id string Yes ID บทสนทนา

พารามิเตอร์ใน Request Body

Field Type Required Description
content String Yes เนื้อหาข้อความที่แสดงใน UI แชต
message_type String Yes ประเภทข้อความ เมื่อต้องการส่งข้อความเทมเพลต ค่านี้จะต้องเป็น outgoing
template_params Object Yes อ็อบเจ็กต์พารามิเตอร์ของข้อความเทมเพลต
name String Yes ชื่อเทมเพลต
namespace String No namespace ของเทมเพลต ใช้กับ WhatsApp Cloud / 360Dialog
language String Yes รหัสภาษาของเทมเพลต เช่น en_US
category String No หมวดหมู่ของเทมเพลต เช่น MARKETING
processed_params Object No ค่าตัวแปรในส่วนเนื้อหาของเทมเพลต โดย key คือ ตำแหน่งตัวแปร เช่น "1", "2" หรือชื่อของตัวแปร
header_params Object No พารามิเตอร์ของส่วนหัวเทมเพลต ดูรายละเอียดด้านล่าง
footer_params Object No พารามิเตอร์ของส่วนท้ายเทมเพลต ดูรายละเอียดด้านล่าง
button_params Array No พารามิเตอร์ของปุ่มในเทมเพลต ดูรายละเอียดด้านล่าง

คำอธิบายพารามิเตอร์ header_params

โครงสร้างของ header_params จะแตกต่างกันไปตามประเภทของส่วนหัว:

ประเภทข้อความ:

{ "type": "text", "text_variables": { "1": "Order #456" } }
              
              {
  "type": "text",
  "text_variables": { "1": "Order #456" }
}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

ประเภทรูปภาพ:

{ "type": "image", "media_url": "https://example.com/image.jpg" }
              
              {
  "type": "image",
  "media_url": "https://example.com/image.jpg"
}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

ประเภทวิดีโอ:

{ "type": "video", "media_url": "https://example.com/video.mp4" }
              
              {
  "type": "video",
  "media_url": "https://example.com/video.mp4"
}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

ประเภทเอกสาร:

{ "type": "document", "media_url": "https://example.com/invoice.pdf", "filename": "invoice.pdf" }
              
              {
  "type": "document",
  "media_url": "https://example.com/invoice.pdf",
  "filename": "invoice.pdf"
}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

ประเภทตำแหน่งที่ตั้ง:

{ "type": "location", "location": { "latitude": 37.7749, "longitude": -122.4194, "name": "Acme HQ", "address": "123 Main St, San Francisco" } }
              
              {
  "type": "location",
  "location": {
    "latitude": 37.7749,
    "longitude": -122.4194,
    "name": "Acme HQ",
    "address": "123 Main St, San Francisco"
  }
}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย
Field Type Required Description
type String Yes ประเภทของส่วนหัว รองรับ text, image, video, document, location
text_variables Object No ใช้กับประเภทข้อความ โดย key คือ ตำแหน่งตัวแปร และ value คือ เนื้อหาที่ใช้แทน
media_url String No ใช้กับประเภทสื่อ เป็น URL ของไฟล์สื่อ
filename String No ใช้กับประเภทเอกสาร เป็นชื่อไฟล์
location Object No ใช้กับประเภทตำแหน่งที่ตั้ง
latitude Float Yes ละติจูด
longitude Float Yes ลองจิจูด
name String No ชื่อสถานที่
address String No ที่อยู่ของสถานที่
{ "text_variables": { "1": "Acme Corp" } }
              
              {
  "text_variables": { "1": "Acme Corp" }
}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย
Field Type Required Description
text_variables Object No key คือ ตำแหน่งตัวแปร และ value คือ เนื้อหาที่ใช้แทน

คำอธิบายพารามิเตอร์ button_params

[ { "index": 0, "sub_type": "url", "text": "track/12345" }, { "index": 1, "sub_type": "quick_reply", "payload": "OPT_OUT" } ]
              
              [
  {
    "index": 0,
    "sub_type": "url",
    "text": "track/12345"
  },
  {
    "index": 1,
    "sub_type": "quick_reply",
    "payload": "OPT_OUT"
  }
]

            
โค้ดนี้โชว์เป็นหน้าต่างลอย
Field Type Required Description
index Int Yes ลำดับของปุ่ม โดยเริ่มนับจาก 0
sub_type String Yes ประเภทปุ่ม รองรับ url, quick_reply
text String No ใช้กับปุ่มประเภท URL เป็นส่วนต่อท้ายของ URL หรือ path สำหรับเปลี่ยนเส้นทาง
payload String No ใช้กับปุ่มประเภท quick_reply เป็นค่า payload ที่จะส่งกลับ

ตัวอย่างการตอบกลับ

การตอบกลับเมื่อสำเร็จ

{ "id": 123, "content": "ข้อความที่แสดงในหน้าต่างแชต", "message_type": 1, "status": "sent", "additional_attributes": { "template_params": { "name": "order_update", "language": "en_US", "category": "MARKETING" } } }
              
              {
  "id": 123,
  "content": "ข้อความที่แสดงในหน้าต่างแชต",
  "message_type": 1,
  "status": "sent",
  "additional_attributes": {
    "template_params": {
      "name": "order_update",
      "language": "en_US",
      "category": "MARKETING"
    }
  }
}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

การตอบกลับเมื่อล้มเหลว

{ "id": 123, "status": "failed", "content_attributes": { "external_error": "131047: Re-engagement message is not allowed" } }
              
              {
  "id": 123,
  "status": "failed",
  "content_attributes": {
    "external_error": "131047: Re-engagement message is not allowed"
  }
}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

พารามิเตอร์การตอบกลับ

Field Type Description
id Int ID ข้อความ
content String เนื้อหาข้อความ
message_type Int ประเภทข้อความ
status String สถานะข้อความ เช่น sent, delivered, failed เป็นต้น
additional_attributes Object คุณสมบัติเพิ่มเติม
template_params Object ข้อมูลพารามิเตอร์เทมเพลตที่ได้ส่งไปแล้ว
content_attributes Object คุณสมบัติของเนื้อหา หากการส่งล้มเหลวจะมีข้อมูลข้อผิดพลาดอยู่ภายใน
external_error String ข้อมูลข้อผิดพลาดจากภายนอก ซึ่งจะส่งกลับมาเมื่อส่งข้อความล้มเหลว

ส่งข้อความที่ล้มเหลวใหม่อีกครั้ง

หากสถานะของข้อความเป็น failed คุณสามารถรีเซ็ตสถานะของข้อความและส่งใหม่ได้ผ่าน API ต่อไปนี้:

URL สำหรับการร้องขอ

POST https://livedesk-api.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages/:message_id/retry

พารามิเตอร์ Path

Field Type Required Description
conversation_id string Yes ID บทสนทนา
message_id string Yes ID ข้อความ
Icon Solid Transparent White Qiyu
ติดต่อฝ่ายขาย