con un clic
zhin-command-middleware
// Explains Zhin command registration, middleware flow, and permission checks. Use when building commands or message middleware in Zhin plugins.
// Explains Zhin command registration, middleware flow, and permission checks. Use when building commands or message middleware in Zhin plugins.
Guides creation and management of Zhin tools using ZhinTool, defineTool, and ToolService. Covers the unified tool system that bridges AI agent tool-calling and message commands, including Tool↔Command conversion, permission levels, platform/scope filtering, and tool collection. Use when registering tools, converting between tools and commands, or integrating tools with AI agents.
Guides integration of AI/LLM capabilities in Zhin plugins using @zhin.js/ai. Covers multi-model providers, Agent tool calling, session management, streaming responses, unified tool services, and rich media output. Use when adding AI chat, agents, or tool-calling features to a Zhin bot.
Guides development of custom platform adapters in Zhin. Covers extending the Adapter abstract class, creating Bot instances, handling message events, registering tools, and lifecycle management. Use when building adapters for new chat platforms.
Guides database usage in Zhin including model definitions, CRUD queries, transactions, migrations, and lifecycle hooks. Covers the built-in ORM based on @zhin.js/database with SQLite support. Use when working with data persistence in Zhin plugins.
Guides error handling in Zhin using the built-in error hierarchy, ErrorManager, RetryManager, and CircuitBreaker. Use when implementing resilient error handling, retry logic, or circuit breaker patterns in Zhin plugins.
Guides setup and usage of the Zhin MCP (Model Context Protocol) server plugin. Covers configuration, available tools, resources, and prompts for AI assistant integration. Use when integrating Zhin with AI coding assistants like Claude or Cursor via MCP.
| name | zhin-command-middleware |
| description | Explains Zhin command registration, middleware flow, and permission checks. Use when building commands or message middleware in Zhin plugins. |
| license | MIT |
| metadata | {"author":"zhinjs","version":"1.0","framework":"zhin"} |
Use this skill to add message commands and middleware in Zhin plugins. It maps to MessageCommand, addCommand, and the middleware compose flow.
import { usePlugin, MessageCommand } from '@zhin.js/core'
const plugin = usePlugin()
plugin.addCommand(
new MessageCommand('ping')
.desc('Health check command')
.action(async (message) => {
return 'pong'
})
)
MessageCommand uses segment-matcher syntax. Example with parameters:
new MessageCommand('echo <content:text>')
.usage('echo hello')
.examples('echo 你好')
.action(async (message, result) => {
return `You said: ${result.params.content}`
})
Commands can enforce permissions before matching:
new MessageCommand('admin-only')
.permit('group(123456)')
.permit('adapter(onebot11)')
.action(async (message) => 'ok')
The built-in permission service supports:
adapter(name)group(id) (use * to match any group)private(id)channel(id)user(id)Zhin composes middleware in a Koa-like onion model.
plugin.addMiddleware(async (message, next) => {
plugin.logger.info(`Incoming: ${message.$raw}`)
await next()
})
The core inserts a default middleware that routes messages to registered commands:
commandService.handle(...)message.$replyUse custom middleware for logging, auth, or throttling.
Commands can be auto-generated from ZhinTool definitions. When a tool is registered via plugin.addTool(), a corresponding MessageCommand is created automatically.
Conversely, existing commands can be converted to tools for AI agent use via toolService.commandToTool().
See the zhin-tool-service skill for full details on the unified Tool↔Command system, including ZhinTool, defineTool, permission levels, and tool collection.
usePlugin()..desc/.usage/.examples to enrich help text.next() unless you intentionally stop processing.ZhinTool when you need a tool that works with both AI agents and chat commands (see zhin-tool-service skill).