การเชื่อมต่อ Meta และ Instagram API
เอกสารอ้างอิงสำหรับการสร้างแอป Instagram บน SMSBAT ChatHub Platform: การยืนยันตัวตน การสนทนา Instagram Direct, ความคิดเห็นในโพสต์และ Reels, การตอบกลับ Story, webhook และ polling
แหล่งที่มา
หน้านี้รวมข้อกำหนดภายในของ Meta Comments API เข้ากับคำนิยาม OpenAPI
ที่ใช้งานจริงที่ https://chatapi.smsbat.com/swagger/v1/swagger.json และ
https://restapi.smsbat.com/swagger/v1/swagger.json หากทั้งสองแหล่งไม่ตรงกัน
ความแตกต่างจะถูกระบุไว้ในเนื้อหาและแสดงรายการไว้ในคำถามที่ยังไม่มีคำตอบ
1. Base URL
| วัตถุประสงค์ | URL |
|---|---|
| Chat API + Meta API | https://chatapi.smsbat.com |
| Swagger UI / OpenAPI | https://chatapi.smsbat.com/index.html · …/swagger/v1/swagger.json |
| REST API (องค์กร, callback URL) | https://restapi.smsbat.com |
| REST API Swagger | https://restapi.smsbat.com/swagger/v1/swagger.json |
| แผงควบคุมผู้ปฏิบัติงานบนเว็บ | https://chat.smsbat.com |
2. การยืนยันตัวตน
รูปแบบการยืนยันตัวตน ขึ้นอยู่กับกลุ่ม endpoint การใช้ปะปนกันเป็นสาเหตุที่พบบ่อยที่สุดของ 401
| กลุ่ม | เฮดเดอร์ |
|---|---|
chatapi.smsbat.com/api/meta/* (posts, comments) | X-Authorization-Key: <organization token> |
chatapi.smsbat.com/api/chat/*, /api/company/*, /api/operator/* | Authorization: Bearer <JWT> |
restapi.smsbat.com/* | X-Authorization-Key · Authorization: Bearer · Basic Auth |
โทเคนองค์กรสำหรับ X-Authorization-Key ออกให้ในแผงควบคุมที่ โปรไฟล์
JWT ของบริษัทและผู้ปฏิบัติงานได้มาจาก /api/company/get-token และ /api/operator/get-token
ความไม่สอดคล้อง
เอกสาร OpenAPI ของ chatapi ประกาศรูปแบบความปลอดภัยเพียงรูปแบบเดียวคือ Bearer และใช้
กับทุก endpoint X-Authorization-Key ไม่ได้ถูกประกาศไว้เลย แม้ว่าข้อกำหนดภายในของ Meta
Comments API จะระบุไว้สำหรับ /api/meta/* ก็ตาม เป็นไปได้มากว่าถูกจัดการโดย
middleware ที่ไม่ได้สะท้อนอยู่ใน Swagger โปรดยืนยันด้วยการทดสอบจริงก่อนนำขึ้นใช้งานจริง
2.1 โทเคนบริษัท
POST https://chatapi.smsbat.com/api/company/get-token
Content-Type: application/json
{ "login": "company_login", "password": "company_password" }
200 OK ส่งคืนสตริงโทเคนเปล่า
2.2 องค์กร
GET https://chatapi.smsbat.com/api/company/organization
Authorization: Bearer <company_token>
[ { "id": 24, "name": "My Instagram Store" } ]
2.3 ผู้ปฏิบัติงานในองค์กร
GET https://chatapi.smsbat.com/api/operator?organizationId=24
Authorization: Bearer <company_token>
[
{
"id": 21,
"name": "Jane Doe",
"status": 0,
"organization": { "id": 24, "name": "My Instagram Store" }
}
]
สถานะผู้ปฏิบัติงาน: 0 ใช้งานอยู่, 1 ไม่ใช้งาน, 2 ถูกลบ
2.4 เพิ่ม / ซิงโครไนซ์ผู้ปฏิบัติงาน
POST https://chatapi.smsbat.com/api/operator/synchronize
Authorization: Bearer <company_token>
Content-Type: application/json
[ { "organizationId": 24, "name": "John Operator" } ]
200 OK → [ { "id": 21, "status": 0, "name": "John Operator" } ]
2.5 JWT ของผู้ปฏิบัติงาน
POST https://chatapi.smsbat.com/api/operator/get-token
Authorization: Bearer <company_token>
Content-Type: application/json
{ "id": 21, "expiresAt": "2026-12-31T23:59:59.000Z" }
200 OK ส่งคืน JWT เป็นสตริง
2.6 ตรวจสอบโทเคนของผู้ปฏิบัติงาน
POST https://chatapi.smsbat.com/api/operator/validate-token
Authorization: Bearer <company_token>
Content-Type: application/json
"eyJhbGciOi..."
{
"isValid": true,
"operatorId": 21,
"clientId": 0,
"expiresAt": "2026-12-31T23:59:59.000Z",
"error": null
}
เมื่อไม่ถูกต้อง: { "isValid": false, "error": "Invalid token" }
2.7 ฝังแผงแชทของผู้ปฏิบัติงาน
<script type="module" id="operator-chat-panel-script"
src="https://widget.smsbat.com/operator-chat-panel/widget-script.js"
token="YOUR_OPERATOR_JWT_TOKEN"></script>
3. Deeplink เข้าสู่แผงแชท
ระบบภายนอก (CRM, ERP, เว็บไซต์) สามารถเปิดการสนทนาที่ระบุใน
https://chat.smsbat.com/ ได้ ผู้ปฏิบัติงานได้รับการอนุญาตผ่าน JWT ที่ส่งเป็นพารามิเตอร์ query
https://chat.smsbat.com/?chat_raw_id=<chat_id>&token=<jwt>
https://chat.smsbat.com/?phone=<phone>&token=<jwt>
https://chat.smsbat.com/?from=<bm_id>&phone=<phone>&token=<jwt>
https://chat.smsbat.com/?source=7&from=<bm_id>&phone=<phone>&token=<jwt>
| พารามิเตอร์ | คำอธิบาย |
|---|---|
chat_raw_id | ID ของแชท |
phone | หมายเลขโทรศัพท์ในรูปแบบสากล |
from | ตัวระบุแบรนด์ / บัญชีธุรกิจ (bm_id) |
source | แหล่งที่มาของแชท — 7 สำหรับ Instagram ดู §8.1 |
token | JWT ของผู้ปฏิบัติงานที่ถูกต้อง ยังไม่หมดอายุ และมีสิทธิ์เข้าถึงแชท |
JWT ที่ไม่ถูกต้องจะพาผู้เยี่ยมชมไปยังหน้าจอเข้าสู่ระบบของแผงควบคุมผู้ปฏิบัติงาน
4. การสนทนา Instagram Direct
4.1 แสดงรายการแชท
GET https://chatapi.smsbat.com/api/chat/chats?source=7&page=1&per_page=20
Authorization: Bearer <token>
Note
การแบ่งหน้าที่นี่ใช้ per_page (snake_case) ส่วนภายใต้ /api/meta/* และ
endpoint สำหรับ polling จะใช้ perPage (camelCase) นี่ไม่ใช่การพิมพ์ผิด — API ใช้ทั้งสองแบบ
พารามิเตอร์ query ทั้งหมดเป็นตัวเลือก:
| พารามิเตอร์ | ประเภท | คำอธิบาย |
|---|---|---|
source | ChatSource | 7 จำกัดผลลัพธ์เฉพาะ Instagram |
entityId | int | ID บัญชีธุรกิจ ใช้ได้เฉพาะเมื่อระบุร่วมกับ source |
instagram_user_id | int | ID ผู้ใช้ Instagram ใน ChatHub |
facebook_user_id | int | ID ผู้ใช้ Facebook ใน ChatHub |
page / per_page | int | การแบ่งหน้า ค่าเริ่มต้น 1 / 20 |
status | ChatStatus[] | สถานะแชท ระบุซ้ำได้ |
search | string | ค้นหาข้อความอิสระ (ชื่อ, เบอร์โทร, …) |
organizationId | int | ID องค์กร |
operatorId | int[] | กรองตามผู้ปฏิบัติงานที่ได้รับมอบหมาย |
date | string[] | สองค่าขอบเขต: ?date=…&date=… |
isChain | bool | ส่งคืนแชทเป็นสายโซ่ โดยรวมข้อความจากแชทก่อนหน้า |
isUnread, starMark, isOperator, isAIAgent | bool | ตัวกรองเพิ่มเติม |
phone, email, contactId, clientId, tagIds, rate, sortedBy | — | ตัวกรองอื่นๆ |
200 OK ส่งคืน GetChatsResponse:
{
"total": 1,
"newMessagesCount": 2,
"items": [
{
"id": 1867,
"theme": null,
"messSource": 7,
"chatStatus": 1,
"countUnread": 2,
"metaUserId": "1585775752382460",
"instaAccount": { "id": 12, "name": "my_instagram_shop", "photo": "https://..." },
"instagramUser": { "id": 123, "name": "marianna_cat", "photo": "https://..." },
"operator": { "id": 21, "name": "Jane", "photo": "https://..." },
"client": { "id": 55, "name": "Marianna", "photo": null },
"textLastMess": "Hello! Is this product available?",
"timeLastMess": "2026-08-13T10:15:00Z",
"authorLastMessage": 1,
"messageStatus": 6,
"isMedia": false,
"phone": null,
"organizationId": 1,
"createdAt": "2026-08-13T10:14:00Z",
"isStarred": false,
"isBlocked": false,
"tags": []
}
]
}
ฟิลด์ที่สำคัญสำหรับแอป Instagram:
| ฟิลด์ | ความหมาย |
|---|---|
instaAccount | บัญชีธุรกิจ Instagram (ร้านค้า) id คือค่าของตัวกรอง entityId; name คือชื่อบัญชีจาก Meta |
instagramUser | ลูกค้า name คือแฮนเดิล Instagram, id คือค่าของตัวกรอง instagram_user_id |
metaUserId | ID แบบ scoped ของลูกค้าฝั่ง Meta (สตริง) |
messSource | 7 สำหรับ Instagram |
phone | โดยปกติเป็น null สำหรับ Instagram — อย่าใช้เป็นคีย์ |
ChatDTO ยังมี olxUser, promUser, waba, rozetkaUser, facebookAccount,
facebookUser, viberAccount, tgBot, tgUser, viberBot, viberBotUser, widget,
media, isConnectedAI, isPromo, rate, rateComment, closedBy, draft, lang,
starMark, contactId, contactName, block, isInStopList, stopList,
isSmsFallbackEnabled และ taggedMessages ด้วย
4.2 ข้อความในแชท
GET https://chatapi.smsbat.com/api/chat/chats/1867/messages?isChain=false
Authorization: Bearer <token>
200 OK ส่งคืนอาร์เรย์ของ ChatMessageDTO:
[
{
"id": 9928,
"chatId": 1867,
"message": "Hi! Do you have size M in stock?",
"messageTranslation": null,
"phone": null,
"author": 1,
"source": 7,
"media": null,
"replyTo": null,
"status": 6,
"date": "2026-08-13T10:14:00Z",
"operator": null,
"client": { "id": 123, "name": "marianna_cat", "photo": "https://..." },
"messageType": 0,
"isInternal": false,
"isBroadcast": false,
"starMark": false,
"referralGuid": null,
"postId": null,
"isConnectedAI": false,
"organizationId": 1,
"countUnreadMessages": 0
}
]
postId จะมีค่าเมื่อข้อความเกี่ยวข้องกับโพสต์หรือ Story บน Instagram — ส่งค่านี้
กลับไปเป็น id / postId ใน Meta API ได้โดยตรง media คือ ChatMediaDTO:
{ name, format, type, uri, raw, length, isUploaded }.
4.3 ส่งข้อความ (JSON)
POST https://chatapi.smsbat.com/api/chat/1867/message
Authorization: Bearer <token>
Content-Type: application/json
เนื้อหาคำขอ — SendChatMessageDTO:
{
"textMessage": "Hello! Yes, size M is available.",
"author": 0,
"isInternal": false,
"replyToMessageId": 9928,
"appGuid": "550e8400-e29b-41d4-a716-446655440000",
"media": {
"name": "item.jpg",
"format": "image/jpeg",
"dataBase64": "/9j/4AAQSkZJRg...",
"type": 1
}
}
| ฟิลด์ | ประเภท | คำอธิบาย |
|---|---|---|
textMessage | string? | ข้อความ อาจว่างได้เมื่อมี media |
author | AuthorMessage? | 0 ผู้ปฏิบัติงาน, 1 ลูกค้า |
isInternal | bool? | true หมายถึงบันทึกภายในที่ไม่ถูกส่งถึงลูกค้า |
replyToMessageId | int? | ID ของข้อความที่ตอบกลับ |
appGuid | uuid? | GUID อ้างอิง |
media | MediaDTO? | { name, format, dataBase64, thumbnail, duration, type } |
200 OK → { "id": 9930, "messageStatus": 0 }
สามารถส่ง GUID อ้างอิงในพาธได้เช่นกัน:
POST /api/chat/{chatId}/{referralGuid}/message (likewise …/message/v1, …/message/v2).
4.4 ส่งไฟล์หรือวิดีโอ (multipart, v2)
POST https://chatapi.smsbat.com/api/chat/1867/message/v2
Authorization: Bearer <token>
Content-Type: multipart/form-data
ชื่อฟิลด์ฟอร์มเป็น PascalCase และใช้เครื่องหมายจุด
textMessage และ media.file จะถูกละเว้นโดยไม่มีการแจ้งเตือน ใช้ชื่อที่ถูกต้องตามด้านล่างนี้
| ฟิลด์ฟอร์ม | ประเภท | คำอธิบาย |
|---|---|---|
TextMessage | string | ข้อความ |
Author | int | 0 ผู้ปฏิบัติงาน, 1 ลูกค้า |
IsInternal | bool | บันทึกภายใน |
ReplyToMessageId | int | ข้อความที่ตอบกลับ |
AppGuid | uuid | GUID อ้างอิง |
Media.File | binary | ตัวไฟล์ |
Media.Name | string | ชื่อไฟล์ |
Media.Format | string | ประเภท MIME (video/mp4, image/png, application/pdf) |
Media.Type | MediaType | ดู §8.5 |
Media.DataBase64 | string | ทางเลือกแทน Media.File |
Media.Thumbnail | string | เฟรมตัวอย่างวิดีโอแบบ Base64 |
Media.Duration | double | ความยาววิดีโอเป็นวินาที |
curl -X POST "https://chatapi.smsbat.com/api/chat/1867/message/v2" \
-H "Authorization: Bearer <token>" \
-F "TextMessage=Here is the price list" \
-F "Author=0" \
-F "Media.Type=2" \
-F "Media.File=@./price.pdf"
200 OK → { "id": 9931, "messageStatus": 0 }
4.5 เปลี่ยนสถานะแชท
PUT https://chatapi.smsbat.com/api/chat/status
Authorization: Bearer <token>
Content-Type: application/json
{ "id": 1867, "status": 4 }
200 OK ส่งคืนอ็อบเจ็กต์ที่อัปเดตแล้วกลับมา
4.6 อัปเดตสถานะข้อความ
PUT https://chatapi.smsbat.com/api/chat/messages/status
Authorization: Bearer <token>
Content-Type: application/json
{ "status": 3, "messageIds": [9928, 9929] }
4.7 ลบแชท
DELETE https://chatapi.smsbat.com/api/chat/chats/1867
Authorization: Bearer <token>
5. โพสต์ Reels และ Stories
พาธฐาน: https://chatapi.smsbat.com/api/meta
การยืนยันตัวตน: X-Authorization-Key: <organization token>
5.1 แสดงรายการโพสต์ Reels และ Stories
GET https://chatapi.smsbat.com/api/meta/posts?platform=instagram&mediaType=story&page=1&perPage=20
X-Authorization-Key: <token>
| พารามิเตอร์ | ประเภท | จำเป็น | คำอธิบาย |
|---|---|---|---|
page | int | ไม่ | หน้า ค่าเริ่มต้น 1 |
perPage | int | ไม่ | จำนวนรายการต่อหน้า ค่าเริ่มต้น 20 |
id | int | ไม่ | กรองตาม ID โพสต์ภายใน |
platform | string | ไม่ | instagram หรือ facebook |
mediaType | string | ไม่ | post, reel หรือ story หากไม่ระบุจะรวมทุกประเภท |
# Every post
curl -H "X-Authorization-Key: <token>" \
"https://chatapi.smsbat.com/api/meta/posts?page=1&perPage=10"
# Instagram only
curl -H "X-Authorization-Key: <token>" \
"https://chatapi.smsbat.com/api/meta/posts?platform=instagram"
# A single post by ID
curl -H "X-Authorization-Key: <token>" \
"https://chatapi.smsbat.com/api/meta/posts?id=42"
# Instagram Stories only
curl -H "X-Authorization-Key: <token>" \
"https://chatapi.smsbat.com/api/meta/posts?platform=instagram&mediaType=story"
200 OK:
{
"total": 42,
"items": [
{
"id": 42,
"metaId": "18113450675314072",
"text": "Check out our new collection!",
"imageUrl": "https://dashboard.smsbat.com/api/meta/post/media/7d124c36-1711-4aa8-b21d-f6dbf8f347ef",
"platform": "instagram",
"mediaType": "story",
"createdAt": "2026-07-22T09:35:30Z",
"story": {
"id": 42,
"metaId": "18113450675314072",
"url": "https://dashboard.smsbat.com/api/meta/post/media/7d124c36-1711-4aa8-b21d-f6dbf8f347ef"
}
}
]
}
ความไม่สอดคล้อง — ชื่อฟิลด์ตัวนับ
สคีมา Swagger MetaCommentPostListItemDtoPaginationDTO กำหนด total ส่วน
ข้อกำหนดภายในระบุ totalCount Swagger สร้างจากโค้ด ดังนั้น
total น่าจะเป็นค่าที่ถูกต้องมากกว่า ให้แยกวิเคราะห์ total ?? totalCount จนกว่าจะได้ข้อสรุป
| ฟิลด์ | คำอธิบาย |
|---|---|
id | ID โพสต์ภายใน |
metaId | ID โพสต์ / Reel / Story ภายนอกใน Meta |
text | คำบรรยายภาพของโพสต์ |
imageUrl | URL สื่อแบบพร็อกซีที่อ้างอิงด้วย MetaPost.Guid ที่ไม่เรียงลำดับ หรือ null |
platform | facebook หรือ instagram |
mediaType | post, reel หรือ story |
createdAt | วันที่สร้าง (วันที่ของแพลตฟอร์ม หรือวันที่ในฐานข้อมูล) |
story | มีอยู่ เฉพาะ เมื่อ mediaType: "story" |
story.id | ID Story ภายใน; เท่ากับ post.id |
story.metaId | ID Story ภายนอกใน Meta |
story.url | URL พร็อกซีที่คงที่ของสื่อ Story ที่จัดเก็บไว้; เป็น null หากบันทึกสื่อไม่สำเร็จ |
สื่อของโพสต์ให้บริการผ่านสองเส้นทาง: GET /api/meta/post/media/{id:int} เพื่อความเข้ากันได้
ย้อนหลัง และ GET /api/meta/post/media/{guid:guid} การตอบกลับและ callback ของ API ใหม่
จะสร้างในรูปแบบ GUID เสมอ
5.2 แสดงรายการความคิดเห็น
GET https://chatapi.smsbat.com/api/meta/comments?platform=instagram&postId=42&page=1&perPage=20
X-Authorization-Key: <token>
| พารามิเตอร์ | ประเภท | จำเป็น | คำอธิบาย |
|---|---|---|---|
page | int | ไม่ | หน้า ค่าเริ่มต้น 1 |
perPage | int | ไม่ | จำนวนรายการต่อหน้า ค่าเริ่มต้น 20 |
postId | int | ไม่ | กรองตาม ID โพสต์ |
parentCommentId | int | ไม่ | ความคิดเห็นย่อย (การตอบกลับ) ของความคิดเห็นที่ระบุ |
platform | string | ไม่ | facebook หรือ instagram |
200 OK:
{
"total": 100,
"items": [
{
"id": 5,
"metaId": "179000000000005",
"text": "What is the price?",
"createdAt": "2026-04-15T10:30:00Z",
"platform": "instagram",
"replyStatus": null,
"author": {
"type": "meta_user",
"name": "John Doe",
"metaUserId": "1585775752382460"
},
"post": {
"id": 1,
"metaId": "18113450675314072",
"text": null,
"imageUrl": "https://dashboard.smsbat.com/api/meta/post/media/7d124c36-…",
"createdAt": "2026-07-22T09:35:30Z",
"mediaType": "story",
"story": {
"id": 1,
"metaId": "18113450675314072",
"url": "https://dashboard.smsbat.com/api/meta/post/media/7d124c36-…"
}
},
"mediaUrl": "https://chatapi.smsbat.com/api/meta/comment/media/5",
"replyTo": {
"id": 3,
"metaId": "179000000000003",
"text": "Parent comment..."
}
}
]
}
| ฟิลด์ | คำอธิบาย |
|---|---|
id | ID ความคิดเห็นภายใน |
metaId | ID ภายนอกใน Meta เป็น null สำหรับการตอบกลับของเราที่รอดำเนินการจนกว่าจะส่ง |
text | ข้อความความคิดเห็น |
createdAt | วันที่สร้าง |
platform | facebook หรือ instagram |
replyStatus | null สำหรับความคิดเห็นขาเข้าของผู้ใช้; "pending" / "sent" / "failure" สำหรับการตอบกลับของเรา |
author.type | "meta_user" ผู้ใช้ภายนอก, "owner" เจ้าของเพจ |
author.name | ชื่อผู้เขียน |
author.metaUserId | ID ผู้ใช้แบบ scoped ใน Meta; เป็น null สำหรับ "owner" |
post | โพสต์ Reel หรือ Story ที่ความคิดเห็นนั้นอยู่ |
post.mediaType | post, reel หรือ story |
post.story | การอ้างอิง Story { id, metaId, url } เฉพาะ Stories เท่านั้น |
mediaUrl | สื่อที่แนบกับความคิดเห็น หรือ null |
replyTo | ความคิดเห็นหลัก { id, metaId, text }; เป็น null ในระดับบนสุด |
ความไม่สอดคล้อง — ประเภทของ `author.type`
ข้อกำหนดภายในระบุสตริง "meta_user" / "owner" ส่วน Swagger กำหนดประเภทของ
MetaCommentAuthorType เป็น จำนวนเต็ม พร้อม enum [0, 1] การใช้ JsonStringEnumConverter
อาจอธิบายความต่างนี้ได้ แต่ยังไม่ได้ยืนยันกับการตอบกลับจริง ให้เขียน
parser ที่รองรับทั้งสองแบบ
5.3 ตอบกลับความคิดเห็น
จัดคิวการตอบกลับเพื่อส่ง
curl -X POST \
-H "X-Authorization-Key: <token>" \
-H "Content-Type: application/json" \
-d '{"text": "Thanks for the feedback!"}' \
"https://chatapi.smsbat.com/api/meta/comments/5/reply"
เนื้อหาคำขอ: { "text": "Reply text" }
202 Accepted ส่งคืนอ็อบเจ็กต์ความคิดเห็น — รูปแบบเดียวกับ GET /api/meta/comments — พร้อม
replyStatus: "pending" และ metaId: null ผลการส่งจะมาถึงภายหลังเป็น
callback source: 13 (§6.4)
ความไม่สอดคล้อง — รหัสตอบกลับ
Swagger ประกาศ 200 โดยไม่มี body ส่วนข้อกำหนดภายในประกาศ 202 Accepted
พร้อมความคิดเห็นเป็น body เป็นไปได้มากว่า controller ขาดแอตทริบิวต์ ProducesResponseType
ทำให้ Swagger ใช้ค่าเริ่มต้น ให้ยอมรับ 2xx ใดๆ และอย่าพึ่งพา body
6. Webhook
SMSBAT ส่งคำขอ POST แบบ application/json ไปยัง URL ของคุณ และคาดหวังให้ตอบกลับ HTTP 200
ฟิลด์ที่เป็น null จะถูกละไว้ทั้งหมด
ฟิลด์ที่มีค่าเป็น null จะไม่ถูกซีเรียไลซ์ลงใน body ของ callback เลย สำหรับ
ข้อความที่ไม่ได้มาจาก Facebook หรือ Instagram จะไม่มีคีย์ MetaUserId เลย
ให้ถือว่า “ไม่มี” และ null เป็นสิ่งเดียวกัน
6.1 ลงทะเบียน callback URL
curl -X POST 'https://restapi.smsbat.com/organizations/callback_urls' \
-H 'X-Authorization-Key: <token>' \
-H 'Content-Type: application/json' \
-d '{
"url": "https://your-server.com/webhook",
"source": 12,
"headerName": "X-Webhook-Secret",
"headerValue": "your-secret",
"channelType": 7,
"channelEntityId": 12
}'
| ฟิลด์ | ประเภท | คำอธิบาย |
|---|---|---|
url | string | endpoint ของคุณ |
source | SendingSourceCallback | ประเภทเหตุการณ์ ดู §8.2 |
headerName / headerValue | string | เฮดเดอร์สำหรับยืนยันตัวตนตามที่คุณกำหนดซึ่งเราจะแนบไปกับคำขอ (ไม่บังคับ) |
channelType | ChatSource | ช่องทาง 7 สำหรับ Instagram ไม่บังคับ |
channelEntityId | int | บัญชีธุรกิจที่ระบุ ต้องใช้ร่วมกับ channelType |
หากไม่ระบุ channelType URL จะได้รับเหตุการณ์จากทุกช่องทาง
Tip
การครอบคลุมความคิดเห็นอย่างครบถ้วนต้องลงทะเบียน สอง รายการ: source: 12 สำหรับความคิดเห็นใหม่ และ
source: 13 สำหรับสถานะการตอบกลับ สำหรับการตอบกลับใน Direct และ Story ให้เพิ่ม source: 3
(and 11 if you want every chat message).
การดำเนินการที่เหลือ:
GET https://restapi.smsbat.com/organizations/callback_urls?source=12
GET https://restapi.smsbat.com/organizations/callback_urls/{id}
PUT https://restapi.smsbat.com/organizations/callback_urls/{id}
DELETE https://restapi.smsbat.com/organizations/callback_urls/{id}
GET ส่งคืน:
[
{
"id": 101,
"url": "https://your-server.com/webhook",
"source": 12,
"headerName": "X-Webhook-Secret",
"headerValue": "your-secret",
"createdAt": "2026-08-13T09:00:00Z",
"channelType": 7,
"channelEntityId": 12
}
]
6.2 ข้อความใหม่และการตอบกลับ Instagram Story (source: 3, 11)
การตอบกลับของผู้ใช้ต่อ Instagram Story จะมาถึงเป็นข้อความปกติใน callback เหล่านี้
พร้อมบล็อก Story เพิ่มเติมในระดับบนสุด:
{
"ChatId": 123,
"MessageId": 456,
"MessageText": "😍",
"Username": "Jane Smith",
"UserId": 789,
"MetaUserId": "1585775752382460",
"ShopId": 12,
"ShopName": "instagram shop name",
"Author": 0,
"type_messenger": 7,
"Story": {
"Id": 42,
"MetaId": "18113450675314072",
"Url": "https://dashboard.smsbat.com/api/meta/post/media/7d124c36-1711-4aa8-b21d-f6dbf8f347ef"
}
}
| ฟิลด์ | คำอธิบาย |
|---|---|
ChatId / MessageId | ตัวระบุแชทและข้อความ |
Author | 0 ผู้ใช้, 1 ผู้ปฏิบัติงาน |
Username | ชื่อที่แสดงหรือแฮนเดิลของ Instagram / Facebook |
UserId | ID ผู้ใช้ตัวเลขภายในของ SMSBAT |
MetaUserId | ID แบบ scoped ของคู่สนทนาใน Meta สำหรับข้อความ ขาออก ของผู้ปฏิบัติงาน ค่านี้ยังคงระบุผู้ใช้ Meta ของแชท ไม่ใช่ผู้ปฏิบัติงาน |
ShopId | ID ภายในของบัญชีธุรกิจ Instagram / Facebook |
ShopName | ชื่อบัญชีธุรกิจตามที่ได้รับจาก Meta ณ เวลาที่เชื่อมต่อ |
MessageText | ข้อความ |
MessageMedia | URL ของสื่อเมื่อข้อความเป็นสื่อ |
type_messenger | แหล่งที่มา 7 สำหรับ Instagram |
operator_name | ชื่อผู้ปฏิบัติงานเมื่อ Author = 1 |
Story | มี เฉพาะ ในการตอบกลับ Story ขาเข้า |
Story.Id | ID Story ภายใน (MetaPost) — ใช้เป็น id / postId ใน Meta API ได้โดยตรง |
Story.MetaId | ID Story ภายนอกใน Meta |
Story.Url | URL พร็อกซีที่คงที่ของสื่อ Story ที่จัดเก็บไว้ จะไม่มีเมื่อบันทึกสื่อไม่สำเร็จ — บล็อก Story และข้อความยังคงถูกส่งตามปกติ |
`Author` กลับค่าตรงข้ามกับ Chat API
ใน ChatMessageDTO.author ค่า 0 หมายถึงผู้ปฏิบัติงานและ 1 หมายถึงลูกค้า ใน callback นี้
เป็นตรงกันข้าม: 0 คือผู้ใช้ และ 1 คือผู้ปฏิบัติงาน อย่าใช้การแมปร่วมกัน
6.3 ความคิดเห็นใหม่ (source: 12)
ทำงานเมื่อผู้ใช้ Meta แสดงความคิดเห็นในโพสต์ Facebook หรือโพสต์ / Reel บน Instagram
Note
การตอบกลับ Story บน Instagram จะไม่ถูกส่งผ่าน source: 12 แต่จะมาถึงเป็นข้อความ
ขาเข้าปกติใน source: 3 และ/หรือ 11 พร้อมบล็อก Story — ดู §6.2
{
"type": "new_comment",
"platform": "instagram",
"comment": {
"id": 10,
"metaId": "179000000000010",
"parentCommentId": 5,
"parentMetaId": "179000000000005",
"parentCommentText": "The user's previous comment",
"text": "Great product!",
"createdAt": "2026-04-16T12:00:00Z",
"author": {
"type": "meta_user",
"name": "Jane Smith",
"metaUserId": "1585775752382460"
}
},
"post": {
"id": 1,
"metaId": "123456789012345",
"text": "Post description...",
"imageUrl": "https://dashboard.smsbat.com/api/meta/post/media/7d124c36-…",
"createdAt": "2026-04-10T12:00:00Z",
"mediaType": "post"
}
}
6.4 สถานะการตอบกลับความคิดเห็น (source: 13)
ทำงานหลังจากเราพยายามส่งการตอบกลับ ไม่ว่าจะสำเร็จหรือล้มเหลว
{
"type": "comment_status",
"platform": "instagram",
"comment": {
"id": 15,
"metaId": "179000000000015",
"parentCommentId": 10,
"parentMetaId": "179000000000010",
"parentCommentText": "Great product!",
"text": "Thanks for the feedback!",
"createdAt": "2026-04-16T12:05:00Z",
"updatedAt": "2026-04-16T12:05:03Z",
"replyStatus": "sent",
"author": {
"type": "owner",
"name": "Support Agent"
}
},
"post": {
"id": 1,
"metaId": "179999999999999",
"text": "Reel description...",
"imageUrl": "https://dashboard.smsbat.com/api/meta/post/media/7d124c36-…",
"createdAt": "2026-07-22T09:35:30Z",
"mediaType": "reel"
}
}
6.5 ฟิลด์ callback ความคิดเห็นที่ใช้ร่วมกัน
callback ความคิดเห็นทั้งสองแบบใช้ รูปแบบ body เดียวกัน และต่างกันที่ type เท่านั้น
| ฟิลด์ | คำอธิบาย |
|---|---|
type | "new_comment" หรือ "comment_status" |
platform | "facebook" หรือ "instagram" |
comment.id | ID ความคิดเห็นภายใน |
comment.metaId | ID ภายนอกใน Meta; เป็น null สำหรับการตอบกลับที่รอดำเนินการก่อนส่ง |
comment.parentCommentId | ID ความคิดเห็นหลัก ไม่มี สำหรับความคิดเห็นระดับบนสุด |
comment.parentMetaId | ID ภายนอกของความคิดเห็นหลัก ไม่มีในระดับบนสุด |
comment.parentCommentText | ข้อความของความคิดเห็นหลัก ไม่มีในระดับบนสุด |
comment.text | ข้อความความคิดเห็น |
comment.createdAt | วันที่สร้าง |
comment.updatedAt | การอัปเดตล่าสุด ไม่มีหากความคิดเห็นไม่เคยถูกแก้ไข |
comment.replyStatus | "pending" / "sent" / "failure" ไม่มี สำหรับความคิดเห็นขาเข้าของผู้ใช้ |
comment.author.type | "meta_user" หรือ "owner" |
comment.author.name | ชื่อผู้เขียน |
comment.author.metaUserId | ID ผู้เขียนแบบ scoped ใน Meta ไม่มีสำหรับ "owner" |
comment.mediaUrl | สื่อของความคิดเห็น ไม่มีเมื่อไม่มีสื่อ |
post.id | ID โพสต์ภายใน |
post.metaId | ID โพสต์ / Reel / Story ภายนอกใน Meta |
post.text | ข้อความโพสต์ |
post.imageUrl | URL รูปภาพของโพสต์ หรือ null |
post.createdAt | วันที่สร้างโพสต์ |
post.mediaType | ใน callback ความคิดเห็น มีเพียง post หรือ reel |
6.6 แชทใหม่ (source: 7)
{ "ChatId": 12345, "Phone": "+380501234567", "chat.Source": 7 }
6.7 การเปลี่ยนแปลงสถานะข้อความและแชท (source: 6 / 5)
{ "name": "changed_message_status", "id": 9928, "status": 6 }
{ "name": "changed_chat_status", "id": 1867, "status": 4 }
6.8 ข้อความถูกแก้ไขหรือลบ (source: 9)
{ "messageId": 9930, "text": "Updated message text" }
{ "messageId": 9931, "delete": true }
6.9 ตัวบ่งชี้การพิมพ์ (source: 8)
{ "chat_id": 1867, "event": "start_typing", "operator_name": "Iryna" }
{ "chat_id": 1867, "event": "end_typing" }
7. การ polling เหตุการณ์
สำหรับสภาพแวดล้อมที่ไม่สามารถรับ HTTP ขาเข้าได้
7.1 ดึงเหตุการณ์
GET https://chatapi.smsbat.com/api/chat/callback-events?page=1&perPage=20
Authorization: Bearer <token>
| พารามิเตอร์ | คำอธิบาย |
|---|---|
organizationId | ไม่บังคับ ใช้ค่าจากโทเคนเมื่อไม่ระบุ |
page / perPage | การแบ่งหน้า ค่าเริ่มต้น 1 / 20 |
{
"page": 1,
"perPage": 20,
"total": 947,
"items": [
{
"ChatId": 1867,
"MessageId": 9928,
"MessageText": "Hello there!",
"MessageMedia": null,
"Phone": null,
"Username": "marianna_cat",
"UserId": 123,
"ShopId": 12,
"ShopName": "instagram shop name",
"Author": 1,
"type_messenger": 7,
"message_date": "2026-08-13T12:27:39.724Z",
"timestamp": "2026-08-13T12:27:39.736Z",
"event_guid": "ff60129e-c6e4-4876-9d90-badb430c0606",
"organization_id": 1,
"callback_type": "3"
}
]
}
ทุกเหตุการณ์มี event_guid, timestamp, organization_id และ callback_type — เป็น
สตริงที่ตรงกับค่า source ใน §8.2 ฟิลด์ที่เหลือตรงกับ
webhook ที่สอดคล้องกันใน §6
7.2 ยืนยันเหตุการณ์ที่ประมวลผลแล้ว
POST https://chatapi.smsbat.com/api/chat/callback-events/processed
Authorization: Bearer <token>
Content-Type: application/json
[ "ff60129e-c6e4-4876-9d90-badb430c0606" ]
200 OK → { "deleted": 1 }
เหตุการณ์ที่ถูกลบไปแล้วจะไม่ถูกนับรวมใน deleted ลำดับและการลองใหม่เป็นความรับผิดชอบของ
ฝั่งคุณ
7.3 ลูปที่แนะนำ
- polling
GET /api/chat/callback-eventsตามกำหนดเวลา - ประมวลผลเหตุการณ์ในบริการของคุณ
- ส่งรายการ
event_guidที่ประมวลผลแล้วไปที่/callback-events/processed - ทำซ้ำ
8. เอกสารอ้างอิง Enum
8.1 ChatSource — ช่องทาง (0–9)
| รหัส | ช่องทาง |
|---|---|
| 0 | Viber |
| 1 | ViberBot |
| 2 | TelegramBot |
| 3 | |
| 4 | Widget |
| 5 | Rozetka |
| 6 | |
| 7 | |
| 8 | Prom |
| 9 | Olx |
8.2 SendingSourceCallback — ประเภทเหตุการณ์ callback (0–13)
| รหัส | เหตุการณ์ |
|---|---|
| 3 | Chat — ข้อความแชทใหม่ รวมถึงการตอบกลับ Story |
| 5 | สถานะแชทเปลี่ยนแปลง |
| 6 | สถานะข้อความเปลี่ยนแปลง |
| 7 | สร้างแชทใหม่ |
| 8 | ตัวบ่งชี้การพิมพ์ |
| 9 | ข้อความถูกอัปเดตหรือลบ |
| 11 | AnyChatMessage — ข้อความแชทใดๆ |
| 12 | MetaNewComment — ความคิดเห็นใหม่บน Instagram / Facebook |
| 13 | MetaCommentStatus — สถานะการส่งของการตอบกลับความคิดเห็นของเรา |
enum ครอบคลุม 0–13 ส่วนค่าที่เหลือไม่จำเป็นสำหรับการเชื่อมต่อ Instagram
8.3 ChatStatus (0–4)
0 New, 1 Open, 2 Waiting, 3 OnPause, 4 Closed
8.4 MessageStatus (0–11)
| รหัส | ชื่อ |
|---|---|
| 0 | NEW |
| 1 | SUCCESS |
| 2 | REJECTED |
| 3 | READ |
| 4 | UNKNOWN |
| 5 | PROCESSING |
| 6 | DELIVERED |
| 7 | BLOCKED_BY_USER |
| 8 | USER_NOT_FOUND |
enum ครอบคลุม 0–11 ค่า 9, 10 และ 11 มีอยู่ใน API แต่ยังไม่มีเอกสารประกอบ —
ให้ถือว่าเป็น UNKNOWN
8.5 MediaType (1–10)
1 Photo, 2 File, 3 Audio, 4 Video, 5 Sticker, 6 StickerAnimated,
7 StickerVideo, 8 Animation, 9 Voice, 10 VideoNote
8.6 AuthorMessage — ผู้เขียนใน Chat API (0–4)
0 Operator, 1 Client, 2 Bot, 3 ViberAccount
enum ครอบคลุม 0–4 ค่า 4 ยังไม่มีเอกสารประกอบ callback “ข้อความใหม่” ใช้
การแมปแบบตรงกันข้าม — ดู §6.2
8.7 ChatMessageType (0–2)
0 Text, 1 Photo, 2 File
8.8 replyStatus ของความคิดเห็น
null ความคิดเห็นขาเข้าของผู้ใช้, "pending" การตอบกลับของเราอยู่ในคิว, "sent" ส่งสำเร็จ,
"failure" ส่งล้มเหลว
คำถามที่ยังไม่มีคำตอบ
สามประเด็นที่ข้อกำหนดภายในกับ Swagger ที่สร้างจากโค้ดไม่ตรงกัน คำขอ หนึ่งครั้งด้วยโทเคนจริงจะยุติทั้งหมดได้ จนกว่าจะถึงตอนนั้น ให้เขียนไคลเอนต์แบบป้องกันไว้ก่อน
| # | คำถาม | ข้อกำหนด | Swagger | วิธีตรวจสอบ |
|---|---|---|---|---|
| 1 | เฮดเดอร์ยืนยันตัวตนสำหรับ /api/meta/* | X-Authorization-Key | ประกาศเฉพาะ Bearer | curl -i -H "X-Authorization-Key: <token>" ".../api/meta/posts?perPage=1" — คาดว่าจะได้ 200 ไม่ใช่ 401 |
| 2 | ฟิลด์ตัวนับในการตอบกลับของ Meta | totalCount | total | คำขอเดียวกัน — อ่านคีย์ JSON ระดับราก |
| 3 | ประเภทของ author.type และรหัสสถานะของ reply | "meta_user" / "owner", 202 พร้อม body | int [0,1], 200 ไม่มี body | curl -i .../api/meta/comments?perPage=1 พร้อมการตอบกลับทดสอบ |
แนวทางชั่วคราว:
- ตัวนับ — อ่าน
total ?? totalCount; author.type— รองรับทั้งสตริงและจำนวนเต็ม (0↔meta_user,1↔ownerการแมปต้องยืนยันอีกครั้ง);reply— ถือว่า2xxใดๆ เป็นความสำเร็จ ไม่ต้องการ body และใช้สถานะสุดท้ายจาก callbacksource: 13
หมายเหตุการติดตั้งใช้งาน
- การยืนยันตัวตนแตกต่างกันในแต่ละกลุ่ม endpoint —
/api/meta/*ใช้X-Authorization-Key, แชทและ ผู้ปฏิบัติงานใช้Bearer,restapiรับได้ทั้งสองแบบ - การแบ่งหน้าสะกดสองแบบ —
per_pageที่/api/chat/chats,perPageที่/api/meta/*และ/api/chat/callback-events - ฟิลด์
multipart/form-dataเป็น PascalCase พร้อมเครื่องหมายจุด (Media.File,Media.Type) - ฟิลด์ที่เป็น null จะถูกละไว้จาก callback — คีย์ที่ไม่มีหมายถึง
null phoneมักเป็นnullบน Instagram ให้ระบุลูกค้าด้วยinstagramUser.id/metaUserIdและร้านค้าด้วยinstaAccount.id(ค่าของตัวกรองentityId)Story.Idจาก callback ส่งกลับเป็นid/postIdใน Meta API ได้โดยตรง- ตรวจสอบ
expiresAtของ JWT ผู้ปฏิบัติงานก่อนใช้ใน deeplink หรือวิดเจ็ต