Help Center Pagsasama ng Meta at Instagram API

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

LayuninURL
Chat API + Meta APIhttps://chatapi.smsbat.com
Swagger UI / OpenAPIhttps://chatapi.smsbat.com/index.html · …/swagger/v1/swagger.json
REST API (mga organisasyon, mga callback URL)https://restapi.smsbat.com
REST API Swaggerhttps://restapi.smsbat.com/swagger/v1/swagger.json
Operator web panelhttps://chat.smsbat.com

2. Pagpapatunay

Ang auth scheme depende sa endpoint group. Ang paghahalo sa kanila ay ang pinakakaraniwang sanhi ng 401.

PangkatHeader
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>

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>
ParameterPaglalarawan
chat_raw_idChat ID
phoneNumero ng telepono sa internasyonal na format
fromIdentifier ng brand / account ng negosyo (bm_id)
sourcePinagmulan ng chat — 7 para sa Instagram, tingnan ang §8.1
tokenWasto, 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:

ParameterUriPaglalarawan
sourceChatSource7 nililimitahan ang mga resulta sa Instagram
entityIdintBusiness account ID. Inilapat lamang kasama ng source
instagram_user_idintInstagram user ID sa ChatHub
facebook_user_idintFacebook user ID sa ChatHub
page / per_pageintPagbilang ng pahina, mga default 1 / 20
statusChatStatus[]Katayuan ng chat, nauulit
searchstringLibreng-text na paghahanap (pangalan, telepono, …)
organizationIdintOrganization ID
operatorIdint[]I-filter ayon sa mga nakatalagang operator
datestring[]Dalawang hangganan: ?date=…&date=…
isChainboolIbalik ang mga chat bilang mga chain, nagdadala ng mga mensahe mula sa mga nakaraang chat
isUnread, starMark, isOperator, isAIAgentboolMga 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:

PatlangIbig sabihin
instaAccountAng Instagram business account (ang tindahan). Ang id ay ang entityId na halaga ng filter; Ang name ay ang pangalan ng account mula sa Meta
instagramUserAng customer. Ang name ay ang Instagram handle, ang id ay ang instagram_user_id filter value
metaUserIdAng saklaw na ID ng customer sa gilid ng Meta (string)
messSource7 para sa Instagram
phoneKaraniwan 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
  }
}
PatlangUriPaglalarawan
textMessagestring?Text ng mensahe. Maaaring walang laman kapag naroroon ang media
authorAuthorMessage?0 operator, 1 kliyente
isInternalbool?Ang true ay nagmamarka ng panloob na tala na hindi naihatid sa customer
replyToMessageIdint?ID ng mensaheng sinasagot sa
appGuiduuid?Referral GUID
mediaMediaDTO?{ 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 formUriPaglalarawan
TextMessagestringTeksto ng mensahe
Authorint0 operator, 1 kliyente
IsInternalboolPanloob na tala
ReplyToMessageIdintSinasagot ang mensahe sa
AppGuiduuidReferral GUID
Media.FilebinaryAng file mismo
Media.NamestringPangalan ng file
Media.FormatstringUri ng MIME (video/mp4, image/png, application/pdf)
Media.TypeMediaTypeTingnan ang §8.5
Media.DataBase64stringAlternatibo sa Media.File
Media.ThumbnailstringBase64 video preview frame
Media.DurationdoubleTagal 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>
ParameterUriKinakailanganPaglalarawan
pageinthindiPahina, default 1
perPageinthindiMga item sa bawat pahina, default 20
idinthindiI-filter ayon sa panloob na post ID
platformstringhindiinstagram o facebook
mediaTypestringhindipost, 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.

PatlangPaglalarawan
idPanloob na post ID
metaIdPanlabas na post / Reel / Story ID sa Meta
textMag-post ng caption
imageUrlURL ng proxy media na naka-key ng hindi sequential MetaPost.Guid, o null
platformfacebook o instagram
mediaTypepost, reel o story
createdAtPetsa ng paglikha (petsa ng platform, o petsa ng database)
storyIpakita lamang sa halagang mediaType: "story"
story.idPanloob na Story ID; katumbas ng post.id
story.metaIdPanlabas na Story ID sa Meta
story.urlMatatag 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>
ParameterUriKinakailanganPaglalarawan
pageinthindiPahina, default 1
perPageinthindiMga item sa bawat pahina, default 20
postIdinthindiI-filter ayon sa post ID
parentCommentIdinthindiMga komento ng bata (mga tugon) ng isang ibinigay na komento
platformstringhindifacebook 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..."
      }
    }
  ]
}
PatlangPaglalarawan
idPanloob na comment ID
metaIdPanlabas na ID sa Meta. null para sa nakabinbing tugon namin hanggang sa maipadala
textTeksto ng komento
createdAtPetsa ng paglikha
platformfacebook o instagram
replyStatusnull 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.namePangalan ng may-akda
author.metaUserIdSaklaw na user ID sa Meta; null para sa "owner"
postAng post, Reel o Story ang komento ay kay
post.mediaTypepost, reel o story
post.storySanggunian ng kwento { id, metaId, url }, Mga Kuwento lamang
mediaUrlMedia na naka-attach sa komento, o null
replyToKomento 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
  }'
