Help Center Meta 与 Instagram API 集成

Meta 与 Instagram API 集成

在 SMSBAT ChatHub 平台 上构建 Instagram 应用的参考:身份验证、 Instagram Direct 对话、帖子和 Reels 下的评论、Story 回复、webhook 和轮询。

来源

本页合并了内部的 Meta Comments API 规范与 https://chatapi.smsbat.com/swagger/v1/swagger.json 和 https://restapi.smsbat.com/swagger/v1/swagger.json 上的在线 OpenAPI 定义。若两者不一致, 差异会在文中标出,并列在待解决问题中。


1. 基础 URL

用途URL
Chat API + Meta APIhttps://chatapi.smsbat.com
Swagger UI / OpenAPIhttps://chatapi.smsbat.com/index.html · …/swagger/v1/swagger.json
REST API(组织、回调 URL)https://restapi.smsbat.com
REST API Swaggerhttps://restapi.smsbat.com/swagger/v1/swagger.json
操作员网页面板https://chat.smsbat.com

2. 身份验证

身份验证方案取决于端点组。混用它们是导致 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 的组织令牌在面板的 Profile 下签发。 公司和操作员的 JWT 来自 /api/company/get-token 和 /api/operator/get-token。

差异

chatapi OpenAPI 文档只声明了一种安全方案 —— Bearer —— 并将其全局 应用。其中根本没有声明 X-Authorization-Key,尽管内部的 Meta Comments API 规范在 /api/meta/* 中提到了它。它很可能由 中间件处理,而这并未体现在 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. 指向聊天面板的深度链接

外部系统(CRM、ERP、网站)可以在 https://chat.smsbat.com/ 中打开特定对话。操作员通过作为查询参数传递的 JWT 获得授权。

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聊天来源 —— Instagram 为 7,见 §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/* 和轮询 端点下则为 perPage(camelCase)。这不是笔误 —— API 同时使用了两种写法。

查询参数,均为可选:

参数类型说明
sourceChatSource7 将结果限制为 Instagram
entityIdint商务账户 ID。仅与 source 一起使用时生效
instagram_user_idintChatHub 中的 Instagram 用户 ID
facebook_user_idintChatHub 中的 Facebook 用户 ID
page / per_pageint分页,默认值为 1 / 20
statusChatStatus[]聊天状态,可重复
searchstring自由文本搜索(姓名、手机号码等)
organizationIdint组织 ID
operatorIdint[]按已分配的操作员筛选
datestring[]两个边界值:?date=…&date=…
isChainbool以聊天链的形式返回聊天,并携带之前聊天中的消息
isUnread, starMark, isOperator, isAIAgentbool其他筛选条件
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 应用而言重要的字段:

字段含义
instaAccountInstagram 商务账户(店铺)。id 是 entityId 筛选值;name 是来自 Meta 的账户名称
instagramUser客户。name 是 Instagram 用户名,id 是 instagram_user_id 筛选值
metaUserId客户在 Meta 一侧的范围 ID(字符串)
messSourceInstagram 为 7
phone对 Instagram 通常为 null —— 请勿将其用作键

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
  }
]

当消息与 Instagram 帖子或 Story 相关时会填充 postId —— 请将其 直接作为 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
  }
}
字段类型说明
textMessagestring?消息文本。存在 media 时可为空
authorAuthorMessage?0 操作员,1 客户
isInternalbool?true 表示不会发送给客户的内部备注
replyToMessageIdint?所回复消息的 ID
appGuiduuid?推荐 GUID
mediaMediaDTO?{ 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 会被静默忽略。请使用下面的确切名称。

表单字段类型说明
TextMessagestring消息文本
Authorint0 操作员,1 客户
IsInternalbool内部备注
ReplyToMessageIdint所回复的消息
AppGuiduuid推荐 GUID
Media.Filebinary文件本身
Media.Namestring文件名
Media.FormatstringMIME 类型(video/mp4、image/png、application/pdf)
Media.TypeMediaType见 §8.5
Media.DataBase64stringMedia.File 的替代方式
Media.ThumbnailstringBase64 编码的视频预览帧
Media.Durationdouble视频时长(秒)
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>
参数类型必填说明
pageint否页码,默认为 1
perPageint否每页条目数,默认为 20
idint否按内部帖子 ID 筛选
platformstring否instagram 或 facebook
mediaTypestring否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
metaIdMeta 中的外部帖子/Reel/Story ID
text帖子说明文字
imageUrl以非顺序的 MetaPost.Guid 为键的代理媒体 URL,或 null
platformfacebook 或 instagram
mediaTypepost、reel 或 story
createdAt创建日期(平台日期或数据库日期)
story仅在 mediaType: "story" 时存在
story.id内部 Story ID;与 post.id 相同
story.metaIdMeta 中的外部 Story ID
story.url已存储 Story 媒体的稳定代理 URL;如果媒体无法保存,则为 null

帖子媒体通过两条路由提供:GET /api/meta/post/media/{id:int}(为向后 兼容而保留)和 GET /api/meta/post/media/{guid:guid}。新的 API 响应和回调 始终生成 GUID 形式。

5.2 评论列表

GET https://chatapi.smsbat.com/api/meta/comments?platform=instagram&postId=42&page=1&perPage=20
X-Authorization-Key: <token>
参数类型必填说明
pageint否页码,默认为 1
perPageint否每页条目数,默认为 20
postIdint否按帖子 ID 筛选
parentCommentIdint否指定评论的子评论(回复)
platformstring否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
metaIdMeta 中的外部 ID。对于我方尚未发送的待处理回复,为 null
text评论文本
createdAt创建日期
platformfacebook 或 instagram
replyStatus入站用户评论为 null;我方回复为 "pending" / "sent" / "failure"
author.type"meta_user" 外部用户,"owner" 主页所有者
author.name作者姓名
author.metaUserIdMeta 中的范围用户 ID;"owner" 时为 null
post评论所属的帖子、Reel 或 Story
post.mediaTypepost、reel 或 story
post.storyStory 引用 { id, metaId, url },仅限 Stories
mediaUrl评论附带的媒体,或 null
replyTo父评论 { id, metaId, text };顶层评论为 null

差异 —— `author.type` 的类型

内部规范记录的是字符串 "meta_user" / "owner"。Swagger 将 MetaCommentAuthorType 定义为枚举值为 [0, 1] 的整数。JsonStringEnumConverter 可以解释这一差异,但尚未对照真实响应加以确认。请编写一个 同时接受两种形式的解析器。

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。发送结果稍后会通过 source: 13 回调到达(§6.4)。

差异 —— 响应码

Swagger 声明为 200 且无响应体;内部规范声明为 202 Accepted, 并以评论作为响应体。控制器很可能缺少 ProducesResponseType 特性,因此 Swagger 采用了默认值。请接受任何 2xx 响应,且不要依赖响应体。


6. Webhook

SMSBAT 以 application/json 向您的 URL 发送 POST 请求,并期望收到 HTTP 200 响应。

空字段会被完全省略

值为 null 的字段根本不会被序列化到回调正文中。对于 并非来自 Facebook 或 Instagram 的消息,则根本没有 MetaUserId 键。 请将“缺失”和 null 视为同一回事。

6.1 注册回调 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
  }'
字段类型说明
urlstring您的端点
sourceSendingSourceCallback事件类型,见 §8.2
headerName / headerValuestring我们附加到请求上的任意身份验证请求头(可选)
channelTypeChatSource渠道。 Instagram 为 7。可选
channelEntityIdint特定的商务账户。需要 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 的回复会作为普通消息出现在这些回调中, 并带有一个额外的顶层 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聊天和消息标识符
Author0 用户,1 操作员
UsernameInstagram / Facebook 显示名称或用户名
UserIdSMSBAT 中的内部数字用户 ID
MetaUserId对话对方在 Meta 中的范围 ID。对于发出的操作员消息,它仍然标识该聊天中的 Meta 用户,而不是操作员
ShopIdInstagram / Facebook 商务账户的内部 ID
ShopName连接时从 Meta 收到的商家账号名称
MessageText消息文本
MessageMedia消息为媒体消息时的媒体 URL
type_messenger来源,Instagram 为 7
operator_name当 Author = 1 时的客服人员姓名
Story仅在收到 Story 回复的入站消息中出现
Story.Id内部 Story(MetaPost)ID — 可直接用作 Meta API 中的 id / postId
Story.MetaIdMeta 中的外部 Story ID
Story.Url已保存 Story 媒体的稳定代理 URL。媒体无法保存时不存在 — Story 块和消息仍会送达

`Author` 与 Chat API 中的含义相反

在 ChatMessageDTO.author 中,0 表示客服人员,1 表示客户。在此回调中则 相反:0 是用户,1 是客服人员。请勿共用同一套映射。

6.3 新评论(source: 12)

当 Meta 用户评论 Facebook 帖子或 Instagram 帖子 / Reel 时触发。

Note

Instagram Story 回复不会通过 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 评论回调的通用字段

两个评论回调共用同一种消息体结构,仅 type 不同。

字段说明
type"new_comment" 或 "comment_status"
platform"facebook" 或 "instagram"
comment.id内部评论 ID
comment.metaIdMeta 中的外部 ID;待发送的回复在发出前为 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.metaUserIdMeta 中作者的范围 ID。"owner" 时不存在
comment.mediaUrl评论媒体。没有时不存在
post.id内部帖子 ID
post.metaIdMeta 中的外部帖子 / Reel / Story ID
post.text帖子文本
post.imageUrl帖子图片 URL,或 null
post.createdAt帖子创建日期
post.mediaType在评论回调中,仅为 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. 事件轮询

适用于无法接收入站 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 — 后者是 与 §8.2 中 source 值对应的字符串。其余字段与 §6 中相应的 webhook 一致。

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 推荐的循环流程

  1. 按计划轮询 GET /api/chat/callback-events。
  2. 在您的服务中处理这些事件。
  3. 将已处理的 event_guid 列表发送到 /callback-events/processed。
  4. 重复上述步骤。

8. 枚举参考

8.1 ChatSource — 渠道(0–9)

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

8.2 SendingSourceCallback — 回调事件类型(0–13)

代码事件
3Chat — 新聊天消息,包括 Story 回复
5聊天状态已变更
6消息状态已变更
7已创建新聊天
8正在输入提示
9消息已更新或删除
11AnyChatMessage — 任意聊天消息
12MetaNewComment — Instagram / Facebook 新评论
13MetaCommentStatus — 我们的评论回复的送达状态

该枚举范围为 0–13;其余取值在 Instagram 集成中用不到。

8.3 ChatStatus (0–4)

0 New,1 Open,2 Waiting,3 OnPause,4 Closed

8.4 MessageStatus (0–11)

代码名称
0NEW
1SUCCESS
2REJECTED
3READ
4UNKNOWN
5PROCESSING
6DELIVERED
7BLOCKED_BY_USER
8USER_NOT_FOUND

该枚举范围为 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

该枚举范围为 0–4;值 4 没有文档说明。“新消息”回调使用 相反的映射 — 参见 §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仅声明了 Bearercurl -i -H "X-Authorization-Key: <token>" ".../api/meta/posts?perPage=1" — 应返回 200,而不是 401
2Meta 响应中的计数字段totalCounttotal同一请求 — 查看 JSON 根级键
3author.type 的类型以及 reply 的状态码"meta_user" / "owner",202 且带响应体int [0,1],200 且无响应体curl -i .../api/meta/comments?perPage=1 再加一次测试回复

临时建议:

  • 计数 — 读取 total ?? totalCount;
  • author.type — 同时接受字符串和整数(0 ↔ meta_user,1 ↔ owner,映射待确认);
  • reply — 将任何 2xx 视为成功,不要求有响应体,最终状态以 source: 13 回调为准。

实现说明

  • 不同端点组的认证方式不同 — /api/meta/* 使用 X-Authorization-Key,聊天和 客服人员接口使用 Bearer,restapi 两者均可。
  • 分页参数有两种写法 — /api/chat/chats 使用 per_page,而 perPage 用于 /api/meta/* 和 /api/chat/callback-events。
  • multipart/form-data 字段为 PascalCase,并使用点号表示法(Media.File、Media.Type)。
  • 回调中会省略值为 Null 的字段 — 键不存在即表示 null。
  • 在 Instagram 上 phone 通常为 null。请通过 instagramUser.id / metaUserId 识别客户,通过 instaAccount.id(即 entityId 过滤值)识别商家。
  • 回调中的 Story.Id 可以直接作为 id / postId 传回 Meta API。
  • 在深度链接或小部件中使用客服人员 JWT 之前,请先检查其 expiresAt。