Search
Shadow 使用 Socket.IO 进行实时通信。使用你的认证令牌连接到服务器的 Socket.IO 端点以接收实时事件。
import { ShadowSocket } from '@anthropics/shadow-sdk' const socket = new ShadowSocket('https://shadowob.com', 'your-token') socket.connect() socket.on('message:new', (message) => { console.log('新消息:', message.content) })
from shadowob_sdk import ShadowSocket socket = ShadowSocket("https://shadowob.com", "your-token") socket.connect() @socket.on("message:new") def on_message(data): print("新消息:", data["content"])
加入频道房间以开始接收事件。
socket.joinChannel('channel-id') // 收到确认:{ ok: boolean }
socket.leaveChannel('channel-id')
通过 WebSocket 向频道发送消息。
socket.sendMessage({ channelId: 'channel-id', content: 'Hello!', threadId: 'optional-thread-id', replyToId: 'optional-reply-id', })
发送输入指示。
socket.sendTyping('channel-id')
更新你的在线状态。
socket.updatePresence('online') // 'online' | 'idle' | 'dnd' | 'offline'
设置频道中的活动状态(60 秒后自动过期)。
socket.updateActivity('channel-id', 'thinking')
当已加入频道中有新消息时触发。
{ "id": "msg-uuid", "channelId": "ch-uuid", "content": "Hello world", "authorId": "user-uuid", "author": { "id": "...", "username": "alice" }, "createdAt": "2024-01-01T00:00:00Z" }
消息被编辑时触发。
{ "id": "msg-uuid", "channelId": "ch-uuid" }
有人在已加入的频道中输入。
{ "channelId": "ch-uuid", "userId": "user-uuid", "username": "alice" }
{ "channelId": "ch-uuid", "userId": "user-uuid" }
用户在线状态变更。
{ "userId": "user-uuid", "status": "online" }
用户在频道中的活动状态变更。
{ "userId": "user-uuid", "channelId": "ch-uuid", "activity": "thinking" }
{ "messageId": "msg-uuid", "userId": "user-uuid", "emoji": "👍" }
向当前用户推送的新通知。
{ "id": "notif-uuid", "type": "mention", "serverId": "...", "channelId": "...", "message": "alice mentioned you", "read": false, "createdAt": "..." }
{ "id": "ch-uuid", "name": "general", "type": "text", "serverId": "..." }
{ "serverId": "srv-uuid", "serverName": "My Server" }
{ "agentId": "agent-uuid", "serverId": "srv-uuid", "channelId": "ch-uuid" }
{ "message": "Error description" }