plugin/scripts/middleware.py is the SDK for regular Python plugins. Use it to create Sender, read the current context, reply to messages, store data, wait for input, handle payments, download user-uploaded files, handle HTTP routes, push proactively, and manage runtime scheduled tasks.
New plugins should prefer
from middleware import Sender, getSenderID. Do not hard-code credentials, ports, or autClaw internal service addresses.Quick start
Exception; catch exceptions in flows that send network requests, media, or files, and reply with an actionable message.
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=None), and amount-matching details.Events, media, and files
getMediaItems(), fileDownload(...), downloadAdapterFile(...), and getGroupMemberList(...).Storage and routes
Default storage, named buckets, and HTTP router request and response aliases.
Proactive push
Targets, account selection, and return values for
push(...) / pushImage(...) / pushMixed(...).Tools, Cron, and group management
import_module(...), system utilities, Cron, group invite/mute/announcement.Python signatures
Navigation-indexed
.pyi-style signatures for IDEs and AI retrieval through MCP.Common imports
- Use
Senderto handle the current message, route request, or event. - Use top-level functions for global operations, such as
bucketGet(...),pushImage(...), andfileDownload(...). - Business timeout parameters for
listen(...),input(...), andwaitPay(...)use milliseconds. - Serialize objects with
json.dumps(...)before saving them withset(...)/bucketSet(...).
Recommended template
Actual differences from JavaScript middleware
This table is checked against the currentplugin/scripts/middleware.py and plugin/scripts/middleware.js:
| Difference | JavaScript | Python |
|---|---|---|
| Call style | Most methods return Promise and need await. | Methods return synchronously and raise Exception on failure. |
| Import style | const { Sender } = require('./middleware.js') | from middleware import Sender |
| Default storage delete | del(key) | delete(key); del_ is also available. Avoid the Python keyword del. |
| Dependency ensure | importModule(module, versionOrOptions?, manager?) | import_module(module, package="", version="", manager=""); the current SDK also keeps importModule. |
| Router aliases | sender.getRouter() / getMethod() / getRouterData() are available. | The same aliases are available; prefer getRouterPath(), getRouterMethod(), and getRouterBody() in new docs. |
getRouterData() | Returns a JSON string. | Returns a JSON string; use getRouterBody() when you need an object. |
Cron constructor | new Cron() | Cron() or the legacy-compatible Cron(cronID=None). |
| Cron methods | getCron(...), delCron(...). | Also supports getCronByID(...) and deleteCron(...). |
| Python-only aliases | None. | download_adapter_file(...), get_group_member_list(...). |