Files
Auto_Bangumi/docs/en/dev/plugins/points/notifier.md
Estrella Pan 3258fcca4b docs(4.0-P7): 插件开发文档拆分为总览加每个扩展点一页,补齐中英日三语
- docs/dev/plugins.md 改为总览与导航,旧内容拆入 docs/dev/plugins/
- 新增核心概念、配置表单、事件、前端挂载点、命令行、签名与分发、内置插件、示例页
- 每个扩展点一页,侧边栏由页面表生成
- 改正旧文档中下载器配置、hardlink path_map 与补链按钮的过时描述
2026-10-08 14:51:00 +02:00

50 lines
1.9 KiB
Markdown

# Notifier (notifier)
Adds a notification channel. `@provider(points.NOTIFIER, id=...)` returns a `NotifierFactory`. The factory receives the channel entry `NotifierSettings` and returns a `Notifier`. When the user adds a channel in Settings → Notification, the type list shows this `id`.
```python
from ab_sdk import Plugin, points, provider
from ab_sdk.notify import NotificationMessage, NotifierFactory, NotifierSettings
class Channel:
def __init__(self, settings: NotifierSettings) -> None:
self.settings = settings
async def send(self, message: NotificationMessage) -> bool:
... # return True when the message is delivered
async def test(self) -> tuple[bool, str]:
ok = await self.send(NotificationMessage(kind="event", title="AB", body="test"))
return ok, "ok" if ok else "send failed"
class MyPlugin(Plugin):
@provider(points.NOTIFIER, id="my-push")
def channel(self) -> NotifierFactory:
return Channel
```
## Contract
- `send(message)` returns a `bool`. When the backend refuses the message, return `False`. Do not raise an exception.
- `test()` returns `(success, message)`.
- `NotificationMessage.kind` is `episode` (a new episode; it has `official_title`, `season`, `episode`, `poster_url`) or `event` (a system event).
- Put the credentials in the `config_model` of the plugin and read them through `self.config`. The channel entry `NotifierSettings` has only the common template `template` and the other fields in `extra`.
- To rewrite the push text, use the [message template](/en/dev/plugins/points/message-template) hook.
## Tests
```python
from ab_sdk.testing import NotifierContract
class TestChannel(NotifierContract):
def create(self):
... # a channel whose backend accepts messages
def create_failing(self):
... # optional: a channel whose backend refuses messages
```
Example: `examples/plugins/ntfy-notifier`.