-
Notifications
You must be signed in to change notification settings - Fork 787
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
45 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import os | ||
import requests | ||
|
||
TELEGRAM_BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN") | ||
|
||
CHAT_ID = "-1002428644828" | ||
API_URL = f"http://localhost:8081/bot{TELEGRAM_BOT_TOKEN}/sendMediaGroup" | ||
|
||
DIST_DIR = os.path.join(os.getcwd(), "dist") | ||
release_file = os.path.join(os.getcwd(), "release.md") | ||
|
||
media = [] | ||
curl_files = {} | ||
|
||
i = 1 | ||
for file in os.listdir(DIST_DIR): | ||
file_path = os.path.join(DIST_DIR, file) | ||
if os.path.isfile(file_path): | ||
file_key = f"file{i}" | ||
media.append({ | ||
"type": "document", | ||
"media": f"attach://{file_key}" | ||
}) | ||
curl_files[file_key] = open(file_path, 'rb') | ||
i += 1 | ||
|
||
with open(release_file, 'r') as f: | ||
release_notes = f.read() | ||
|
||
if media: | ||
media[-1]["caption"] = release_notes | ||
media[-1]["parse_mode"] = "MarkdownV2" | ||
|
||
# 发送 POST 请求到 Telegram API | ||
response = requests.post( | ||
API_URL, | ||
data={ | ||
"chat_id": CHAT_ID, | ||
"media": json.dumps(media) | ||
}, | ||
files=curl_files | ||
) |