Skip to main content

消息推送插件

Project description

nonebot-plugin-push

✨ 消息推送插件 ✨

PyPI - Python Version PyPI GitHub

简介

本插件提供通过邮件、Feishu Webhook 方式进行消息推送,支持纯文本与 Markdown 格式的内容。

安装步骤

使用 nb-cli 安装(推荐)

nb plugin install nonebot-plugin-push

使用 pip 安装

pip install nonebot-plugin-push

需要在 bot 根目录 pyproject.toml 文件中 [tool.nonebot] 部分添加:

plugins = ["nonebot_plugin_push"]

配置

账号配置

当前支持通过邮件和 Feishu Webhook 进行推送,配置示例如下:

PUSH_ACCOUNTS='
[
  {
    "name": "push1",
    "type": "mail",
    "url": "smtp://smtp.example.com:465",
    "username": "name@example.com",
    "password": "password",
    "targets": [ "to@example.com" ]
  },
  {
    "name": "push2",
    "type": "feishu",
    "url": "https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxx",
    "password": "password"
  }
]
'

如需按名称获取推送账号,请保证 name 字段唯一,下表为单个账号配置中各字段的说明:

Mail Feishu Webhook
name 推送名称 推送名称
type 固定为 "mail" 固定为 "feishu"
url SMTP 连接主机与端口号 webhook url
username 账号名(邮箱账号) -
password SMTP 连接密钥 签名校验密钥,可选
targets 推送邮箱列表 -

Driver

若使用 Feishu Webhook,需要参考 driver 配置项,添加 ForwardDriver 支持。

跨插件使用

导入方式:

from nonebot import require
require("nonebot_plugin_push")

使用方式:

from nonebot_plugin_push import MessageSegment, get_push, get_push_list

message = MessageSegment.markdown('**Markdown**<font color="red">文本</font>') + '普通文本'
push = get_push()
if push is not None:
    await push.send(message, "推送消息标题(可选)")

获取特定的推送账号:

from nonebot_plugin_push import get_push, get_push_list

# 获取第一个推送账号
push = get_push()
# 获取一个指定名称的推送账号
push = get_push(name="push1")
# 获取一个指定类型的推送账号
push = get_push(type="mail")
# 获取指定类型的推送账号列表
push = get_push_list(type="feishu")

其他说明

Feishu Webhook 仅支持部分 Markdown 语法,具体请查阅 Markdown 模块 文档。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nonebot_plugin_push-0.1.0.tar.gz (7.0 kB view hashes)

Uploaded Source

Built Distribution

nonebot_plugin_push-0.1.0-py3-none-any.whl (9.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page