First Plugin
Build and test your first real plugin.
This page walks through a realistic first plugin for the current SDK.
We will build a small command plugin:
- when the user sends
.hello Alice, the plugin rewrites the outgoing message - the greeting template is configurable in plugin settings
- the example stays synchronous and easy to read on purpose
Before you start
Keep these pages nearby:
Minimal plugin shape
Every plugin file should contain:
- metadata as plain top-level constants
- one class inheriting from
BasePlugin
Complete first plugin
What this example teaches
1. Metadata is parsed statically
The loader reads metadata from the Python file with AST, so values such as __id__ and __version__ should stay as plain top-level constants.
2. Hooks must be registered
Implementing on_send_message_hook(...) is not enough by itself.
You also need:
3. Settings are regular Python dataclasses
The settings page is built from objects from ui.settings.
In this example:
Headercreates a section titleInputpersists a string under the key"template"Textis just a read-only helper row
4. HookResult decides what happens next
For outgoing messages:
HookResult()means "leave it unchanged"HookResult(strategy=HookStrategy.MODIFY, params=params)means "use the updated params"HookResult(strategy=HookStrategy.CANCEL)means "stop the send entirely"
Testing it
- Enable the plugin.
- Open the plugin settings and change the template if you want.
- Send
.hello Alicein any chat.
Expected result:
If you change the template to:
then .hello Alice becomes:
Common beginner mistakes
- forgetting
self.add_on_send_message_hook()inon_plugin_load - building metadata dynamically instead of using plain constants
- assuming
params.messagealways exists - doing slow network or file work directly in a hook on the UI thread
If your plugin needs background work, continue with Client Utilities, especially run_on_queue(...).
What to explore next
After this plugin, the most useful next steps are:
- Plugin Class for lifecycle and hooks
- Plugin Settings for richer settings UIs
- Client Utilities for sending messages, requests, and queue work
To further develop your plugin skills, explore community-made plugins: