@the-next-ai/bot-gateway-sdk
v0.1.0
Published
Node.js SDK for Bot Gateway external agents.
Readme
Bot Gateway Node SDK
import { createBotGatewayClient, BotGatewayWebSocketClient } from '@the-next-ai/bot-gateway-sdk';
const client = createBotGatewayClient({
transport: 'http',
baseUrl: 'http://127.0.0.1:3000',
});
await client.handleNextEvent(async (queued, gateway) => {
const text = queued.event.message?.text ?? '';
await gateway.sendText({
tenantId: queued.event.tenantId,
integrationId: queued.event.integrationId,
conversationRef: {
platformConversationId: queued.event.conversation.id,
type: queued.event.conversation.type,
},
text: `Echo: ${text}`,
});
});
const ws = new BotGatewayWebSocketClient({ baseUrl: 'http://127.0.0.1:3000' });
await ws.subscribeEvents(async (queued) => {
await ws.send({
tenantId: queued.event.tenantId,
integrationId: queued.event.integrationId,
conversationRef: {
platformConversationId: queued.event.conversation.id,
type: queued.event.conversation.type,
},
intent: { type: 'text', text: 'handled over websocket' },
});
await ws.ackEvent(queued.id);
});统一 transport 入口:
const http = createBotGatewayClient({ transport: 'http', baseUrl: 'http://127.0.0.1:3000' });
const websocket = createBotGatewayClient({ transport: 'websocket', baseUrl: 'http://127.0.0.1:3000' });
const stdio = createBotGatewayClient({ transport: 'stdio' });
await stdio.health();
await stdio.close?.();The npm package includes bin/bot-gateway-stdio.mjs and exposes a bot-gateway-stdio executable. The stdio client uses that bundled runner by default.
Install from npm:
npm install @the-next-ai/bot-gateway-sdkLocal Weixin iLink playground
From the repository root:
npm run playground:replThe playground builds and imports this Node SDK, then starts a command shell:
auth
connect
sendmessage 你好
sendstream --chunk-size 8 --delay 250 这是一段流式回复
sendfile /absolute/path/report.pdf 这是附件After connect, incoming Weixin iLink user messages are printed automatically. sendmessage,
sendstream, and sendfile reply to the latest incoming message unless you pass --to <userId>.
For manual stream control, use sendstream start <text>, sendstream update <delta>, and
sendstream end <delta>; pass --replace to send a full snapshot instead of appending.
