ShopChill Open Chat API v2
Public REST API สำหรับ Partner app ของร้านค้า: รับข้อความใหม่จากลูกค้าผ่าน webhook เท่านั้น แล้วใช้ REST API สำหรับดูห้องแชต อ่านข้อความ และตอบกลับลูกค้าที่เคยเริ่มบทสนทนาแล้ว
Authentication
สร้าง token ด้วย app_key และ app_secret ที่ได้จาก Partner app แล้วส่ง header แบบ Bearer ในทุก API ที่เหลือ
Authorization: Bearer your_app_access_token
Webhook
เมื่อมีข้อความใหม่จากลูกค้า ShopChill จะส่ง webhook ไปยัง URL ของ Partner app แบบ fire-and-forget
{
"event": "chat.message.created",
"data": {
"message_id": "664b2c3d4e5f6a7b8c9d0e1f",
"room_id": "664a1b2c3d4e5f6a7b8c9d0e",
"shop_id": "42",
"user_id": "customer_001",
"sender_by": "user",
"sender_id": "customer_001",
"sender_name": "Customer",
"message": "สวัสดีครับ",
"type": "text",
"created_at": "2026-05-19T00:00:00.000Z"
}
}
ใช้ room_id จาก webhook เพื่อเรียกดูข้อความย้อนหลังหรือ reply กลับในห้องนั้น
Create Token
| Name | Required | Description |
|---|---|---|
app_key | yes | Partner app key |
app_secret | yes | Partner app secret |
grant_type | no | Use client_credentials |
Request
{
"grant_type": "client_credentials",
"app_key": "app_key_xxx",
"app_secret": "app_secret_xxx"
}
Response 201
{
"status": true,
"code": "0000",
"message": "Token created successfully",
"data": {
"access_token": "...",
"token_type": "Bearer",
"expires_in": null,
"username": "partner_username",
"app_id": "partner_app_id",
"app_key": "app_key_xxx",
"scopes": ["chat.read", "chat.write"]
}
}
Rooms
คืนเฉพาะห้องของ shop_id ที่ app นี้ได้รับ authorization แล้ว
{
"status": true,
"code": "0000",
"data": [
{
"_id": "664a1b2c3d4e5f6a7b8c9d0e",
"shop_id": "42",
"user_id": "customer_001",
"shop_name": "Shop Chill Demo",
"user_name": "Customer",
"message": "สวัสดีครับ",
"shop_unread": 1,
"lasted_message_at": "2026-05-19T00:00:00.000Z"
}
]
}
Chats
ตรวจสอบว่า room เป็นของ app token ปัจจุบัน และ app ยังมีสิทธิ์กับ shop ของห้องนี้
{
"status": true,
"code": "0000",
"data": [
{
"_id": "664b2c3d4e5f6a7b8c9d0e1f",
"room_id": "664a1b2c3d4e5f6a7b8c9d0e",
"shop_id": "42",
"user_id": "customer_001",
"sender_by": "user",
"message": "สวัสดีครับ",
"type": "text",
"created_at": "2026-05-19T00:00:00.000Z"
}
]
}
Reply
| Name | Required | Description |
|---|---|---|
message | yes | 1-5000 chars |
type | no | text, image, file, audio. Default text |
sender_name | no | Display shop name |
{
"message": "สวัสดีครับ มีอะไรให้ช่วยไหมครับ",
"type": "text",
"sender_name": "Shop Chill Demo"
}
Send
ใช้สำหรับส่งหาลูกค้าคนเดิมโดยไม่ต้องมี room_id แต่ระบบจะส่งได้เฉพาะกรณีที่มีห้องแชตอยู่แล้วเท่านั้น
404 และไม่สร้าง conversation ใหม่{
"message": "แจ้งสถานะคำสั่งซื้อครับ",
"type": "text",
"sender_name": "Shop Chill Demo"
}
Error Codes
1000Invalid parameters
1004Room/customer not found
4001Missing or invalid token
4003App is not authorized for this room/shop
4000Partner authorization check failed
5000Internal server error