Skip to content

MessagePush 是一个Python模块,支持向邮件、微信、钉钉、Bark、Telegram、IGot、PushPlus、Anpush、飞书、Discord和WhatsApp推送消息,同时支持同步和异步方式。

License

Notifications You must be signed in to change notification settings

xiaoqiangclub/MessagePush

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 多平台消息推送工具 🚀

GitHub license PyPI v PyPI wheel PyPI pyversions

MessagePush 是一个用于通过多个平台异步和同步推送消息的 Python 模块。它支持通过配置文件或直接调用接口发送消息。

支持的平台

邮件

微信

钉钉

Bark

Telegram

IGot

PushPlus

Anpush

飞书

Discord

WhatsApp

安装

pip install MessagePush

使用方法

MessagePush 支持同步和异步的调用方式。您可以根据需要选择适合的方式进行消息发送。

1. 同步发送消息

您可以通过 Sender 类的同步方法发送消息到多个平台。

发送邮件

from message_push import Sender


def send_email():
    Sender.email(
        subject="测试邮件",
        body="这是一封测试邮件",
        to_email="[email protected]",
        from_email="[email protected]",
        smtp_server="smtp.example.com",
        smtp_port=587,
        smtp_user="[email protected]",
        smtp_password="your_password"
    )


send_email()

发送微信消息

from message_push import Sender


def send_wechat_message():
    Sender.wechat(
        wechat_corp_id="your_corp_id",
        wechat_corp_secret="your_corp_secret",
        wechat_agent_id=1000002,
        message="这是一条测试微信消息"
    )


send_wechat_message()

发送钉钉消息

from message_push import Sender


def send_dingtalk_message():
    Sender.dingtalk(
        webhook_url="https://oapi.dingtalk.com/robot/send?access_token=your_access_token",
        message="这是一条测试钉钉消息",
        secret="your_secret"  # 可选
    )


send_dingtalk_message()

2. 异步发送消息

您可以通过 Sender 类的异步方法发送消息到多个平台。

发送邮件

import asyncio
from message_push import Sender


async def send_email():
    await Sender.email_async(
        subject="测试邮件",
        body="这是一封测试邮件",
        to_email="[email protected]",
        from_email="[email protected]",
        smtp_server="smtp.example.com",
        smtp_port=587,
        smtp_user="[email protected]",
        smtp_password="your_password"
    )


asyncio.run(send_email())

发送微信消息

import asyncio
from message_push import Sender


async def send_wechat_message():
    await Sender.wechat_async(
        wechat_corp_id="your_corp_id",
        wechat_corp_secret="your_corp_secret",
        wechat_agent_id=1000002,
        message="这是一条测试微信消息"
    )


asyncio.run(send_wechat_message())

发送钉钉消息

import asyncio
from message_push import Sender


async def send_dingtalk_message():
    await Sender.dingtalk_async(
        webhook_url="https://oapi.dingtalk.com/robot/send?access_token=your_access_token",
        message="这是一条测试钉钉消息",
        secret="your_secret"  # 可选
    )


asyncio.run(send_dingtalk_message())

3. 使用配置文件发送消息

您可以通过 Sender 类的同步或异步方法使用配置文件发送消息到多个平台。

同步方式

from message_push import Sender


def send_messages_with_config():
    Sender.send_messages_with_config_sync(
        config_path="config.yaml",  # 或者 "config.json"
        message="这是一条测试消息",
        title="测试标题",
        url="https://example.com"
    )


send_messages_with_config()

异步方式

import asyncio
from message_push import Sender


async def send_messages_with_config():
    await Sender.send_messages_with_config_async(
        config_path="config.yaml",  # 或者 "config.json"
        message="这是一条测试消息",
        title="测试标题",
        url="https://example.com"
    )


asyncio.run(send_messages_with_config())

示例配置文件

YAML 格式

email:
  to_email: "[email protected]"
  from_email: "[email protected]"
  smtp_server: "smtp.example.com"
  smtp_port: 587
  smtp_user: "[email protected]"
  smtp_password: "your_password"

wechat:
  corp_id: "your_corp_id"
  corp_secret: "your_corp_secret"
  agent_id: 1000002
  to_user: "UserID"

dingtalk:
  webhook_url: "https://oapi.dingtalk.com/robot/send?access_token=your_access_token"
  secret: "your_secret"  # 可选

bark:
  bark_url: "https://api.day.app/your_bark_key"

telegram:
  bot_token: "your_bot_token"
  chat_id: "your_chat_id"

igot:
  igot_key: "your_igot_key"

pushplus:
  token: "your_pushplus_token"

anpush:
  token: "your_anpush_token"

feishu:
  webhook_url: "https://open.feishu.cn/open-apis/bot/v2/hook/your_feishu_webhook"

discord:
  webhook_url: "https://discord.com/api/webhooks/your_discord_webhook"

whatsapp:
  api_url: "https://graph.facebook.com/v13.0/your_phone_number_id/messages"
  phone_number: "your_phone_number"
  api_token: "your_api_token"

JSON 格式

{
  "email": {
    "to_email": "[email protected]",
    "from_email": "[email protected]",
    "smtp_server": "smtp.example.com",
    "smtp_port": 587,
    "smtp_user": "[email protected]",
    "smtp_password": "your_password"
  },
  "wechat": {
    "corp_id": "your_corp_id",
    "corp_secret": "your_corp_secret",
    "agent_id": 1000002,
    "to_user": "UserID"
  },
  "dingtalk": {
    "webhook_url": "https://oapi.dingtalk.com/robot/send?access_token=your_access_token",
    "secret": "your_secret"
    #
    可选
  },
  "bark": {
    "bark_url": "https://api.day.app/your_bark_key"
  },
  "telegram": {
    "bot_token": "your_bot_token",
    "chat_id": "your_chat_id"
  },
  "igot": {
    "igot_key": "your_igot_key"
  },
  "pushplus": {
    "token": "your_pushplus_token"
  },
  "anpush": {
    "token": "your_anpush_token"
  },
  "feishu": {
    "webhook_url": "https://open.feishu.cn/open-apis/bot/v2/hook/your_feishu_webhook"
  },
  "discord": {
    "webhook_url": "https://discord.com/api/webhooks/your_discord_webhook"
  },
  "whatsapp": {
    "api_url": "https://graph.facebook.com/v13.0/your_phone_number_id/messages",
    "phone_number": "your_phone_number",
    "api_token": "your_api_token"
  }
}

捐赠

支持我

About

MessagePush 是一个Python模块,支持向邮件、微信、钉钉、Bark、Telegram、IGot、PushPlus、Anpush、飞书、Discord和WhatsApp推送消息,同时支持同步和异步方式。

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages