API Reference
Connect
Connect API

Connect API

Base URL: https://connect-api.pcampus.co

Connect API จัดการ unified inbox, chat widget, conversations, AI-suggested replies, และ reward delivery in-chat


Conversations

GET /v1/conversations

List conversations ทุก channel

GET https://connect-api.pcampus.co/v1/conversations?status=open&limit=20
Authorization: Bearer <pip_api_key>
x-tenant-id: your-tenant-id

Query params:

ParamTypeDescription
statusstringopen | pending | resolved
channelstringline | facebook | web | email
assignedTostringstaff user ID
limitnumberdefault 20, max 100
cursorstringpagination cursor

Response:

{
  "data": [
    {
      "conversationId": "conv_xxx",
      "channel": "line",
      "customerId": "cust_001",
      "customerName": "สมชาย จันทร์ดี",
      "lastMessage": "ยา Amlodipine หมดแล้วครับ",
      "lastMessageAt": "2026-07-15T10:00:00.000Z",
      "status": "open",
      "assignedTo": "staff-01",
      "unreadCount": 2
    }
  ],
  "nextCursor": "eyJpZCI6ImNvbnZfeXl5In0="
}

GET /v1/conversations/:conversationId

ดู conversation thread พร้อม Customer Story

GET https://connect-api.pcampus.co/v1/conversations/conv_xxx
Authorization: Bearer <pip_api_key>
x-tenant-id: your-tenant-id

Response:

{
  "conversationId": "conv_xxx",
  "channel": "line",
  "customerId": "cust_001",
  "status": "open",
  "messages": [
    {
      "messageId": "msg_001",
      "direction": "inbound",
      "body": "ยา Amlodipine หมดแล้วครับ",
      "sentAt": "2026-07-15T10:00:00.000Z"
    }
  ],
  "customerStory": {
    "segment": "loyal",
    "churnRisk": 0.12,
    "lastVisit": "2026-07-12",
    "topProduct": "Amlodipine 5mg",
    "recommendations": [
      { "type": "reorder", "message": "เสนอสั่งซ้ำ Amlodipine 5mg 30 เม็ด" }
    ]
  },
  "suggestedReply": "ได้เลยครับ คุณสมชาย Amlodipine 5mg 30 เม็ด ราคา ฿180 จัดส่งได้วันนี้ครับ ต้องการสั่งเลยไหมครับ?"
}

PATCH /v1/conversations/:conversationId

อัปเดต status หรือ assign

PATCH https://connect-api.pcampus.co/v1/conversations/conv_xxx
Authorization: Bearer <pip_api_key>
 
{
  "status": "resolved",
  "assignedTo": "staff-02"
}

Messages

POST /v1/conversations/:conversationId/messages

ส่ง reply กลับหาลูกค้าในช่องทางเดิม

POST https://connect-api.pcampus.co/v1/conversations/conv_xxx/messages
Authorization: Bearer <pip_api_key>
 
{
  "body": "ได้เลยครับ Amlodipine 5mg 30 เม็ด ราคา ฿180 จัดส่งได้วันนี้ครับ",
  "sentBy": "staff-01",
  "suggestionUsed": true
}

Response:

{
  "messageId": "msg_002",
  "conversationId": "conv_xxx",
  "channel": "line",
  "direction": "outbound",
  "body": "ได้เลยครับ...",
  "sentAt": "2026-07-15T10:02:00.000Z",
  "deliveryStatus": "sent"
}

Rewards

POST /v1/conversations/:conversationId/rewards

ส่ง coupon หรือ reward ให้ลูกค้าในช่องทางที่กำลังคุยอยู่

POST https://connect-api.pcampus.co/v1/conversations/conv_xxx/rewards
Authorization: Bearer <pip_api_key>
 
{
  "rewardType": "coupon",
  "couponCode": "WINBACK10",
  "description": "ส่วนลด 10% สำหรับคำสั่งซื้อถัดไป",
  "validDays": 7,
  "sentBy": "staff-01"
}

Response:

{
  "rewardId": "rwd_xxx",
  "conversationId": "conv_xxx",
  "customerId": "cust_001",
  "rewardType": "coupon",
  "couponCode": "WINBACK10",
  "deliveredAt": "2026-07-15T10:03:00.000Z",
  "pbcpEventId": "evt_xxx"
}

ระบบบันทึก reward.sent_via_chat event กลับไปยัง PBCP อัตโนมัติ


Q&A Corpus

GET /v1/qa

List Q&A ที่ใช้ train chatbot

GET https://connect-api.pcampus.co/v1/qa
Authorization: Bearer <pip_api_key>
x-tenant-id: your-tenant-id