PatlangUriPaglalarawan
urlstringAng iyong endpoint
sourceSendingSourceCallbackUri ng kaganapan, tingnan ang §8.2
headerName / headerValuestringArbitrary na auth header na inilakip namin sa kahilingan (opsyonal)
channelTypeChatSourceChannel. 7 para sa Instagram. Opsyonal
channelEntityIdintIsang 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"
  }
}
PatlangPaglalarawan
ChatId / MessageIdMga pagkakakilanlan ng chat at mensahe
Author0 user, 1 operator
UsernameInstagram / Facebook display name o handle
UserIdPanloob na numerong user ID sa SMSBAT
MetaUserIdSaklaw 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
ShopIdPanloob na ID ng Instagram / Facebook account ng negosyo
ShopNamePangalan ng account ng negosyo bilang natanggap mula sa Meta sa oras ng koneksyon
MessageTextTeksto ng mensahe
MessageMediaURL ng media kapag ang mensahe ay media
type_messengerPinagmulan, 7 para sa Instagram
operator_namePangalan ng operator kapag Author = 1
StoryIpakita lamang sa isang papasok na tugon sa Kwento
Story.IdInternal Story (MetaPost) ID — direktang magagamit bilang id / postId sa Meta API
Story.MetaIdPanlabas na Story ID sa Meta
Story.UrlStable 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.

PatlangPaglalarawan
type"new_comment" o "comment_status"
platform"facebook" o "instagram"
comment.idPanloob na comment ID
comment.metaIdPanlabas na ID sa Meta; null para sa isang nakabinbing tugon bago ito ipadala
comment.parentCommentIdID ng komento ng magulang. Absent para sa isang top-level na komento
comment.parentMetaIdExternal na parent comment ID. Wala sa pinakamataas na antas
comment.parentCommentTextText ng komento ng magulang. Wala sa pinakamataas na antas
comment.textTeksto ng komento
comment.createdAtPetsa ng paglikha
comment.updatedAtHuling 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.namePangalan ng may-akda
comment.author.metaUserIdSaklaw na author ID sa Meta. Absent para sa "owner"
comment.mediaUrlMagkomento ng media. Absent kapag walang
post.idPanloob na post ID
post.metaIdPanlabas na post / Reel / Story ID sa Meta
post.textMag-post ng text
post.imageUrlMag-post ng URL ng larawan, o null
post.createdAtPetsa ng paggawa ng post
post.mediaTypeSa 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>
ParameterPaglalarawan
organizationIdOpsyonal. Kinuha mula sa token kapag tinanggal
page / perPagePagbilang 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

  1. Poll GET /api/chat/callback-events sa isang iskedyul.
  2. Iproseso ang mga kaganapan sa iyong serbisyo.
  3. Ipadala ang naprosesong event_guid listahan sa /callback-events/processed.
  4. Ulitin.

8. Enum reference

8.1 ChatSource — channel (0–9)

CodeChannel
0Viber
1ViberBot
2TelegramBot
3Whatsapp
4Widget
5Rozetka
6Facebook
7Instagram
8Prom
9Olx

8.2 SendingSourceCallback — uri ng callback na kaganapan (0–13)

CodeKaganapan
3Chat — bagong mensahe sa chat, kasama ang mga tugon sa Story
5Binago ang status ng chat
6Nabago ang status ng mensahe
7Nagawa ang bagong chat
8Tagapagpahiwatig ng pagta-type
9Na-update o tinanggal ang mensahe
11AnyChatMessage — anumang mensahe sa chat
12MetaNewComment — bagong komento sa Instagram / Facebook
13MetaCommentStatus — 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)

CodePangalan
0BAGONG
1TAGUMPAY
2TINANGGIHAN
3BASAHIN
4HINDI ALAM
5PAGPROSESO
6INIHIGAY
7BLOCKED_BY_USER
8USER_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.

#TanongPagtutukoyPagmamayabangPaano suriin
1Auth header para sa /api/meta/*X-Authorization-KeyBearer lang ang nagdeklaracurl -i -H "X-Authorization-Key: <token>" ".../api/meta/posts?perPage=1" — asahan ang 200, hindi 401
2Counter field sa mga tugon ng MetatotalCounttotalParehong kahilingan — basahin ang root JSON key
3author.type uri at reply status code"meta_user" / "owner", 202 na may katawanint [0,1], 200 walang katawancurl -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 anumang 2xx bilang tagumpay, hindi nangangailangan ng katawan, kunin ang huling katayuan mula sa source: 13 callback.

Mga tala sa pagpapatupad

  • Nag-iiba ang auth sa bawat endpoint group — /api/meta/* gumagamit ng X-Authorization-Key, mga chat at ginagamit ng mga operator ang Bearer, tinatanggap ng restapi ang alinman.
  • Ang pagbilang ng pahina ay binabaybay ng dalawang paraan — per_page sa /api/chat/chats, perPage sa /api/meta/* at /api/chat/callback-events.
  • multipart/form-data field 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 phone ay karaniwang null sa Instagram. Kilalanin ang customer sa pamamagitan ng instagramUser.id / metaUserId at ang tindahan ng instaAccount.id (ang entityId na halaga ng filter).
  • Story.Id mula sa isang callback ay maaaring ipasa pabalik bilang id / postId sa Meta API.
  • Suriin ang expiresAt ng operator na JWT bago ito gamitin sa isang deeplink o sa widget.