A Cloudflare Worker-based Telegram bot that fetches movie and TV series details from the OMDb API and provides download links. The bot handles both text messages and callback queries from inline keyboards to deliver detailed information and media download buttons.
-
Telegram Integration:
Uses Telegram's Bot API to send messages and photos.
Handles commands like/start
and/help
, and processes movie/series title searches. -
OMDb API:
Searches for movie or series details using the OMDb API and returns relevant information such as title, year, genre, plot, and poster. -
Download Links:
Constructs download URLs based on the search results and callback query selections.
Provides separate URL formats for movies and series with inline keyboard buttons. -
Cloudflare Workers:
Designed to run as a Cloudflare Worker. Environment secrets (likeBOT_TOKEN
andOMDB_API_KEY
) are set in the Cloudflare dashboard.
- [worker.js]
Main source file that includes the Cloudflare Worker event listener, the request handler (handleRequest
), and helper functions:- [
sendTelegramMessage
]: Sends text messages. - [
sendTelegramPhoto
]: Sends photos with captions. - [
answerCallback
]: Answers Telegram callback queries.
- [
- A Telegram Bot with a valid Bot Token.
- An OMDb API key for accessing the OMDb API.
- A Cloudflare Workers account to deploy the bot.
-
Clone the Repository:
git clone https://github.com/ahyaghoubi/telegram-movie-bot.git cd telegram-movie-bot
-
Configure Environment Secrets:
Set the following secrets in your Cloudflare Worker dashboard:
BOT_TOKEN
: Your Telegram bot token.OMDB_API_KEY
: Your OMDb API key.
-
Update Webhook (Optional):
The
/setwebhook
endpoint in [worker.js] uses a placeholder URL (https://your-cloudflare-worker.workers.dev/
). Update it to your deployed worker URL:// Change this to your Cloudflare Worker URL const webhookUrl = "https://your-deployed-worker.workers.dev/";
-
Local Testing:
Use Wrangler to test your worker locally:wrangler dev
You can simulate incoming requests as needed.
-
Deployment:
When you're ready to deploy the bot, run:wrangler publish
-
Setting the Webhook:
Once deployed, trigger the/setwebhook
endpoint (via browser or a tool likecurl
) to register the webhook with Telegram. For example:curl https://your-deployed-worker.workers.dev/setwebhook
-
Commands:
/start
: Send a welcome message./help
: Display available commands and usage instructions.
-
Search:
Simply send a movie or series name to get search results. The bot responds with a list of choices as inline keyboard buttons.
Tapping a button will fetch detailed information and provide download links. -
Callback Queries:
When a search result button is clicked, the bot fetches the detailed info from the OMDb API and replies with a photo containing the movie/series details and download links.
- Ensure that your Cloudflare Worker is correctly configured with the necessary secrets.
- Verify that the OMDb API key is active and that you have not exceeded the request limit.
- Check the worker logs (via Cloudflare dashboard or local Wrangler logs) for any error messages during operation.
This project is licensed under the MIT License.
Happy coding with your Telegram Movie Bot!