A powerful Telegram bot that generates stunning AI videos using Kling AI's state-of-the-art video generation models. Create cinematic videos from text prompts or animate images with natural motion — all from within Telegram.
- 🎥 Text-to-Video — Generate videos from descriptive text prompts
- 🖼️ Image-to-Video — Animate your photos with natural motion
- 🔊 Native Sound Generation — Videos include synchronized audio
- 🧠 AI Prompt Enhancement — Optional Claude AI integration for cinematic prompt optimization
- 💰 Budget Tracking — Daily spending limits with automatic reset
- 👥 User Whitelist — Optional access control for private deployments
- ⚙️ Flexible Settings — Customize duration, aspect ratio, quality mode per user
- 🐳 Docker Support — Deploy in seconds with Docker Compose
-
Clone the repository
git clone https://github.com/progresak/clipforge.git cd kling-telegram-bot -
Configure environment
cp .env.example .env nano .env # Fill in your API keys -
Start the bot
docker compose up -d
That's it! Your bot is now running.
Requirements: Node.js 18+, ffmpeg
-
Clone and install
git clone https://github.com/progresak/clipforge.git cd kling-telegram-bot npm install -
Configure
cp .env.example .env nano .env # Fill in your API keys -
Build & Run
npm run build npm start
- Open Telegram and search for @BotFather
- Send
/newbotand follow the instructions - Copy the bot token (format:
123456789:ABCdefGHIjklMNOpqrsTUVwxyz) - Paste it into
.envasTELEGRAM_BOT_TOKEN
- Visit Kling AI Developer Portal
- Sign up or log in to your account
- Navigate to API keys section
- Generate new API keys (Access Key + Secret Key)
- Add them to
.env:KLING_ACCESS_KEYKLING_SECRET_KEY
Pricing: Kling AI charges per video generation:
- 5-second video (Pro mode): $0.33
- 10-second video (Pro mode): $0.66
For AI-powered prompt enhancement:
- Visit Anthropic Console
- Create an account or sign in
- Generate an API key
- Add to
.envasANTHROPIC_API_KEY
Note: Prompt enhancement is entirely optional. The bot works perfectly without it.
Edit .env to customize your bot:
| Variable | Required | Default | Description |
|---|---|---|---|
TELEGRAM_BOT_TOKEN |
✅ Yes | - | Your Telegram bot token from @BotFather |
KLING_ACCESS_KEY |
✅ Yes | - | Kling AI API access key |
KLING_SECRET_KEY |
✅ Yes | - | Kling AI API secret key |
ALLOWED_USER_IDS |
❌ No | (empty) | Comma-separated Telegram user IDs. Empty = anyone can use |
DAILY_BUDGET_USD |
❌ No | 5 |
Maximum spending per day (resets at midnight UTC) |
DEFAULT_MODEL |
❌ No | kling-v2-6 |
Kling AI model version |
DEFAULT_MODE |
❌ No | pro |
Generation quality: std or pro |
DEFAULT_DURATION |
❌ No | 5 |
Video length in seconds: 5 or 10 |
DEFAULT_ASPECT_RATIO |
❌ No | 16:9 |
Options: 16:9, 9:16, 1:1 |
ANTHROPIC_API_KEY |
❌ No | - | For AI prompt enhancement (optional) |
CLAUDE_CLI_PATH |
❌ No | - | Path to Claude CLI (alternative to API) |
To restrict bot access to specific users:
- Get your Telegram user ID (send any message to @userinfobot)
- Add to
.env:ALLOWED_USER_IDS=123456789,987654321 - Leave empty to allow anyone
| Command | Description |
|---|---|
/start |
Welcome message and feature overview |
/help |
Detailed help and usage instructions |
/budget |
Check today's spending and remaining budget |
/settings |
View your current generation settings |
/duration 5|10 |
Set default video duration (seconds) |
/aspect 16:9|9:16|1:1 |
Set aspect ratio |
/mode std|pro |
Set quality mode |
/sound |
Toggle sound generation on/off 🔊/🔇 |
/enhance |
Toggle AI prompt enhancement on/off ✨ |
Simply send any text message to the bot:
A majestic dragon soaring through storm clouds at sunset
The bot will:
- ✨ Enhance your prompt (if enabled)
- 🎬 Generate the video using Kling AI
- 📹 Send you the finished video
- Send a photo to the bot
- Add a caption describing the desired motion:
Camera slowly zooms in while waves crash on the shore - The bot will animate your image
The optional Claude AI integration transforms simple prompts into cinematic masterpieces:
Your input:
dog running on beach
Enhanced prompt:
Golden retriever ++sprinting across wet sand++ at golden hour, ocean waves
crashing in background. Camera: dynamic tracking shot following lateral
motion, shallow depth of field (f/2.8). Volumetric lighting through ocean
spray, warm color grading, shot on ARRI Alexa. SFX: paws splashing through
water, distant seagulls, crashing waves. Cinematic realism, film grain.
How to enable:
- Add
ANTHROPIC_API_KEYto your.envfile - The bot automatically uses Claude Sonnet 4.5 for enhancement
- Toggle on/off anytime with
/enhance
Cost: ~$0.01 per enhancement (negligible compared to video generation)
The project is written in TypeScript with strict type-checking enabled.
src/
├── index.ts # Main bot logic & command handlers
├── kling-api.ts # Kling AI API client & JWT auth
├── prompt-enhancer.ts # Claude AI integration (API + CLI)
├── budget-tracker.ts # Daily spending tracker
├── utils.ts # Helper functions
└── types/
├── index.ts # Type re-exports
├── kling.ts # Kling AI API types
└── config.ts # App config & settings types
prompts/
└── enhance-video.txt # System prompt for Claude enhancement
data/
├── budget.json # Daily budget state (auto-generated)
└── generations.log # Generation history (auto-generated)
The provided docker-compose.yml handles everything:
- ✅ Node.js 20 runtime
- ✅ ffmpeg for video processing
- ✅ Automatic restarts
- ✅ Data persistence in
./data/ - ✅ Non-root user for security
Useful commands:
# Start bot
docker compose up -d
# View logs
docker compose logs -f
# Restart bot
docker compose restart
# Stop bot
docker compose down- Pro mode (default) generates higher quality videos but costs 2x more than Standard mode
- Prompt enhancement significantly improves video quality — try it!
- Budget tracking resets daily at midnight UTC to prevent overspending
- 5-second videos are perfect for quick tests and cost less
- Use descriptive prompts with camera movements for best results
Bot doesn't respond:
- Check logs:
docker compose logs -fornpm start - Verify
.envvariables are set correctly - Ensure your Telegram user ID is in
ALLOWED_USER_IDS(if using whitelist)
"Enhancement not available" error:
- Make sure
ANTHROPIC_API_KEYis set in.env - Or install Claude CLI and set
CLAUDE_CLI_PATH - Enhancement is optional — bot works without it
Video generation fails:
- Check Kling AI API key validity
- Verify you have sufficient Kling API credits
- Check daily budget hasn't been exceeded (
/budget)
Docker build fails:
- Ensure Docker and Docker Compose are installed
- Try
docker compose build --no-cache
The bot tracks daily spending automatically:
- Expenses are logged in
data/budget.json - Budget resets at midnight UTC
- Check anytime with
/budget - Videos are never generated if budget is exceeded
Contributions welcome! Feel free to:
- 🐛 Report bugs via GitHub Issues
- 💡 Suggest features
- 🔧 Submit pull requests
- ⭐ Star the repo if you find it useful!
MIT License - see LICENSE file for details.
- Kling AI for their amazing video generation API
- Anthropic for Claude AI prompt enhancement
- node-telegram-bot-api for Telegram integration
Made with ❤️ by progresak
Generate stunning AI videos right from your Telegram chat!