POST /v1/qa

เพิ่ม Q&A ใหม่

POST https://connect-api.pcampus.co/v1/qa
Authorization: Bearer <pip_api_key>
 
{
  "question": "ยา Amlodipine กินตอนไหนครับ",
  "answer": "กินได้ทุกเวลาครับ แต่ควรกินเวลาเดิมทุกวัน เช่น หลังอาหารเช้าทุกวัน",
  "tags": ["amlodipine", "วิธีกิน"],
  "domain": "pharmacy"
}

PATCH /v1/qa/:qaId

DELETE /v1/qa/:qaId


Widget

GET /v1/widget/config

ดึง config สำหรับ render widget หน้า client

GET https://connect-api.pcampus.co/v1/widget/config
Authorization: Bearer <pip_api_key>
x-tenant-id: your-tenant-id

Response:

{
  "tenantId": "pharmacy-demo",
  "domain": "pharmacy",
  "primaryColor": "#2563eb",
  "position": "bottom-right",
  "quickActions": ["ประวัติยา", "สั่งยาซ้ำ", "ปรึกษาเภสัชกร"],
  "businessHours": { "open": "08:00", "close": "20:00", "timezone": "Asia/Bangkok" },
  "offlineMessage": "ร้านปิดแล้วครับ จะติดต่อกลับในวันทำการถัดไป"
}

Identity — External IdP Binding

POST /v1/identity/exchange

แลก External IdP token เป็น Connect session token (เรียกโดย widget SDK อัตโนมัติ)

POST https://connect-api.pcampus.co/v1/identity/exchange
x-tenant-id: your-tenant-id
 
{
  "provider": "firebase",
  "identityToken": "<firebase_id_token>"
}

Response:

{
  "sessionToken": "cses_xxx",
  "expiresAt": "2026-07-15T11:00:00.000Z",
  "customerId": "cust_001",
  "isNewCustomer": false
}

Supported providers:

providerข้อมูลที่ต้องตั้งค่าใน Console
firebaseFirebase Project ID
auth0Domain + Audience
supabaseProject URL + JWT Secret
customJWKS URI

GET /v1/identity/providers

List External IdP providers ที่ tenant ตั้งค่าไว้

GET https://connect-api.pcampus.co/v1/identity/providers
Authorization: Bearer <pip_api_key>
x-tenant-id: your-tenant-id

Platform docs → · Intelligence API →

Connect API

Base URL: https://connect-api.pcampus.co

Connect API manages the unified inbox, chat widget, conversations, AI-suggested replies, and reward delivery in-chat.


Conversations

GET /v1/conversations

List conversations across all channels.

GET https://connect-api.pcampus.co/v1/conversations?status=open&limit=20
Authorization: Bearer <pip_api_key>
x-tenant-id: your-tenant-id

Query params:

ParamTypeDescription
statusstringopen | pending | resolved
channelstringline | facebook | web | email
assignedTostringstaff user ID
limitnumberdefault 20, max 100
cursorstringpagination cursor

Response:

{
  "data": [
    {
      "conversationId": "conv_xxx",
      "channel": "line",
      "customerId": "cust_001",
      "customerName": "สมชาย จันทร์ดี",
      "lastMessage": "ยา Amlodipine หมดแล้วครับ",
      "lastMessageAt": "2026-07-15T10:00:00.000Z",
      "status": "open",
      "assignedTo": "staff-01",
      "unreadCount": 2
    }
  ],
  "nextCursor": "eyJpZCI6ImNvbnZfeXl5In0="
}

GET /v1/conversations/:conversationId

View a conversation thread with Customer Story.

GET https://connect-api.pcampus.co/v1/conversations/conv_xxx
Authorization: Bearer <pip_api_key>
x-tenant-id: your-tenant-id

Response:

{
  "conversationId": "conv_xxx",
  "channel": "line",
  "customerId": "cust_001",
  "status": "open",
  "messages": [
    {
      "messageId": "msg_001",
      "direction": "inbound",
      "body": "ยา Amlodipine หมดแล้วครับ",
      "sentAt": "2026-07-15T10:00:00.000Z"
    }
  ],
  "customerStory": {
    "segment": "loyal",
    "churnRisk": 0.12,
    "lastVisit": "2026-07-12",
    "topProduct": "Amlodipine 5mg",
    "recommendations": [
      { "type": "reorder", "message": "เสนอสั่งซ้ำ Amlodipine 5mg 30 เม็ด" }
    ]
  },
  "suggestedReply": "ได้เลยครับ คุณสมชาย Amlodipine 5mg 30 เม็ด ราคา ฿180 จัดส่งได้วันนี้ครับ ต้องการสั่งเลยไหมครับ?"
}

