ShopChill Open Chat API v2

Public REST API สำหรับ Partner app ของร้านค้า: รับข้อความใหม่จากลูกค้าผ่าน webhook เท่านั้น แล้วใช้ REST API สำหรับดูห้องแชต อ่านข้อความ และตอบกลับลูกค้าที่เคยเริ่มบทสนทนาแล้ว

REST only for partnersWebhook inboundNo public Socket.IOApp token
Base URL https://open-chat-api.shopchill.co.th
Socket.IO เป็น internal channel ของ ShopChill เท่านั้น Partner ไม่ต้องเชื่อมต่อ Socket.IO โดยตรง

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

POST/v2/auth/tokenCreate app access token
NameRequiredDescription
app_keyyesPartner app key
app_secretyesPartner app secret
grant_typenoUse 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

GET/v2/rooms?shop_id={shop_id}List chat rooms of an authorized shop

คืนเฉพาะห้องของ 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

GET/v2/rooms/{room_id}/chatsList messages in a room

ตรวจสอบว่า 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

POST/v2/rooms/{room_id}/replyReply in an existing room
NameRequiredDescription
messageyes1-5000 chars
typenotext, image, file, audio. Default text
sender_namenoDisplay shop name
{
  "message": "สวัสดีครับ มีอะไรให้ช่วยไหมครับ",
  "type": "text",
  "sender_name": "Shop Chill Demo"
}

Send

POST/v2/shops/{shop_id}/customers/{user_id}/sendSend to a customer who already started a conversation

ใช้สำหรับส่งหาลูกค้าคนเดิมโดยไม่ต้องมี room_id แต่ระบบจะส่งได้เฉพาะกรณีที่มีห้องแชตอยู่แล้วเท่านั้น

ถ้าลูกค้ายังไม่เคยทักเข้ามา API จะตอบ 404 และไม่สร้าง conversation ใหม่
{
  "message": "แจ้งสถานะคำสั่งซื้อครับ",
  "type": "text",
  "sender_name": "Shop Chill Demo"
}

Error Codes

1000

Invalid parameters

1004

Room/customer not found

4001

Missing or invalid token

4003

App is not authorized for this room/shop

4000

Partner authorization check failed

5000

Internal server error