Send Message
API สำหรับส่งข้อความเข้าห้อง HumanSoft Notify ครั้งละ 1–10 ข้อความ ข้อความจะแสดงในห้องในนามบอท HumanSoft Notify และสมาชิกในห้องจะได้รับแจ้งเตือนในแอป ระบุห้องด้วย chat_token ที่ได้จาก List Chatroom
Endpoint
POST /api/v1/open-apis/hms-notify/send-messageสิทธิ์ที่ต้องการ: API Key ต้องมีสิทธิ์ การส่งข้อความ HumanSoft Notify (notify:send)
Request Body
ส่งเป็น JSON body (application/json) — ห้ามใส่ chat_token ใน URL (query string) เพราะ URL อาจถูกบันทึกใน log ระหว่างทาง ระบบจะปฏิเสธคำขอที่มี chat_token ใน URL
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
chat_token | string | Yes | token ของห้องจาก List Chatroom — ส่งตามที่ได้รับ ไม่ต้องเข้ารหัส Base64 | "20251127C4E8A2F6B1D3957E0A6C" |
messages | string[] | Yes | ข้อความที่ต้องการส่ง 1–10 ข้อความ แต่ละข้อความยาวไม่เกิน 1,000 ตัวอักษร ข้อความจะขึ้นในห้องตามลำดับใน array | ["ข้อความที่ 1", "ข้อความที่ 2"] |
Request Body Example
{
"chat_token": "20251127C4E8A2F6B1D3957E0A6C",
"messages": [
"พรุ่งนี้ปิดระบบลงเวลา 22:00 ถึง 23:00 น.",
"ขออภัยในความไม่สะดวก"
]
}Response Format
Success Response (HTTP 200)
{
"code": 200,
"message": "Success",
"payload": {
"status": "sent"
}
}Response Fields
| Field | Type | Description |
|---|---|---|
status | string | sent เมื่อระบบ HumanSoft Notify รับข้อความทั้งหมดแล้ว — ข้อความจะขึ้นในห้องตามมาหลังจากนั้น |
Error Response - Validation Failed (HTTP 400)
ข้อมูลไม่ครบหรือไม่ถูกต้อง — ยังไม่มีข้อความใดถูกส่ง errors จะรวมข้อผิดพลาดของ chat_token และของข้อความแต่ละรายการมาในคำตอบเดียวกัน ยกเว้นเมื่อ messages ไม่ใช่ array หรือมีเกิน 10 รายการ ซึ่งจะแจ้งเฉพาะข้อนั้นโดยยังไม่ตรวจข้อความรายตัว
{
"code": 400,
"message": "Validation failed",
"errors": [
"'chat_token' is required",
"'messages[1]' must not exceed 1000 characters"
]
}Error Response - Invalid chat_token (HTTP 400)
ระบบไม่รู้จัก chat_token ที่ส่งมา — ยังไม่มีข้อความใดถูกส่ง ตรวจว่าคัดลอก chat_token จาก List Chatroom มาครบทุกตัวอักษร และห้องยังอยู่ในรายการ
{
"code": 400,
"message": "Invalid chat_token. Use a chat_token from list_chatroom"
}Error Response - Could Not Connect (HTTP 400)
เชื่อมต่อระบบ HumanSoft Notify ไม่ได้ — ยังไม่มีข้อความใดถูกส่ง
{
"code": 400,
"message": "Could not connect to HumanSoft Notify. Nothing was sent. Please try again"
}Error Response - Connection Lost (HTTP 400)
การเชื่อมต่อหลุดระหว่างส่ง — ข้อความบางส่วนหรือทั้งหมดอาจขึ้นในห้องแล้ว
{
"code": 400,
"message": "Connection lost while sending. Some or all messages may have been delivered. Check the chat room before resending"
}Error Response - Send Failed (HTTP 400)
ระบบ HumanSoft Notify ตอบกลับว่าส่งไม่สำเร็จ ตัวเลขในวงเล็บคือรหัสสถานะที่ระบบ HumanSoft Notify ตอบกลับมา ไม่ใช่ HTTP status ของ Response นี้ (ซึ่งเป็น 400 เสมอ)
เมื่อส่งข้อความเดียว:
{
"code": 400,
"message": "Failed to send message (HTTP 500)"
}เมื่อส่งหลายข้อความ — ระบบรับข้อความทีละข้อความตามลำดับ ข้อความต้น ๆ อาจขึ้นในห้องแล้ว:
{
"code": 400,
"message": "Failed to send messages (HTTP 500). Earlier messages may have been delivered. Check the chat room before resending"
}| HTTP Status | Description |
|---|---|
400 | ข้อมูลไม่ถูกต้อง, chat_token ไม่ถูกต้อง หรือส่งข้อความไม่สำเร็จ (ดูข้อความใน message) |
401 | API Key ไม่ถูกต้อง หรือไม่ได้ส่ง API Key |
403 | API Key ไม่มีสิทธิ์ notify:send |
404 | เรียกด้วย method อื่นที่ไม่ใช่ POST |
500 | เกิดข้อผิดพลาดที่เซิร์ฟเวอร์ (message: Internal Server Error) — ติดต่อ HumanSoft |
Validation Rules
| Parameter | Validation | Error Message |
|---|---|---|
chat_token | ต้องระบุใน JSON body และเป็นข้อความ (string) | 'chat_token' is required |
chat_token | ห้ามส่งใน URL (query string) | 'chat_token' must be sent in the JSON body, not in the URL |
chat_token | มีได้เฉพาะตัวอักษรภาษาอังกฤษและตัวเลข ไม่เกิน 64 ตัวอักษร (ระบบไม่ตัดช่องว่างให้) | 'chat_token' is not in the correct format. Use a chat_token from list_chatroom |
messages | ต้องเป็น array ของข้อความ และมีอย่างน้อย 1 รายการ | 'messages' is required and must be an array of text |
messages | ไม่เกิน 10 รายการ | 'messages' must not contain more than 10 items |
messages[n] | ต้องเป็นข้อความ (string) และไม่เป็นค่าว่างหรือมีแต่ช่องว่าง — n คือลำดับใน array เริ่มที่ 0 | 'messages[n]' is required and must be text |
messages[n] | ยาวไม่เกิน 1,000 ตัวอักษร | 'messages[n]' must not exceed 1000 characters |
- ความยาวของข้อความนับตามจำนวนตัวอักษร (Unicode code point) ไม่ใช่ขนาด byte — สระและวรรณยุกต์ภาษาไทยนับแยกเป็น 1 ตัวอักษร
- ข้อความจะถูกส่งตามที่ได้รับ ระบบไม่ตัดช่องว่าง ไม่ตัดการขึ้นบรรทัดใหม่ และไม่แปลงอักขระ เช่น
%หรือ& - หาก body ไม่ใช่ JSON ที่ถูกต้อง ระบบจะถือว่าไม่ได้ส่งข้อมูลมา และตอบ
'chat_token' is requiredกับ'messages' is required and must be an array of text
Retry Guidance
ข้อความที่ส่งแล้วยกเลิกไม่ได้ และระบบไม่ส่งซ้ำให้อัตโนมัติ ก่อนส่งซ้ำให้ดูจากข้อความ error:
| Error message | ข้อความถูกส่งแล้วหรือยัง | วิธีจัดการ |
|---|---|---|
Validation failed | ยังไม่ส่ง | แก้ไขข้อมูลตาม errors แล้วส่งใหม่ |
Invalid chat_token... | ยังไม่ส่ง | ตรวจ chat_token กับรายการจาก List Chatroom แล้วส่งใหม่ |
Could not connect to HumanSoft Notify... | ยังไม่ส่ง | ส่งซ้ำได้ทันที |
Connection lost while sending... | อาจส่งแล้วบางส่วนหรือทั้งหมด | ตรวจในห้องว่าข้อความไหนขึ้นแล้ว แล้วส่งเฉพาะข้อความที่ยังไม่ขึ้น มิฉะนั้นสมาชิกอาจได้รับข้อความซ้ำ |
Failed to send message (HTTP ...) | ไม่ทราบแน่ชัด | ตรวจในห้องว่าข้อความขึ้นแล้วหรือยังก่อนส่งซ้ำ หากยังไม่สำเร็จให้ติดต่อ HumanSoft |
Failed to send messages (HTTP ...)... | ข้อความต้น ๆ อาจส่งแล้ว | ตรวจในห้องว่าข้อความไหนขึ้นแล้ว แล้วส่งเฉพาะข้อความที่ยังไม่ขึ้น |
ระบบรอผลการส่งได้นานสูงสุดประมาณ 30 วินาที ควรตั้ง timeout ฝั่งผู้เรียกให้นานกว่านี้ — หากผู้เรียกตัดการเชื่อมต่อไปก่อน จะไม่ทราบว่าข้อความถูกส่งแล้วหรือยัง
Code Examples
cURL
curl -X POST "https://openapi.humansoft.co.th/api/v1/open-apis/hms-notify/send-message" \
-H "Ocp-Apim-Subscription-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"chat_token": "20251127C4E8A2F6B1D3957E0A6C",
"messages": [
"พรุ่งนี้ปิดระบบลงเวลา 22:00 ถึง 23:00 น.",
"ขออภัยในความไม่สะดวก"
]
}'Notes
chat_token เป็นข้อมูลลับของห้อง: ผู้ที่มี chat_token ส่งข้อความเข้าห้องนั้นได้ — เรียก API นี้จากฝั่ง server เท่านั้น ห้ามใส่ token ในโค้ดฝั่ง browser หรือแอป
- ข้อความแสดงในนามบอท HumanSoft Notify ไม่ใช่ชื่อระบบของคุณ — หากต้องการให้ผู้รับรู้ที่มา ให้ระบุไว้ในเนื้อข้อความ
- แต่ละข้อความใน
messagesขึ้นเป็นข้อความแยกกันในห้อง และสมาชิกได้รับแจ้งเตือนแยกทีละข้อความ — หากเป็นเรื่องเดียวกันควรรวมเป็นข้อความเดียว - ส่งได้เฉพาะข้อความตัวอักษร (text)
Related APIs
- List Chatroom - ขอ
chat_tokenของห้อง HumanSoft Notify ของบริษัท - HumanSoft Notify Overview - ภาพรวมและขั้นตอนการใช้งาน