未提供项目说明
telegram-exception-alerts的Python项目详细描述
电报异常警报
一个非常轻量级的库,用于使用decorator将异常详细信息发送到Telegram。在
安装
pip install telegram-exception-alerts
或者
^{pr2}$使用
初始化alerter实例后,可以将decorator附加到任何函数。如果它
引发异常信息将发送到chat_id
中指定的聊天室(不要忘记
如果你想向一个频道发送通知,你需要在chat_id
前面加上-100
)。在
正常初始化
fromtelegram_exception_alertsimportAlertertg_alert=Alerter(bot_token='YOUR_BOT_TOKEN',chat_id='YOUR_CHAT_ID')@tg_alertdefsome_func_that_can_raise_an_exception():raiseRuntimeError('this is an exception')
从环境初始化(推荐)
也可以从环境变量初始化警报程序。这是推荐的方法 因为它可以确保你没有向回购提交敏感信息。在
ALERT_BOT_TOKEN
-你的机器人代币ALERT_CHAT_ID
-您的聊天id以接收通知
fromtelegram_exception_alertsimportAlertertg_alert=Alerter.from_environment()@tg_alertdefsome_func_that_can_raise_an_exception():raiseRuntimeError('this is an exception')
上面示例中的电报信息如下:
发送消息
您还可以使用Alerter
作为向Telegram发送消息的简单方法:
fromtelegram_exception_alertsimportAlertertg_alert=Alerter.from_environment()tg_alert.send_message(chat_id=111222333,text='Message text')
对于真正的bot编程,我强烈推荐优秀的python-telegram-bot库。在
- 项目
标签: