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 纵向 reels)并希望立即投递到 Telegram。
- 你希望拥有一个交互式 Telegram 机器人,用户可按需请求 reels。
- 你希望在视频渲染完成后自动进行管道投递。
前提条件
- 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
}
设置与自动链接
使用你的机器人令牌运行设置脚本:
node setup_telegram.js <YOUR_BOT_TOKEN>
- 使用
getMe验证令牌。 - 打印你的机器人链接(
https://t.me/<bot_username>)。 - 等待用户在 Telegram 中按下
/start。 - 自动捕获并将
chat_id保存到telegram_config.json。 - 立即投递挂起的 reels。
直接 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 工作室质量\n⏱ 逐词同步`);
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();
}
运行交互式机器人监听器
node telegram_bot.js listen
响应:
/start或/help- 概述和菜单/day1- 投递 Day 1 Reel/day2- 投递 Day 2 Reel/reels- 投递完整系列合集/status- 机器人健康状态和聊天链接状态