PATCH /v1/conversations/:conversationId

Update status or assignment.

PATCH https://connect-api.pcampus.co/v1/conversations/conv_xxx
Authorization: Bearer <pip_api_key>
 
{
  "status": "resolved",
  "assignedTo": "staff-02"
}

Messages

POST /v1/conversations/:conversationId/messages

Send a reply to the customer on the same channel.

POST https://connect-api.pcampus.co/v1/conversations/conv_xxx/messages
Authorization: Bearer <pip_api_key>
 
{
  "body": "ได้เลยครับ Amlodipine 5mg 30 เม็ด ราคา ฿180 จัดส่งได้วันนี้ครับ",
  "sentBy": "staff-01",
  "suggestionUsed": true
}

Response:

{
  "messageId": "msg_002",
  "conversationId": "conv_xxx",
  "channel": "line",
  "direction": "outbound",
  "body": "ได้เลยครับ...",
  "sentAt": "2026-07-15T10:02:00.000Z",
  "deliveryStatus": "sent"
}

Rewards

POST /v1/conversations/:conversationId/rewards

Send a coupon or reward to the customer on the active channel.

POST https://connect-api.pcampus.co/v1/conversations/conv_xxx/rewards
Authorization: Bearer <pip_api_key>
 
{
  "rewardType": "coupon",
  "couponCode": "WINBACK10",
  "description": "ส่วนลด 10% สำหรับคำสั่งซื้อถัดไป",
  "validDays": 7,
  "sentBy": "staff-01"
}

Response:

{
  "rewardId": "rwd_xxx",
  "conversationId": "conv_xxx",
  "customerId": "cust_001",
  "rewardType": "coupon",
  "couponCode": "WINBACK10",
  "deliveredAt": "2026-07-15T10:03:00.000Z",
  "pbcpEventId": "evt_xxx"
}

The system automatically records a reward.sent_via_chat event back to PBCP.


Q&A Corpus

GET /v1/qa

List Q&A entries used to train the chatbot.

GET https://connect-api.pcampus.co/v1/qa
Authorization: Bearer <pip_api_key>
x-tenant-id: your-tenant-id

POST /v1/qa

Add a new Q&A entry.

POST https://connect-api.pcampus.co/v1/qa
Authorization: Bearer <pip_api_key>
 
{
  "question": "ยา Amlodipine กินตอนไหนครับ",
  "answer": "กินได้ทุกเวลาครับ แต่ควรกินเวลาเดิมทุกวัน เช่น หลังอาหารเช้าทุกวัน",
  "tags": ["amlodipine", "วิธีกิน"],
  "domain": "pharmacy"
}

PATCH /v1/qa/:qaId

DELETE /v1/qa/:qaId


Widget

GET /v1/widget/config

Fetch the config used to render the widget on the client.

GET https://connect-api.pcampus.co/v1/widget/config
Authorization: Bearer <pip_api_key>
x-tenant-id: your-tenant-id

Response:

{
  "tenantId": "pharmacy-demo",
  "domain": "pharmacy",
  "primaryColor": "#2563eb",
  "position": "bottom-right",
  "quickActions": ["ประวัติยา", "สั่งยาซ้ำ", "ปรึกษาเภสัชกร"],
  "businessHours": { "open": "08:00", "close": "20:00", "timezone": "Asia/Bangkok" },
  "offlineMessage": "ร้านปิดแล้วครับ จะติดต่อกลับในวันทำการถัดไป"
}

Identity — External IdP Binding

POST /v1/identity/exchange

Exchange an External IdP token for a Connect session token (called automatically by the widget SDK).

POST https://connect-api.pcampus.co/v1/identity/exchange
x-tenant-id: your-tenant-id
 
{
  "provider": "firebase",
  "identityToken": "<firebase_id_token>"
}

Response:

{
  "sessionToken": "cses_xxx",
  "expiresAt": "2026-07-15T11:00:00.000Z",
  "customerId": "cust_001",
  "isNewCustomer": false
}

Supported providers:

providerConfiguration required in Console
firebaseFirebase Project ID
auth0Domain + Audience
supabaseProject URL + JWT Secret
customJWKS URI

GET /v1/identity/providers

List External IdP providers configured for the tenant.

GET https://connect-api.pcampus.co/v1/identity/providers
Authorization: Bearer <pip_api_key>
x-tenant-id: your-tenant-id

Platform docs → · Intelligence API →