Skip to content

blackXploit-404/ZsecMail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

Token and Configuration

  • telegramAuthToken: This token is used to authenticate requests to the Telegram Bot API.
  • webhookEndpoint: This is the URL path where Telegram will send updates. It needs to be configured on Telegram’s server to point to your Cloudflare Worker.
  • oneSecMailApiUrl: This URL is used to generate random temporary email addresses.

Event Listener and Handler

  • addEventListener('fetch', event => {...}): This sets up an event listener for incoming HTTP requests. When a request is made to the Cloudflare Worker, it triggers the handleIncomingRequest function.
  • async function handleIncomingRequest(event) {...}: This function handles incoming requests, determines the type of request, and calls the appropriate function to process it.

Request Handling

  • The handleIncomingRequest function:
    • Extracts the URL, method, and path from the request.
    • Checks if the request is a POST to the webhookEndpoint. If so, it processes the Telegram update.
    • Checks if the request is a GET to /configure-webhook. If so, it sets up the webhook with Telegram.
    • Returns a 404 Not Found response for other requests.

Processing Telegram Updates

  • async function processUpdate(update) {...}: This function processes the update received from Telegram.
    • It checks if the update contains a message.
    • Based on the message content (/start, /generate_email, /fetchmail, /info), it performs the appropriate action and sends a response back to the user.

Sending Requests to Telegram API

  • The sendMessage function:
    • Uses the fetch() function to send requests to the Telegram API for actions such as sending messages, setting webhooks, etc.

Error Handling

  • The code includes error handling for:
    • Failed API requests (e.g., when generating emails or fetching emails).
    • Invalid user input (e.g., invalid commands or email numbers).

Response Handling

  • The handleIncomingRequest function:
    • Returns appropriate HTTP responses based on the result of processing the request (e.g., successful setup of the webhook, or a 404 Not Found for unrecognized paths). Here's the updated summary with the revised instructions:

Summary

The code sets up a Cloudflare Worker to serve as a webhook for a Telegram bot. It processes updates from Telegram, handles various commands, and interacts with both the Telegram API and the temporary email service API to provide responses and functionality to the users. The worker listens for HTTP requests, processes them according to the method and path, and handles errors appropriately.

How to Set Up Your Own Bot Using Workers:

  1. Copy my code and create a new account on Cloudflare.
  2. Go to the Workers section and add a new worker.
  3. Paste the code into the worker editor.
  4. Cloudflare will provide you with a URL. Set this URL as the webhook endpoint in your Telegram bot settings. --https://api.telegram.org/bot/setWebhook?url=
  5. In your browser, navigate to YOUR_WORKER_URL/configure-webhook to finalize the webhook setup.
  6. Make sure to replace the placeholder bot token with your actual bot token.
  7. Save your settings, and you're all set!

By following these steps, you'll have your own Telegram bot webhook set up using Cloudflare Workers.

Releases

No releases published

Sponsor this project

Packages

No packages published