SDK
Node.js SDK
Official @starim-io/bot-sdk: high-level StarIMBot + low-level StarIMBotClient. Parameter details live in the API index.
Install
pnpm add @starim-io/bot-sdk
Node.js ≥ 18. Legacy @sochatlive/bot-sdk is unmaintained.
Env
| Var | Meaning |
|---|---|
SOCHAT_BOT_TOKEN | sbot_… after approval |
SOCHAT_API_BASE | Gateway prefix, must include /api/v1 |
SOCHAT_WEBHOOK_SECRET | Same as setWebhook.secret_token |
Quick echo (polling)
import { StarIMBot } from '@starim-io/bot-sdk'
const bot = new StarIMBot({
token: process.env.SOCHAT_BOT_TOKEN!,
baseUrl: process.env.SOCHAT_API_BASE!,
secretToken: process.env.SOCHAT_WEBHOOK_SECRET,
})
bot.command('start', (ctx) => ctx.reply('hi'))
bot.on('message', async (ctx) => {
const text = ctx.message?.text
if (text) await ctx.reply(text, { quote: true })
})
await bot.startPolling()
Two layers
- StarIMBot: events,
start/startPolling,ctx.reply. - StarIMBotClient (
bot.client): direct/api/v1/bots/**calls.
const client = bot.client
await client.sendMessage({ chat_id: '<id>', text: 'hello' })
await client.sendPhotoFromFile('<chat_id>', './photo.jpg', { caption: 'cap' })
Examples (same as repo — runnable)
Sources under botsdk/nodejs/examples/.
export STARIM_API_BASE="https://<api-host>/api/v1"
export STARIM_BOT_TOKEN="sbot_..."
export STARIM_WEBHOOK_SECRET="same as setWebhook"
npx tsx examples/echo-bot.ts
npx tsx examples/slash-command.ts
STARIM_CHAT_ID=<id> npx tsx examples/send-photo.ts ./photo.png
Echo (webhook)
bot.on('message', async (ctx) => {
const t = ctx.message.text?.trim()
if (t) await ctx.reply(t)
})
await bot.start({ port: 8787, path: '/webhook' })
Slash commands
bot.command('start', (ctx) => ctx.reply('Welcome'))
bot.command('help', (ctx) => ctx.reply('/start /help'))
await bot.start({ port: 8788, path: '/webhook' })
Send local photo
await client.sendPhotoFromFile(process.env.STARIM_CHAT_ID!, './photo.png', {
caption: 'from @starim-io/bot-sdk',
})
Polling (no public URL)
await bot.startPolling()
Method map
| Area | SDK | Docs |
|---|---|---|
| Send | sendMessage, sendPhotoFromFile, … | Send |
| Webhook / poll | setWebhook, getUpdates, startPolling | Webhook |
| Chats | getMyChats, getChat*, pin/forward | Chat read |
| Orchestration | simulateSendMessage | Guide |
Full HTTP contract: API index.
MediaUploadCache is deprecated/no-op—use server checksum reuse.Quickstart · botsdk/nodejs/examples/ · package README.
