连接说明

WebSocket地址:wss://ai.yinghetwbot.com/ws/{token}

将您的 token 拼接在URL末尾即可建立连接,连接成功后会实时推送您监控列表中的变更信息。

Token 可在主页查看,请妥善保管不要泄露给他人。

连接示例

// JavaScript const ws = new WebSocket("wss://ai.yinghetwbot.com/ws/你的token"); ws.onopen = function() { console.log("连接成功"); }; ws.onmessage = function(event) { const data = JSON.parse(event.data); console.log("收到推送:", data); console.log("推送类型:", data.ts_type); }; ws.onclose = function() { console.log("连接断开"); };
# Python import websockets import asyncio import json async def listen(): uri = "wss://ai.yinghetwbot.com/ws/你的token" async with websockets.connect(uri) as ws: while True: msg = await ws.recv() data = json.loads(msg) print(f"推送类型: {data['ts_type']}") print(f"数据: {data}") asyncio.run(listen())

推送类型总览

所有推送消息中均包含 ts_type 字段,用于区分推送类型:

ts_type 值推送类型说明
tw新增推文监控用户发布了新推文
description描述更改监控用户修改了个人描述/简介
profile_image_url头像更改监控用户更换了头像
name名称修改监控用户修改了显示名称
profile_banner_urlBanner更改监控用户更换了横幅图片
followers新增关注监控用户的关注列表发生变化

格式一:推文与资料变更推送

以下推送类型使用相同的数据格式:

  • tw 新增推文
  • description 描述更改
  • profile_image_url 头像更改
  • name 名称修改
  • profile_banner_url Banner更改

推送示例(新增推文 ts_type=tw)

{ "ts_type": "tw", ... }

推送示例(描述更改 ts_type=description)

{ "ts_type": "description", ... }

推送示例(头像更改 ts_type=profile_image_url)

{ "ts_type": "profile_image_url", ... }

推送示例(名称修改 ts_type=name)

{ "ts_type": "name", ... }

推送示例(Banner更改 ts_type=profile_banner_url)

{ "ts_type": "profile_banner_url", ... }
以上五种推送的数据结构相同,通过 ts_type 字段区分具体变更类型。

格式二:关注列表变更推送

followers 当监控用户的关注列表发生变化时推送。

推送示例

{ "ts_type": "followers", ... }

处理建议

  • 建议根据 ts_type 字段做分类处理
  • 建议实现自动重连机制,在连接断开时自动重新连接
  • 推送数据为 JSON 格式,使用 JSON.parse() 解析

分类处理示例

ws.onmessage = function(event) { const data = JSON.parse(event.data); switch(data.ts_type) { case "tw": console.log("新推文:", data); break; case "description": console.log("描述更改:", data); break; case "profile_image_url": console.log("头像更改:", data); break; case "name": console.log("名称修改:", data); break; case "profile_banner_url": console.log("Banner更改:", data); break; case "followers": console.log("关注列表变更:", data); break; } };