Skip to content

Documentation Sync

This page is auto-generated from plugins/adapters/napcat/README.md. Please edit the in-package README and then run pnpm sync:adapter-docs.

@zhin.js/adapter-napcat

Zhin.js NapCatQQ adapter (Plugin Runtime, OneBot 11 + NapCat extensions). Default is forward WebSocket client (connection: ws); also supports reverse WS and HTTP POST reporting (via httpHostToken).

Features

  • OneBot 11 + go-cqhttp extensions + NapCat-specific API
  • Convention-based defineAdapter / definePlugin (no usePlugin needed)
  • Forward WebSocket (connection: ws): the application connects to NapCat WS
  • access_token authentication (Bearer + query)
  • Inbound via messageGatewayToken (deduplication + self-message filtering); outbound send({ target, payload })
  • 41 AI tools (agent/tools/)

Installation

bash
pnpm add @zhin.js/adapter-napcat

Plugin Runtime

  • @zhin.js/adapter — convention-based adapters/napcat.ts (defineAdapter)
  • @zhin.js/coremessageGatewayToken inbound/outbound
  • @zhin.js/plugin-runtimeplugin.ts (definePlugin)
  • Configuration goes to plugins.<instanceKey> via the plugin's schema.json

Inbound: gateway.receive({ adapter, target: "private:uid"|"group:gid", content, sender, metadata }) Outbound: send({ target, payload }) -> WS send_private_msg / send_group_msg

Minimal Configuration

yaml
# zhin.config.yml (Plugin Runtime)
plugins:
  napcat:
    connection: ws
    reconnect_interval: 5000
    heartbeat_interval: 30000
    endpoints:
      - name: my-bot
        url: "ws://127.0.0.1:3001"
        access_token: "${NAPCAT_TOKEN}"

The root plugin zhin.plugins (or project graph) must reference @zhin.js/adapter-napcat (instanceKey: napcat).

Connection Modes

connectionStatus
wsImplemented (recommended)
wssImplemented: reverse WS (httpHostToken)
httpImplemented: POST inbound + http_url/{action} outbound

Authentication

  • Bearer: Authorization: Bearer <access_token>
  • Forward WS attaches request headers during Upgrade and includes access_token in the URL query

AI Tools

CategoryPath
Permit vocabularyagent/PERMITS.md
Platform toolsagent/tools/*.ts
Skill documentationagent/skills/napcat.md

Migration Notes (Plugin Runtime)

  • Notice / request side events have been removed: the old Adapter built notice.receive / request.receive events (including $approve / $reject) for post_type: notice|request; the new Plugin Runtime (messageGatewayToken) has no side-event bus yet — inbound only processes post_type: message, and notice / request events are silently discarded. Friend/group join request approval can be done via callApi('set_friend_add_request' | 'set_group_add_request').
  • Group management tools have not been migrated yet: the old Adapter registered a full set of agent tools (kick/mute/group card, etc.) via createSceneManagementTools; after migration, agent/tools/ only covers NapCat extension APIs. Other group management capabilities can be invoked via callApi (e.g., set_group_kick, set_group_ban) as an escape hatch.
  • Platform permission access control: plugin.ts setup has registered registerDefaultScenePlatformPermitChecker('napcat'). scene_admin / scene_owner are determined based on the sender's role (owner / admin) in the inbound metadata.

License

MIT License