Skip to content

Commit

Permalink
feat: telegram 推送可自定义域名
Browse files Browse the repository at this point in the history
  • Loading branch information
chen310 committed Mar 24, 2022
1 parent 05bac20 commit 4fdb167
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ cookie 获取方式:首先在网页登录[网易云音乐](https://music.163.c
"Telegram": {
"module": "Telegram",
"enable": false,
/* 自定义域名,放空则默认为 https://api.telegram.org */
"server": "",
/* Telegram账号ID */
"userId": "",
/* TG机器人token */
Expand Down
2 changes: 2 additions & 0 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
"module": "Telegram",
/* 是否启用Telegram推送 */
"enable": false,
/* 自定义域名,放空则默认为 https://api.telegram.org */
"server": "",
/* Telegram账号ID */
"userId": "",
/* TG机器人token */
Expand Down
9 changes: 7 additions & 2 deletions push/Telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ def push(title, mdmsg, mdmsg_compat, textmsg, config):
msg = mdmsg_compat # .replace('**', '*')
if len(config['userId']) == 0 or len(config['botToken']) == 0:
return

url = 'https://api.telegram.org/bot' + config['botToken'] + '/sendMessage'
server = config['server']
if server:
if server.endswith('/'):
server = server[:-1]
else:
server = 'https://api.telegram.org'
url = server + '/bot' + config['botToken'] + '/sendMessage'
ret = requests.post(url, data={'chat_id': config['userId'], 'text': msg, 'parse_mode': "Markdown"}, headers={
'Content-Type': 'application/x-www-form-urlencoded'})
print('Telegram response: \n', ret.status_code)
Expand Down

0 comments on commit 4fdb167

Please sign in to comment.