Telegram Reel 發布器
自動將工作室品質的垂直 MP4 影片(最高 50MB)直接上傳並串流到 Telegram,使用標準 Telegram Bot API 端點,無需任何外部 npm 相依套件。
flowchart LR
A[已渲染的 Reel MP4] --> B[telegram_bot.js]
B --> C[Telegram Bot API /sendVideo]
C --> D[使用者 / 頻道聊天]
D --> E[互動式指令 /reels、/day1、/status]
使用時機
- 你已渲染好 MP4 影片(特別是 1080x1920 9:16 垂直 Reel),想要立即傳送到 Telegram。
- 你想要一個互動式 Telegram Bot,讓使用者可以按需求要求 Reel。
- 你想要在影片渲染完成後自動進行管線交付。
先決條件
- Node.js 18+(使用原生的
fetch、FormData和Blob)。 - 從
@BotFather取得的 Telegram Bot Token。 - 目標
chat_id(當使用者按下/start時會自動取得)。
設定檔:telegram_config.json
{
"bot_token": "YOUR_BOT_TOKEN_HERE",
"chat_id": "YOUR_CHAT_ID_HERE",
"bot_name": "Peak Lyrics",
"bot_username": "PeakLyricsBot",
"auto_upload": true
}
設定與自動連結
使用你的 Bot Token 執行設定腳本:
node setup_telegram.js <YOUR_BOT_TOKEN>
- 使用
getMe驗證 Token。 - 印出你的機器人連結(
https://t.me/<bot_username>)。 - 等待使用者在 Telegram 按下
/start。 - 自動擷取
chat_id並儲存到telegram_config.json。 - 立即交付待處理的 Reel。
直接 API 上傳工作流程
const fs = require('fs');
const path = require('path');
async function sendReelVideo(videoPath, { day, songTitle }, chatId, botToken) {
const blob = await fs.openAsBlob(videoPath);
const form = new FormData();
form.append('chat_id', chatId);
form.append('video', blob, path.basename(videoPath));
form.append('caption', `🎬 <b>Day ${day}</b>: <i>${songTitle}</i>\n✨ 1080x1920 Studio Quality\n⏱ Word-by-word synced`);
form.append('parse_mode', 'HTML');
form.append('supports_streaming', 'true');
form.append('width', '1080');
form.append('height', '1920');
const res = await fetch(`https://api.telegram.org/bot${botToken}/sendVideo`, {
method: 'POST',
body: form
});
return await res.json();
}
執行互動式 Bot 監聽器
node telegram_bot.js listen
回應以下指令:
/start或/help- 總覽與選單/day1- 交付 Day 1 Reel/day2- 交付 Day 2 Reel/reels- 交付完整系列集合/status- Bot 健康狀態與聊天連結狀態