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
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
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.Recommended template
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.