Skip to content

Configuration

WeixinBot Options

ts
import { WeixinBot } from '@weixin-ts/bot'

const bot = new WeixinBot({
  // Bot token (can be obtained via login())
  token: 'YOUR_TOKEN',

  // API base URL (usually no need to change)
  baseUrl: 'https://ilinkai.weixin.qq.com',

  // CDN base URL (media upload/download)
  cdnBaseUrl: 'https://novac2c.cdn.weixin.qq.com/c2c',

  // iLink App ID
  appId: 'bot',

  // Client version
  version: '1.0.0',

  // Long-poll timeout (ms)
  longPollTimeoutMs: 35000,

  // Normal API request timeout (ms)
  apiTimeoutMs: 15000,
})

Options Reference

OptionTypeDefaultDescription
tokenstringBot token (can be obtained via login())
baseUrlstringhttps://ilinkai.weixin.qq.comAPI base URL
cdnBaseUrlstringhttps://novac2c.cdn.weixin.qq.com/c2cCDN base URL
appIdstring'bot'iLink App ID
versionstringSDK versionClient version
longPollTimeoutMsnumber35000Long-poll timeout
apiTimeoutMsnumber15000Normal request timeout
sessionSessionStorageSession storage backend. Use fileSession(path) from @weixin-ts/bot/node for file storage.

Login Callbacks

ts
const result = await bot.login({
  // Called when QR code is ready; display the URL wherever you like
  onQrCode: url => console.log('Scan:', url),

  // User scanned, waiting for confirmation in WeChat
  onScanned: () => console.log('Confirm in WeChat...'),

  // QR code expired and auto-refreshed
  onQrRefresh: url => console.log('QR refreshed:', url),
})

if (!result.success)
  throw new Error(result.message)

For more control over login timeout, polling interval, or bot type, use the low-level requestQRCode().

Events

EventPayloadDescription
messageWeixinMessageNew message received
errorErrorPolling error (non-fatal, auto-retries)
connectedPolling started
disconnectedPolling stopped
session:expiredSession expired (errcode -14); local session file is deleted automatically when session is configured

Message Types

TypeValueConstant
Text1MessageItemType.TEXT
Image2MessageItemType.IMAGE
Voice3MessageItemType.VOICE
File4MessageItemType.FILE
Video5MessageItemType.VIDEO

Released under the MIT License.