Skip to content

This code implements a Cloudflare Worker that serves as a Telegram bot. It interacts with the Telegram Bot API to handle commands, search for movie or series details using the OMDb API, and deliver results with inline keyboard buttons for download links.

License

Notifications You must be signed in to change notification settings

ahyaghoubi/telegram-movie-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Telegram Movie Bot

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.

Overview

  • 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 (like BOT_TOKEN and OMDB_API_KEY) are set in the Cloudflare dashboard.

File Structure

  • [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.

Prerequisites

Setup

  1. Clone the Repository:

    git clone https://github.com/ahyaghoubi/telegram-movie-bot.git
    cd telegram-movie-bot
  2. 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.
  3. 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/";

Running and Deployment

  • 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 like curl) to register the webhook with Telegram. For example:

    curl https://your-deployed-worker.workers.dev/setwebhook

Usage

  • 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.

Troubleshooting

  • 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.

License

This project is licensed under the MIT License.


Happy coding with your Telegram Movie Bot!

About

This code implements a Cloudflare Worker that serves as a Telegram bot. It interacts with the Telegram Bot API to handle commands, search for movie or series details using the OMDb API, and deliver results with inline keyboard buttons for download links.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published