Pagsasama ng Meta at Instagram API
Sanggunian para sa pagbuo ng Instagram app sa SMSBAT ChatHub Platform: pagpapatunay, Mga direktang pag-uusap sa Instagram, komento sa mga post at Reels, mga tugon sa Kwento, webhook at botohan.
Mga Pinagmulan
Pinagsasama ng page na ito ang panloob na detalye ng Meta Comments API sa live na OpenAPI
mga kahulugan sa https://chatapi.smsbat.com/swagger/v1/swagger.json at
https://restapi.smsbat.com/swagger/v1/swagger.json. Kung saan hindi magkasundo ang dalawa, ang
Ang pagkakaiba ay tinatawag na inline at nakalista sa ilalim ng Open questions.
1. Mga Base URL
| Layunin | URL |
|---|---|
| Chat API + Meta API | https://chatapi.smsbat.com |
| Swagger UI / OpenAPI | https://chatapi.smsbat.com/index.html · …/swagger/v1/swagger.json |
| REST API (mga organisasyon, mga callback URL) | https://restapi.smsbat.com |
| REST API Swagger | https://restapi.smsbat.com/swagger/v1/swagger.json |
| Operator web panel | https://chat.smsbat.com |
2. Pagpapatunay
Ang auth scheme depende sa endpoint group. Ang paghahalo sa kanila ay ang pinakakaraniwang sanhi ng 401.
| Pangkat | Header |
|---|---|
chatapi.smsbat.com/api/meta/* (mga post, komento) | 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 |
Ang token ng organisasyon para sa X-Authorization-Key ay ibinibigay sa panel sa ilalim ng Profile.
Ang mga kumpanya at operator na JWT ay nagmula sa /api/company/get-token at /api/operator/get-token.
Pagkakaiba
Ang chatapi OpenAPI na dokumento ay nagdedeklara ng iisang security scheme — Bearer — at inilalapat ito
sa buong mundo. Ang X-Authorization-Key ay hindi idineklara doon, kahit na ang panloob na Meta
Pinangalanan ito ng detalye ng API ng Mga Komento para sa /api/meta/*. Ito ay malamang na pinangangasiwaan ng
middleware na hindi makikita sa Swagger. Kumpirmahin ang empirically bago ka magpadala.
2.1 Token ng kumpanya
POST https://chatapi.smsbat.com/api/company/get-token
Content-Type: application/json
{ "login": "company_login", "password": "company_password" }
Ang 200 OK ay nagbabalik ng hubad na token string.
2.2 Mga Organisasyon
GET https://chatapi.smsbat.com/api/company/organization
Authorization: Bearer <company_token>
[ { "id": 24, "name": "My Instagram Store" } ]
2.3 Mga operator sa isang organisasyon
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" }
}
]
Mga status ng operator: 0 Aktibo, 1 Hindi Aktibo, 2 Tinanggal.
2.4 Magdagdag / mag-synchronize ng mga operator
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 Operator 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" }
Ibinabalik ng 200 OK ang JWT bilang isang string.
2.6 I-validate ang isang operator token
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
}
Kapag hindi wasto: { "isValid": false, "error": "Invalid token" }.
2.7 I-embed ang operator chat panel
<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. Mga deeplink sa chat panel
Ang isang panlabas na sistema (CRM, ERP, website) ay maaaring magbukas ng isang partikular na pag-uusap
https://chat.smsbat.com/. Ang operator ay pinahintulutan ng isang JWT na ipinasa bilang isang parameter ng 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>
| Parameter | Paglalarawan |
|---|---|
chat_raw_id | Chat ID |
phone | Numero ng telepono sa internasyonal na format |
from | Identifier ng brand / account ng negosyo (bm_id) |
source | Pinagmulan ng chat — 7 para sa Instagram, tingnan ang §8.1 |
token | Wasto, hindi nag-expire na operator na JWT na may access sa mga chat |
Isang di-wastong JWT ang nagpunta sa bisita sa screen ng pag-login ng panel ng operator.
4. Instagram Direktang pag-uusap
4.1 Maglista ng mga chat
GET https://chatapi.smsbat.com/api/chat/chats?source=7&page=1&per_page=20
Authorization: Bearer <token>
Note
Ang pagination dito ay per_page (snake_case). Sa ilalim ng /api/meta/* at ang botohan
endpoint ito ay perPage (camelCase). Hindi ito isang typo — pareho ang ginagamit ng API.
Mga parameter ng query, lahat ay opsyonal:
| Parameter | Uri | Paglalarawan |
|---|---|---|
source | ChatSource | 7 nililimitahan ang mga resulta sa Instagram |
entityId | int | Business account ID. Inilapat lamang kasama ng source |
instagram_user_id | int | Instagram user ID sa ChatHub |
facebook_user_id | int | Facebook user ID sa ChatHub |
page / per_page | int | Pagbilang ng pahina, mga default 1 / 20 |
status | ChatStatus[] | Katayuan ng chat, nauulit |
search | string | Libreng-text na paghahanap (pangalan, telepono, …) |
organizationId | int | Organization ID |
operatorId | int[] | I-filter ayon sa mga nakatalagang operator |
date | string[] | Dalawang hangganan: ?date=…&date=… |
isChain | bool | Ibalik ang mga chat bilang mga chain, nagdadala ng mga mensahe mula sa mga nakaraang chat |
isUnread, starMark, isOperator, isAIAgent | bool | Mga karagdagang filter |
phone, email, contactId, clientId, tagIds, rate, sortedBy | — | Iba pang mga filter |
200 OK nagbabalik 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": []
}
]
}
Ang mga field na mahalaga para sa isang Instagram app:
| Patlang | Ibig sabihin |
|---|---|
instaAccount | Ang Instagram business account (ang tindahan). Ang id ay ang entityId na halaga ng filter; Ang name ay ang pangalan ng account mula sa Meta |
instagramUser | Ang customer. Ang name ay ang Instagram handle, ang id ay ang instagram_user_id filter value |
metaUserId | Ang saklaw na ID ng customer sa gilid ng Meta (string) |
messSource | 7 para sa Instagram |
phone | Karaniwan null para sa Instagram — huwag gamitin ito bilang susi |
Ang ChatDTO ay nagdadala din ng 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 at taggedMessages.
4.2 Mga mensahe sa chat
GET https://chatapi.smsbat.com/api/chat/chats/1867/messages?isChain=false
Authorization: Bearer <token>
Ang 200 OK ay nagbabalik ng hanay ng 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
}
]
Ang postId ay na-populate kapag ang mensahe ay nauugnay sa isang Instagram post o Story — ipasa ito
diretsong bumalik bilang id / postId sa Meta API. Ang media ay isang ChatMediaDTO:
{ name, format, type, uri, raw, length, isUploaded }.
4.3 Magpadala ng mensahe (JSON)
POST https://chatapi.smsbat.com/api/chat/1867/message
Authorization: Bearer <token>
Content-Type: application/json
Katawan — 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
}
}
| Patlang | Uri | Paglalarawan |
|---|---|---|
textMessage | string? | Text ng mensahe. Maaaring walang laman kapag naroroon ang media |
author | AuthorMessage? | 0 operator, 1 kliyente |
isInternal | bool? | Ang true ay nagmamarka ng panloob na tala na hindi naihatid sa customer |
replyToMessageId | int? | ID ng mensaheng sinasagot sa |
appGuid | uuid? | Referral GUID |
media | MediaDTO? | { name, format, dataBase64, thumbnail, duration, type } |
200 OK → { "id": 9930, "messageStatus": 0 }
Ang isang referral GUID ay maaari ding maipasa sa landas:
POST /api/chat/{chatId}/{referralGuid}/message (gayundin …/message/v1, …/message/v2).
4.4 Magpadala ng file o video (multipart, v2)
POST https://chatapi.smsbat.com/api/chat/1867/message/v2
Authorization: Bearer <token>
Content-Type: multipart/form-data
Ang mga pangalan ng field ng form ay PascalCase na may tuldok na notasyon
textMessage at media.file ay tahimik na binabalewala. Gamitin ang eksaktong mga pangalan sa ibaba.
| Field ng form | Uri | Paglalarawan |
|---|---|---|
TextMessage | string | Teksto ng mensahe |
Author | int | 0 operator, 1 kliyente |
IsInternal | bool | Panloob na tala |
ReplyToMessageId | int | Sinasagot ang mensahe sa |
AppGuid | uuid | Referral GUID |
Media.File | binary | Ang file mismo |
Media.Name | string | Pangalan ng file |
Media.Format | string | Uri ng MIME (video/mp4, image/png, application/pdf) |
Media.Type | MediaType | Tingnan ang §8.5 |
Media.DataBase64 | string | Alternatibo sa Media.File |
Media.Thumbnail | string | Base64 video preview frame |
Media.Duration | double | Tagal ng video sa mga segundo |
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 Baguhin ang status ng chat
PUT https://chatapi.smsbat.com/api/chat/status
Authorization: Bearer <token>
Content-Type: application/json
{ "id": 1867, "status": 4 }
200 OK echoes ang na-update na bagay.
4.6 I-update ang mga status ng mensahe
PUT https://chatapi.smsbat.com/api/chat/messages/status
Authorization: Bearer <token>
Content-Type: application/json
{ "status": 3, "messageIds": [9928, 9929] }
4.7 Magtanggal ng chat
DELETE https://chatapi.smsbat.com/api/chat/chats/1867
Authorization: Bearer <token>
5. Mga Post, Reel at Mga Kuwento
Base path: https://chatapi.smsbat.com/api/meta
Awto: X-Authorization-Key: <organization token>
5.1 Maglista ng mga post, Reels at Mga Kuwento
GET https://chatapi.smsbat.com/api/meta/posts?platform=instagram&mediaType=story&page=1&perPage=20
X-Authorization-Key: <token>
| Parameter | Uri | Kinakailangan | Paglalarawan |
|---|---|---|---|
page | int | hindi | Pahina, default 1 |
perPage | int | hindi | Mga item sa bawat pahina, default 20 |
id | int | hindi | I-filter ayon sa panloob na post ID |
platform | string | hindi | instagram o facebook |
mediaType | string | hindi | post, reel o story. Lahat ng uri kapag tinanggal |
# 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"
}
}
]
}
Pagkakaiba — pangalan ng field ng counter
Ang Swagger schema MetaCommentPostListItemDtoPaginationDTO ay tumutukoy sa total. Ang
mga dokumento ng panloob na detalye totalCount. Ang swagger ay nabuo mula sa code, kaya
Ang total ay ang mas malamang na katotohanan. I-parse ang total ?? totalCount hanggang sa ito ay maayos.
| Patlang | Paglalarawan |
|---|---|
id | Panloob na post ID |
metaId | Panlabas na post / Reel / Story ID sa Meta |
text | Mag-post ng caption |
imageUrl | URL ng proxy media na naka-key ng hindi sequential MetaPost.Guid, o null |
platform | facebook o instagram |
mediaType | post, reel o story |
createdAt | Petsa ng paglikha (petsa ng platform, o petsa ng database) |
story | Ipakita lamang sa halagang mediaType: "story" |
story.id | Panloob na Story ID; katumbas ng post.id |
story.metaId | Panlabas na Story ID sa Meta |
story.url | Matatag na proxy URL ng nakaimbak na Story media; null kung hindi ma-save ang media |
Ang post media ay inihahatid sa pamamagitan ng dalawang ruta: GET /api/meta/post/media/{id:int} para sa paatras
compatibility at GET /api/meta/post/media/{guid:guid}. Mga bagong tugon at callback ng API
palaging bumuo ng GUID form.
5.2 Maglista ng mga komento
GET https://chatapi.smsbat.com/api/meta/comments?platform=instagram&postId=42&page=1&perPage=20
X-Authorization-Key: <token>
| Parameter | Uri | Kinakailangan | Paglalarawan |
|---|---|---|---|
page | int | hindi | Pahina, default 1 |
perPage | int | hindi | Mga item sa bawat pahina, default 20 |
postId | int | hindi | I-filter ayon sa post ID |
parentCommentId | int | hindi | Mga komento ng bata (mga tugon) ng isang ibinigay na komento |
platform | string | hindi | facebook o 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..."
}
}
]
}
| Patlang | Paglalarawan |
|---|---|
id | Panloob na comment ID |
metaId | Panlabas na ID sa Meta. null para sa nakabinbing tugon namin hanggang sa maipadala |
text | Teksto ng komento |
createdAt | Petsa ng paglikha |
platform | facebook o instagram |
replyStatus | null para sa isang papasok na komento ng user; "pending" / "sent" / "failure" para sa aming tugon |
author.type | "meta_user" panlabas na user, "owner" may-ari ng pahina |
author.name | Pangalan ng may-akda |
author.metaUserId | Saklaw na user ID sa Meta; null para sa "owner" |
post | Ang post, Reel o Story ang komento ay kay |
post.mediaType | post, reel o story |
post.story | Sanggunian ng kwento { id, metaId, url }, Mga Kuwento lamang |
mediaUrl | Media na naka-attach sa komento, o null |
replyTo | Komento ng magulang { id, metaId, text }; null sa pinakamataas na antas |
Pagkakaiba — uri ng `author.type`
Ang panloob na detalye ay nagdodokumento ng mga string "meta_user" / "owner". Mga tipong swagger
MetaCommentAuthorType bilang integer na may enum [0, 1]. A JsonStringEnumConverter
ipaliwanag ang agwat, ngunit hindi iyon nakumpirma laban sa isang tunay na tugon. Sumulat ng a
parser na tumatanggap ng pareho.
5.3 Tumugon sa isang komento
Nakapila ng tugon para sa paghahatid.
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"
katawan ng kahilingan: { "text": "Reply text" }
Ibinabalik ng 202 Accepted ang object ng komento — parehong hugis tulad ng GET /api/meta/comments — na may
replyStatus: "pending" at metaId: null. Ang resulta ng paghahatid ay darating mamaya bilang a
source: 13 callback (§6.4).
Pagkakaiba — response code
Ang swagger ay nagdeklara ng 200 na walang katawan; ang panloob na detalye ay nagpahayag ng 202 Accepted
na may komento bilang katawan. Ang controller ay malamang na walang ProducesResponseType
attribute, na iniiwan ang Swagger sa default nito. Tanggapin ang anumang 2xx at huwag umasa sa isang katawan.
6. Mga Webhook
Ang SMSBAT ay nagpapadala ng POST kahilingan na may application/json sa iyong URL at inaasahan ang HTTP 200 pabalik.
Ang mga null na field ay ganap na tinanggal
Ang isang field na ang value ay null ay hindi naka-serialize sa callback body. Para sa isang
mensaheng hindi nagmula sa Facebook o Instagram, walang MetaUserId key.
Tratuhin ang “absent” at null bilang parehong bagay.
6.1 Magrehistro ng 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
}'
| Patlang | Uri | Paglalarawan |
|---|---|---|
url | string | Ang iyong endpoint |
source | SendingSourceCallback | Uri ng kaganapan, tingnan ang §8.2 |
headerName / headerValue | string | Arbitrary na auth header na inilakip namin sa kahilingan (opsyonal) |
channelType | ChatSource | Channel. 7 para sa Instagram. Opsyonal |
channelEntityId | int | Isang partikular na account ng negosyo. Nangangailangan ng channelType |
Kung walang channelType nakakatanggap ang URL ng mga kaganapan mula sa bawat channel.
Tip
Ang buong saklaw ng komento ay nangangailangan ng dalawang pagpaparehistro: source: 12 para sa mga bagong komento at
source: 13 para sa mga status ng tugon. Para sa Direktang mga tugon at Kwento, idagdag ang source: 3
(at 11 kung gusto mo ang bawat mensahe sa chat).
Mga natitirang operasyon:
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 nagbabalik:
[
{
"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 Bagong mensahe at tugon sa Instagram Story (source: 3, 11)
Dumating ang tugon ng isang user sa isang Kuwento sa Instagram bilang isang ordinaryong mensahe sa mga callback na ito,
na may dagdag na top-level na Story block:
{
"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"
}
}
| Patlang | Paglalarawan |
|---|---|
ChatId / MessageId | Mga pagkakakilanlan ng chat at mensahe |
Author | 0 user, 1 operator |
Username | Instagram / Facebook display name o handle |
UserId | Panloob na numerong user ID sa SMSBAT |
MetaUserId | Saklaw na ID ng kasosyo sa pag-uusap sa Meta. Sa isang papalabas na mensahe ng operator, kinikilala pa rin nito ang Meta user ng chat, hindi ang operator |
ShopId | Panloob na ID ng Instagram / Facebook account ng negosyo |
ShopName | Pangalan ng account ng negosyo bilang natanggap mula sa Meta sa oras ng koneksyon |
MessageText | Teksto ng mensahe |
MessageMedia | URL ng media kapag ang mensahe ay media |
type_messenger | Pinagmulan, 7 para sa Instagram |
operator_name | Pangalan ng operator kapag Author = 1 |
Story | Ipakita lamang sa isang papasok na tugon sa Kwento |
Story.Id | Internal Story (MetaPost) ID — direktang magagamit bilang id / postId sa Meta API |
Story.MetaId | Panlabas na Story ID sa Meta |
Story.Url | Stable na proxy URL ng nakaimbak na Story media. Wala kapag hindi ma-save ang media — ang Story block at ang mensahe ay naihatid pa rin |
`Author` ay baligtad sa Chat API
Sa ChatMessageDTO.author, 0 ay nangangahulugang operator at 1 ay nangangahulugang kliyente. Sa callback na ito
sa kabilang banda: 0 ang user, 1 ang operator. Huwag ibahagi ang pagmamapa.
6.3 Bagong komento (source: 12)
Masisira kapag nagkomento ang isang user ng Meta sa isang post sa Facebook o isang post sa Instagram / Reel.
Note
Instagram Ang mga tugon sa kwento ay hindi inihahatid sa pamamagitan ng source: 12. Dumarating ang mga ito bilang karaniwan
mga papasok na mensahe sa source: 3 at/o 11 na may Story block — tingnan ang §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 Katayuan ng tugon sa komento (source: 13)
Magaganap pagkatapos naming subukang maghatid ng tugon, magtagumpay man ito o mabigo.
{
"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 Nakabahaging mga field ng callback ng komento
Ang parehong mga callback ng komento ay nagbabahagi isang hugis ng katawan at naiiba lang sa pamamagitan ng type.
| Patlang | Paglalarawan |
|---|---|
type | "new_comment" o "comment_status" |
platform | "facebook" o "instagram" |
comment.id | Panloob na comment ID |
comment.metaId | Panlabas na ID sa Meta; null para sa isang nakabinbing tugon bago ito ipadala |
comment.parentCommentId | ID ng komento ng magulang. Absent para sa isang top-level na komento |
comment.parentMetaId | External na parent comment ID. Wala sa pinakamataas na antas |
comment.parentCommentText | Text ng komento ng magulang. Wala sa pinakamataas na antas |
comment.text | Teksto ng komento |
comment.createdAt | Petsa ng paglikha |
comment.updatedAt | Huling update. Absent kung hindi kailanman na-edit ang komento |
comment.replyStatus | "pending" / "sent" / "failure". Absent para sa isang papasok na komento ng user |
comment.author.type | "meta_user" o "owner" |
comment.author.name | Pangalan ng may-akda |
comment.author.metaUserId | Saklaw na author ID sa Meta. Absent para sa "owner" |
comment.mediaUrl | Magkomento ng media. Absent kapag walang |
post.id | Panloob na post ID |
post.metaId | Panlabas na post / Reel / Story ID sa Meta |
post.text | Mag-post ng text |
post.imageUrl | Mag-post ng URL ng larawan, o null |
post.createdAt | Petsa ng paggawa ng post |
post.mediaType | Sa mga callback ng komento, post o reel lamang |
6.6 Bagong chat (source: 7)
{ "ChatId": 12345, "Phone": "+380501234567", "chat.Source": 7 }
6.7 Mga pagbabago sa status ng mensahe at chat (source: 6 / 5)
{ "name": "changed_message_status", "id": 9928, "status": 6 }
{ "name": "changed_chat_status", "id": 1867, "status": 4 }
6.8 Na-edit o tinanggal ang mensahe (source: 9)
{ "messageId": 9930, "text": "Updated message text" }
{ "messageId": 9931, "delete": true }
6.9 Tagapagpahiwatig ng pagta-type (source: 8)
{ "chat_id": 1867, "event": "start_typing", "operator_name": "Iryna" }
{ "chat_id": 1867, "event": "end_typing" }
7. Pagboto ng kaganapan
Para sa mga environment na hindi makakatanggap ng papasok na HTTP.
7.1 Kunin ang mga kaganapan
GET https://chatapi.smsbat.com/api/chat/callback-events?page=1&perPage=20
Authorization: Bearer <token>
| Parameter | Paglalarawan |
|---|---|
organizationId | Opsyonal. Kinuha mula sa token kapag tinanggal |
page / perPage | Pagbilang ng pahina, mga default 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"
}
]
}
Ang bawat kaganapan ay may event_guid, timestamp, organization_id at callback_type — isang
string na tumutugma sa source value sa §8.2. Ang natitirang mga patlang ay tumutugma sa katumbas
webhook sa §6.
7.2 Kilalanin ang mga naprosesong kaganapan
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 }
Ang mga kaganapang naalis na ay hindi binibilang sa deleted. Ang pag-order at muling pagsubok ay sa iyo
responsibilidad ng panig.
7.3 Inirerekomendang loop
- Poll
GET /api/chat/callback-eventssa isang iskedyul. - Iproseso ang mga kaganapan sa iyong serbisyo.
- Ipadala ang naprosesong
event_guidlistahan sa/callback-events/processed. - Ulitin.
8. Enum reference
8.1 ChatSource — channel (0–9)
| Code | Channel |
|---|---|
| 0 | Viber |
| 1 | ViberBot |
| 2 | TelegramBot |
| 3 | |
| 4 | Widget |
| 5 | Rozetka |
| 6 | |
| 7 | |
| 8 | Prom |
| 9 | Olx |
8.2 SendingSourceCallback — uri ng callback na kaganapan (0–13)
| Code | Kaganapan |
|---|---|
| 3 | Chat — bagong mensahe sa chat, kasama ang mga tugon sa Story |
| 5 | Binago ang status ng chat |
| 6 | Nabago ang status ng mensahe |
| 7 | Nagawa ang bagong chat |
| 8 | Tagapagpahiwatig ng pagta-type |
| 9 | Na-update o tinanggal ang mensahe |
| 11 | AnyChatMessage — anumang mensahe sa chat |
| 12 | MetaNewComment — bagong komento sa Instagram / Facebook |
| 13 | MetaCommentStatus — status ng paghahatid ng aming tugon sa komento |
Ang enum ay sumasaklaw sa 0–13; ang natitirang mga halaga ay hindi kailangan para sa mga pagsasama ng Instagram.
8.3 ChatStatus (0–4)
0 Bago, 1 Bukas, 2 Naghihintay, 3 Naka-onPause, 4 Sarado
8.4 MessageStatus (0–11)
| Code | Pangalan |
|---|---|
| 0 | BAGONG |
| 1 | TAGUMPAY |
| 2 | TINANGGIHAN |
| 3 | BASAHIN |
| 4 | HINDI ALAM |
| 5 | PAGPROSESO |
| 6 | INIHIGAY |
| 7 | BLOCKED_BY_USER |
| 8 | USER_NOT_FOUND |
Ang enum ay sumasaklaw sa 0–11. Ang mga value na 9, 10 at 11 ay umiiral sa API ngunit hindi pa nakadokumento —
ituring sila bilang UNKNOWN.
8.5 MediaType (1–10)
1 Larawan, 2 File, 3 Audio, 4 Video, 5 Sticker, 6 StickerAnimated,
7 StickerVideo, 8 Animation, 9 Boses, 10 VideoNote
8.6 AuthorMessage — may-akda sa Chat API (0–4)
0 Operator, 1 Kliyente, 2 Bot, 3 ViberAccount
Ang enum ay sumasaklaw sa 0–4; ang halagang 4 ay hindi dokumentado. Ang “bagong mensahe” na mga callback ay gumagamit ng
kabaligtaran ng pagmamapa — tingnan ang §6.2.
8.7 ChatMessageType (0–2)
0 Text, 1 Larawan, 2 File
8.8 Komento replyStatus
null papasok na komento ng user, "pending" ang aming tugon ay nakapila, "sent" naihatid,
"failure" nabigo ang paghahatid.
Bukas na mga tanong
Tatlong punto kung saan hindi sumasang-ayon ang panloob na detalye at ang code-generated na Swagger. Isa kahilingan na may isang tunay na token settles lahat ng mga ito; hanggang doon, isulat ang kliyente nang may pagtatanggol.
| # | Tanong | Pagtutukoy | Pagmamayabang | Paano suriin |
|---|---|---|---|---|
| 1 | Auth header para sa /api/meta/* | X-Authorization-Key | Bearer lang ang nagdeklara | curl -i -H "X-Authorization-Key: <token>" ".../api/meta/posts?perPage=1" — asahan ang 200, hindi 401 |
| 2 | Counter field sa mga tugon ng Meta | totalCount | total | Parehong kahilingan — basahin ang root JSON key |
| 3 | author.type uri at reply status code | "meta_user" / "owner", 202 na may katawan | int [0,1], 200 walang katawan | curl -i .../api/meta/comments?perPage=1 kasama ang isang pagsubok na tugon |
Pansamantalang patnubay:
- counter — basahin ang
total ?? totalCount; author.type— tanggapin ang parehong string at isang integer (0↔meta_user,1↔owner, pagma-map upang makumpirma);reply— ituring ang anumang2xxbilang tagumpay, hindi nangangailangan ng katawan, kunin ang huling katayuan mula sasource: 13callback.
Mga tala sa pagpapatupad
- Nag-iiba ang auth sa bawat endpoint group —
/api/meta/*gumagamit ngX-Authorization-Key, mga chat at ginagamit ng mga operator angBearer, tinatanggap ngrestapiang alinman. - Ang pagbilang ng pahina ay binabaybay ng dalawang paraan —
per_pagesa/api/chat/chats,perPagesa/api/meta/*at/api/chat/callback-events. multipart/form-datafield ay PascalCase na may dot notation (Media.File,Media.Type).- Ang mga null na field ay inalis sa mga callback — ang ibig sabihin ng absent key ay
null. - Ang
phoneay karaniwangnullsa Instagram. Kilalanin ang customer sa pamamagitan nginstagramUser.id/metaUserIdat ang tindahan nginstaAccount.id(angentityIdna halaga ng filter). Story.Idmula sa isang callback ay maaaring ipasa pabalik bilangid/postIdsa Meta API.- Suriin ang
expiresAtng operator na JWT bago ito gamitin sa isang deeplink o sa widget.