Skip to main content
plugin/scripts/middleware.js is the SDK for regular JavaScript plugins. Use it to create Sender, then read the current runtime context, reply to messages, save data, wait for input, handle payments, download user-uploaded files, handle HTTP routes, push proactively, and manage runtime scheduled tasks.
New plugins should prefer const { Sender, getSenderID } = require('./middleware.js'). Do not hard-code runtime credentials, ports, or autClaw internal service addresses.

Quick start

//[author: your-name]
//[runtime: [email protected]]
//[title: Echo]
//[rule: echo (.+)]
const { Sender, getSenderID } = require('./middleware.js')

async function main() {
  const sender = new Sender(getSenderID())
  const text = await sender.param(1)
  await sender.reply(text || 'Please enter text')
}

main().catch((error) => {
  console.error(error && error.stack ? error.stack : error)
})

Browse by task

Context and base types

Import style, senderID, response wrappers, SendReceipt, MediaItem, and download return bodies.

Sender message capabilities

Read users and chats, match parameters, reply with text/media, recall, and use replyMixed(...).

Wait for input and payment

listen(...), input(...), waitPay(exitcode, timeout, amount?), and amount-matching details.

Events, media, and files

getMediaItems(), fileDownload(...), downloadAdapterFile(...), and getGroupMemberList(...).

Storage and routes

Default storage, named buckets, and HTTP router requests and responses.

Proactive push

Targets, account selection, and return values for push(...) / pushImage(...) / pushMixed(...).

Tools, Cron, and group management

importModule(...), importJs(...), system utilities, Cron, group invite/mute/announcement.

TypeScript declarations

Machine-readable signatures are available in en/plugin-sdk/types/middleware-js.d.ts for IDEs and AI retrieval.

Common imports

const {
  Sender,
  Cron,
  getSenderID,
  bucketGet,
  bucketSet,
  fileDownload,
  downloadAdapterFile,
  getGroupMemberList,
  importModule,
  push,
  pushImage,
  pushMixed,
} = require('./middleware.js')

const sender = new Sender(getSenderID())
Most methods in middleware.js are asynchronous and throw Error on failure. Use try/catch in flows that send network requests, media, or files, and reply with an actionable error message.
//[author: your-name]
//[runtime: [email protected]]
//[title: Safe template]
//[rule: demo (.+)]
const { Sender, getSenderID } = require('./middleware.js')

async function main() {
  const sender = new Sender(getSenderID())
  const value = await sender.param(1)

  if (!value) {
    await sender.reply('Please enter text, for example: demo hello')
    return
  }

  await sender.reply(`Received: ${value}`)
}

main().catch((error) => {
  console.error(error && error.stack ? error.stack : error)
})

Avoid these patterns

  • Do not hard-code runtime credentials, ports, or service addresses.
  • Do not bypass the SDK to call autClaw services directly.
  • Do not manually parse platform raw file fields. Use SDK download helpers.
  • Do not put large datasets into one bucket key. Split data across keys for easier maintenance.

JavaScript plugin context and types

Understand the Sender runtime context, senderID, response wrappers, SendReceipt, FileDownloadResult, and MediaItem in JavaScript plugins.

JavaScript Sender message capabilities

Use JavaScript Sender methods to read users and chats, match parameters, reply with text or media, send mixed messages, and recall messages.

JavaScript wait for input and payment

Use listen, input, and waitPay in JavaScript plugins to wait for user input, capture media, and handle payment amount matching.

JavaScript events, media, and files

Read event data, get media items, download user-uploaded files, and fetch group member lists in JavaScript plugins.

JavaScript plugin storage and routes

Use default storage, named buckets, and HTTP router request and response helpers in autClaw JavaScript plugins.

JavaScript plugin proactive push

Use JavaScript push, pushImage, and pushMixed to proactively send text, media, and mixed messages while controlling the sending account.

JavaScript tools, Cron, and groups

Use importModule, importJs, system utilities, Cron scheduled tasks, and group management methods in JavaScript plugins.
Last modified on June 3, 2026