ส่งข้อความ

นักพัฒนาสามารถส่งข้อความไปยัง 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": "Customer service is sending a message. Is this normal?", "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": "Customer service is sending a message. Is this normal?",
    "private": false,
    "content_attributes": {
        "in_reply_to": 29
    }
}'

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

ส่วนหัวคำขอ

Field Type Description
Authorization string ยืนยันตัวตนโดยใช้ Authorization: Basic base64(API Key:API Secret) ไปที่หน้าคีย์ API เพื่อรับ API Key และ API Secret จากนั้นเชื่อมทั้งสองค่าด้วยเครื่องหมายโคลอนและเข้ารหัสเป็น Base64
Content-Type application/json ประเภทข้อมูล โดยใช้ application/json สำหรับข้อความธรรมดา

พารามิเตอร์เส้นทาง

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

พารามิเตอร์เนื้อหาคำขอ

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

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

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

{ "id": 3030, "content": "Customer service is sending a message. Is this normal?", "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": "Customer service is sending a message. Is this normal?",
    "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 ข้อมูลผู้ส่ง
sender.id Int ID ผู้ส่ง
sender.name String ชื่อผู้ส่ง
sender.available_name String ชื่อที่แสดงของผู้ส่ง
sender.avatar_url String URL รูปโปรไฟล์ของผู้ส่ง
sender.type String ประเภทผู้ส่ง เช่น user
sender.availability_status String สถานะของผู้ส่ง เช่น offline
sender.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[]=@/path/to/your/file.jpg" \ -F "content=Detailed image below"
              
              curl -X POST "https://livedesk.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages" \
  -H "Authorization: Basic base64(api_key:api_secret)" \
  -F "attachments[]=@/path/to/your/file.jpg" \
  -F "content=Detailed image below"

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

พารามิเตอร์เส้นทาง

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

ตัวอย่างการตอบกลับรูปภาพ เสียง และไฟล์ประเภทอื่น

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

{ "id": 3031, "content": "Detailed image below", "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": "Detailed image below",
    "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 ข้อมูลผู้ส่ง
sender.id Int ID ผู้ส่ง
sender.name String ชื่อผู้ส่ง
sender.available_name String ชื่อที่แสดงของผู้ส่ง
sender.avatar_url String URL รูปโปรไฟล์ของผู้ส่ง
sender.type String ประเภทผู้ส่ง เช่น user
sender.availability_status String สถานะของผู้ส่ง เช่น offline
sender.thumbnail String รูปภาพขนาดย่อของผู้ส่ง
attachments Array รายการข้อมูลไฟล์แนบ
attachments.id Int ID ไฟล์แนบ
attachments.message_id Int ID ของข้อความที่เกี่ยวข้อง
attachments.file_type String ประเภทไฟล์ เช่น image
attachments.account_id Int ID บัญชี
attachments.extension String นามสกุลไฟล์
attachments.data_url String URL ไฟล์
attachments.thumb_url String URL รูปภาพขนาดย่อ (เฉพาะไฟล์ประเภทรูปภาพ)
attachments.file_size Int ขนาดไฟล์เป็นไบต์
attachments.width Int ความกว้างของไฟล์ (เฉพาะไฟล์ประเภทรูปภาพ)
attachments.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": "Display text for chat UI", "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": "Display text for chat UI",
    "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"
        }
      ]
    }
  }'

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

พารามิเตอร์เส้นทาง

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

พารามิเตอร์เนื้อหาคำขอ

Field Type Required Description
content String Yes เนื้อหาข้อความที่แสดงในอินเทอร์เฟซแชต
message_type String Yes ประเภทข้อความ เมื่อต้องการส่งข้อความเทมเพลต ให้ตั้งค่าเป็น outgoing
template_params Object Yes ออบเจ็กต์พารามิเตอร์ของข้อความเทมเพลต
template_params.name String Yes ชื่อเทมเพลต
template_params.namespace String No เนมสเปซของเทมเพลต (ใช้โดย WhatsApp Cloud / 360Dialog)
template_params.language String Yes รหัสภาษาของเทมเพลต เช่น en_US
template_params.category String No หมวดหมู่ของเทมเพลต เช่น MARKETING
template_params.processed_params Object No ค่าตัวแปรในเนื้อหาเทมเพลต โดยคีย์คือตำแหน่งตัวแปร ("1", "2") หรือชื่อตัวแปร
template_params.header_params Object No พารามิเตอร์ขององค์ประกอบส่วนหัวของเทมเพลต ดูคำแนะนำด้านล่าง
template_params.footer_params Object No พารามิเตอร์ขององค์ประกอบส่วนท้ายของเทมเพลต ดูคำแนะนำด้านล่าง
template_params.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 ใช้สำหรับประเภทข้อความ โดยคีย์คือตำแหน่งตัวแปร และค่าคือเนื้อหาที่ใช้แทนที่
media_url String No ใช้สำหรับประเภทสื่อ โดยระบุ URL ของไฟล์สื่อ
filename String No ใช้สำหรับประเภทไฟล์ โดยระบุชื่อไฟล์
location Object No ใช้สำหรับประเภทตำแหน่ง
location.latitude Float Yes ละติจูด
location.longitude Float Yes ลองจิจูด
location.name String No ชื่อตำแหน่ง
location.address String No ที่อยู่ของตำแหน่ง

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

{ "text_variables": { "1": "Acme Corp" } }
              
              {
  "text_variables": { "1": "Acme Corp" }
}

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

คำอธิบายพารามิเตอร์ 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 หรือเส้นทางเปลี่ยนเส้นทาง
payload String No ใช้สำหรับปุ่มประเภท quick_reply โดยระบุ payload ที่จะส่งกลับ

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

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

{ "id": 123, "content": "Display text for chat UI", "message_type": 1, "status": "sent", "additional_attributes": { "template_params": { "name": "order_update", "language": "en_US", "category": "MARKETING" } } }
              
              {
  "id": 123,
  "content": "Display text for chat UI",
  "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 แอตทริบิวต์เพิ่มเติม
additional_attributes.template_params Object ข้อมูลเกี่ยวกับพารามิเตอร์เทมเพลตที่ส่ง
content_attributes Object แอตทริบิวต์ของเนื้อหา ซึ่งจะมีข้อมูลข้อผิดพลาดเมื่อการส่งล้มเหลว
content_attributes.external_error String ข้อมูลข้อผิดพลาดภายนอกที่ส่งกลับเมื่อการส่งข้อความล้มเหลว

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

หากสถานะข้อความเป็น failed ให้ใช้เอนด์พอยต์ต่อไปนี้เพื่อรีเซ็ตสถานะข้อความและส่งอีกครั้ง

URL คำขอ

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

พารามิเตอร์เส้นทาง

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