crawlfetch

Build a Telegram bot that downloads videos

"Send me a link, I send you the video" is one of the most popular Telegram bot patterns. Here it is in Python with python-telegram-bot and CrawlFetch.

How it fits together

The bot listens for messages containing a URL, resolves it and replies with the video — Telegram can fetch the file directly from the download link.

The bot code

import os
import httpx
from telegram import Update
from telegram.ext import ApplicationBuilder, ContextTypes, MessageHandler, filters
cf = httpx.AsyncClient(
base_url="https://api.crawlfetch.com",
headers={"Authorization": f"Bearer {os.environ['CRAWLFETCH_KEY']}"},
timeout=20,
)
async def on_link(update: Update, ctx: ContextTypes.DEFAULT_TYPE):
r = await cf.get("/v1/resolve", params={"url": update.message.text, "res": "720p"})
if r.status_code != 200:
await update.message.reply_text(f"Couldn't fetch that video ({r.status_code}).")
return
v = r.json()
await update.message.reply_video(video=v["downloadUrl"], caption=v["title"][:1000])
app = ApplicationBuilder().token(os.environ["TELEGRAM_TOKEN"]).build()
app.add_handler(MessageHandler(filters.Entity("url"), on_link))
app.run_polling()

Notes for Telegram bot

  • Telegram fetches URLs itself for files up to its URL-upload limit; for bigger files, download and upload them, or send the link.
  • Add per-chat cooldowns to protect your quota.

FAQ

Which links does the bot accept?

Anything the API supports: YouTube, TikTok, Instagram Reels, Facebook, X, Vimeo, Dailymotion, Reddit and Pinterest.

Related

Last updated 2026-10-25

Add video downloads to your product today.

1,000 credits on signup plus 500 every month. That is roughly 180 YouTube clips to start, with no card.

Create free account