Help Center 运营商授权和深度链接

运营商授权和深度链接

本指南说明如何通过 API 为系统中的运营商获取有效的授权令牌,以及如何使用深度链接导航至聊天面板。

API 基础 URL: https://chatapi.smsbat.com/ Swagger: https://chatapi.smsbat.com/index.html

注意:您可以使用 X-Authorization-Key 头部并携带您的令牌(可在仪表板的个人资料中获取),而不是 Bearer 授权,以进行公司级请求。


1. 获取公司令牌

要获取公司令牌,请发送 HTTP POST 请求至 /api/company/get-token,并在其中包含公司的登录凭证。

请求

  • 方法: POST
  • URL: https://chatapi.smsbat.com/api/company/get-token
  • 头部: Content-Type: application/json

主体:

{
  "login": "string",
  "password": "string"
}

响应

  • 状态码: 200 (OK)
  • 主体: 字符串令牌 ("your_token_string")

注意: 保存收到的令牌以供后续请求使用。


2. 检索组织列表

使用公司令牌发送 GET 请求至 /api/company/organization,以列出您的组织。

请求

  • 方法: GET
  • URL: https://chatapi.smsbat.com/api/company/organization
  • 请求头:
    • Authorization: Bearer {token}
    • Accept: text/plain

响应

  • 状态码: 200 (OK)
  • 正文:
[
  {
    "id": 6,
    "name": "string"
  }
]

3. 按组织检索运营商

使用 organizationId 参数发送 GET 请求至 /api/operator。

请求

  • 方法: GET
  • URL: https://chatapi.smsbat.com/api/operator?organizationId={id}
  • 请求头:
    • Authorization: Bearer {token}
    • Accept: text/plain

响应

  • 状态码: 200 (OK)
  • 正文:
[
  {
    "id": 21,
    "name": "string",
    "status": 1,
    "organization": {
      "id": 24,
      "name": "test_costs"
    }
  }
]

4. 将运营商添加到系统

使用公司令牌访问此端点并将运营商同步到系统。

请求

  • 方法: POST
  • URL: https://chatapi.smsbat.com/api/operator/synchronize
  • 请求头:
    • Authorization: Bearer {token}
    • Content-Type: application/json

正文:

[
  {
    "organizationId": 24,
    "name": "string"
  }
]

响应

  • 状态码: 200 (OK)
  • 正文:
[
  {
    "id": 21,
    "status": 0,
    "name": "string"
  }
]

可能的运营商状态:

  • 活动: 0
  • 非活动: 1
  • 已删除: 2

5. 获取运营商令牌

使用公司令牌授权以获取特定运营商的令牌。

请求

  • 方法: POST
  • URL: https://chatapi.smsbat.com/api/operator/get-token
  • 请求头:
    • Authorization: Bearer {token}
    • Content-Type: application/json

正文:

{
  "id": 0,
  "expiresAt": "2025-01-20T14:33:34.147Z"
}

expiresAt 为必填项,决定运营商的会话时长(最大 +24 hours)。

响应

  • 状态码: 200 (OK)
  • 正文: String token

6. 验证运营商令牌

验证运营商令牌的有效性。

请求

  • 方法: POST
  • URL: https://chatapi.smsbat.com/api/operator/validate-token
  • 请求头:
    • Authorization: Bearer {token}
    • Content-Type: application/json

正文: "operator_token_string"

有效响应 (200 OK):

{
  "isValid": true,
  "operatorId": 0,
  "clientId": 0,
  "expiresAt": "2024-12-28T14:04:15.861Z",
  "error": null
}

7. 深度链接至运营商聊天面板

外部系统(CRM、ERP、内部网站)可以通过传递 JWT 运营商令牌作为参数,利用深度链接直接打开聊天面板。 如果令牌无效或已过期,用户将被重定向到登录界面。

格式 1:按聊天 ID

https://chat.smsbat.com/?chat_raw_id=<chat_id>&token=<jwt_token>

格式 2:按电话号码

https://chat.smsbat.com/?phone=<phone_number>&token=<jwt_token>

电话号码必须采用 E.164 国际格式。

格式 3:按字母名称和电话

https://chat.smsbat.com/?from=<bm_id>&phone=<phone_number>&token=<jwt_token>

格式 4:完整目标详情

准确指定要拦截消息的来源:

https://chat.smsbat.com/?source=<sourceId>&from=<bm_id>&phone=<phone_number>&token=<jwt_token>

聊天来源:

  • 0 - Viber
  • 1 - ViberBot
  • 2 - TelegramBot
  • 3 - Whatsapp
  • 4 - 小部件
  • 5 - Rozetka
  • 6 - Facebook
  • 7 - Instagram