forked from comdotwww/ms_graph_docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSendMsg.py
27 lines (24 loc) · 949 Bytes
/
SendMsg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
from fake_useragent import UserAgent
import requests as req
TG_BOT_TOKEN = os.getenv('TG_BOT_TOKEN')
TG_SEND_ID = os.getenv('TG_SEND_ID')
class SendMessage:
# 发送 TG Bot 消息
def send_tg_msg(msg):
if not TG_BOT_TOKEN or not TG_SEND_ID:
print("TG_BOT_TOKEN 或者 TG_SEND_ID 不存在")
return
PROXY_URL = os.getenv('PROXY_URL')
if not PROXY_URL or PROXY_URL.lower() == "null":
PROXY_URL = "api.telegram.org"
try:
headers = {
'Content-Type': 'application/json',
'User-Agent': UserAgent().random
}
if req.get(r'https://' + PROXY_URL + r'/bot' + TG_BOT_TOKEN + r'/sendMessage?chat_id=' + TG_SEND_ID + r'&text=' + msg, headers=headers).status_code == 200:
print('发送 TG Bot 消息 成功')
except:
print("发送 TG Bot 消息 失败")
pass