A Telegram bot that downloads and sends videos from Twitter links. This bot automatically detects Twitter links in messages, downloads the associated videos in the highest available quality, and sends them back to the chat.
- Automatically detects Twitter video links in messages
- Downloads videos in the highest available quality
- Provides video resolution and bitrate information
- Handles temporary file management
- Includes error handling and logging
- Node.js (12.x or higher)
- npm or yarn package manager
- Telegram Bot Token
- Twitter Bearer Token
npm install node-telegram-bot-api axios dotenv
Create a .env
file in the root directory with the following variables:
TELEGRAM_TOKEN=your_telegram_bot_token
TWITTER_BEARER_TOKEN=your_twitter_bearer_token
- Clone the repository:
git clone <repository-url>
cd twitter-video-bot
- Install dependencies:
npm install
-
Set up environment variables as described above
-
Run the bot:
node index.js
- Add the bot to a Telegram chat
- Send a Twitter link containing a video
- The bot will process the link and send back the video file
Example:
User: https://twitter.com/username/status/123456789
Bot: Processing the tweet...
[Bot sends video with resolution and bitrate information]
index.js
: Main bot logictemp/
: Temporary directory for video downloads (created automatically).env
: Environment variables configuration
- Video Quality Selection: Automatically selects the highest quality version available
- Temporary File Management: Downloads are stored temporarily and cleaned up after sending
- Error Handling: Comprehensive error handling for network issues and API failures
- Resolution Information: Provides video resolution and bitrate details with each download
The bot includes handlers for:
- Network failures
- Invalid Twitter links
- Missing video content
- API rate limiting
- Uncaught exceptions
- Unhandled promise rejections
Feel free to submit issues and pull requests.
This bot is intended for personal use and should be used in accordance with Twitter's terms of service and API usage guidelines.