Skip to content

About

A serverless Telegram bot that monitors domain availability using RDAP, Cloudflare Workers, D1, and Cron Triggers, and notifies users when domains become available.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

4 Commits

Folders and files

Repository files navigation

🌐 Domain Notifier Bot

A Telegram bot that monitors domain names and notifies users when a previously registered domain becomes available.

Built with Cloudflare Workers, Cloudflare D1, Telegram Bot API, IANA RDAP, and Cron Triggers.

✨ Features

  • πŸ”Ž Check domain availability through RDAP
  • 🌐 Support domains across different TLDs
  • πŸ€– Telegram bot interface
  • πŸ”” Monitor registered domains
  • πŸŽ‰ Notify users when a monitored domain becomes available
  • πŸ”„ Change the domain being checked
  • πŸ’Ύ Persistent domain storage using Cloudflare D1
  • ⏰ Automatic domain checks every 12 hours
  • ☁️ Serverless deployment with Cloudflare Workers
  • πŸ” Telegram bot token stored as a Worker secret
  • πŸ‘₯ Per-user domain monitoring
  • 🚫 No server, VPS, or setInterval() required

πŸ—οΈ Architecture

                    Telegram User
                         β”‚
                         β”‚ Telegram Message
                         β–Ό
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚   Telegram Bot API  β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚ Webhook
                           β–Ό
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚  Cloudflare Worker   β”‚
                β”‚                     β”‚
                β”‚  β”œβ”€ Telegram Logic  β”‚
                β”‚  β”œβ”€ Domain Checker  β”‚
                β”‚  β”œβ”€ Database Logic  β”‚
                β”‚  └─ Cron Handler    β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
                        β”‚       β”‚
                 D1 Database     β”‚ RDAP
                        β”‚       β–Ό
                        β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                        β”‚   β”‚ IANA RDAP    β”‚
                        β”‚   β”‚ Bootstrap    β”‚
                        β”‚   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚          β”‚
                        β”‚          β–Ό
                        β”‚   Authoritative
                        β”‚   RDAP Server
                        β”‚
                        β–Ό
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚ Cloudflare D1       β”‚
                β”‚                     β”‚
                β”‚ watched_domains     β”‚
                β”‚ user_sessions       β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

                         β–²
                         β”‚
                    Cron Trigger
                    Every 12 hours

πŸ› οΈ Tech Stack

Technology Purpose
JavaScript Application logic
Cloudflare Workers Serverless runtime
Cloudflare D1 SQLite-based persistent database
Telegram Bot API Bot communication
IANA RDAP Bootstrap Finding authoritative RDAP servers
RDAP Domain registration/availability checks
Cloudflare Cron Triggers Scheduled domain monitoring
Wrangler Cloudflare CLI and deployment
Vitest Testing

πŸ“ Project Structure

domain-notifier-worker/
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.js
β”‚   β”œβ”€β”€ database.js
β”‚   β”œβ”€β”€ domainChecker.js
β”‚   β”œβ”€β”€ telegram.js
β”‚   └── watcher.js
β”‚
β”œβ”€β”€ test/
β”‚   └── index.spec.js
β”‚
β”œβ”€β”€ schema.sql
β”œβ”€β”€ wrangler.jsonc
β”œβ”€β”€ package.json
β”œβ”€β”€ package-lock.json
β”œβ”€β”€ vitest.config.mjs
β”œβ”€β”€ .prettierrc
β”œβ”€β”€ .editorconfig
β”œβ”€β”€ .gitignore
└── README.md

Source Files

src/index.js

Main Cloudflare Worker entry point.

Handles:

  • Telegram webhook requests
  • /start
  • domain input
  • πŸ”” Notify Me
  • πŸ”„ Change Domain
  • scheduled events

src/database.js

Contains all D1 database operations.

Handles:

  • user sessions
  • watched domains
  • domain status updates
  • retrieving monitored domains

src/domainChecker.js

Checks domain availability using RDAP.

The process is:

Domain
   ↓
Extract TLD
   ↓
IANA RDAP Bootstrap
   ↓
Find authoritative RDAP server
   ↓
Query /domain/{domain}
   ↓
HTTP 404 β†’ Available
HTTP 200 β†’ Registered
Other β†’ Unknown/Error

src/telegram.js

Contains the Telegram Bot API integration.

The Worker communicates directly with Telegram using fetch().

src/watcher.js

Handles scheduled monitoring.

It:

  1. Gets all monitored domains from D1.
  2. Checks each domain through RDAP.
  3. Determines its current status.
  4. Sends a Telegram message.
  5. Updates the stored status.

πŸš€ Getting Started

Prerequisites

You need:

  • Node.js
  • npm
  • A Cloudflare account
  • A Telegram account
  • A Telegram bot
  • Wrangler CLI

Check Node.js:

node --version

Check npm:

npm --version

1. Clone the Repository

git clone https://github.com/igamanraj/Domain-Notifier-Bot.git
cd Domain-Notifier-Bot

2. Install Dependencies

npm install

3. Create a Telegram Bot

Open Telegram and search for:

@BotFather

Create a new bot using:

/newbot

BotFather will provide a bot token.

⚠️ Security

Never commit the Telegram bot token to GitHub.

Do not put it directly inside:

src/
wrangler.jsonc
README.md

The token should be stored as a Cloudflare Worker secret.


4. Create the Cloudflare D1 Database

Create a D1 database:

npx wrangler d1 create domain-notifier-db

Cloudflare will return a database ID.

Add the database configuration to wrangler.jsonc:

{
  "name": "domain-notifier-worker",
  "main": "src/index.js",
  "compatibility_date": "2026-11-18",

  "d1_databases": [
    {
      "binding": "DB",
      "database_name": "domain-notifier-db",
      "database_id": "YOUR_DATABASE_ID"
    }
  ],

  "triggers": {
    "crons": [
      "0 0,12 * * *"
    ]
  }
}

Replace:

YOUR_DATABASE_ID

with your actual Cloudflare D1 database ID.


5. Initialize the Database Schema

The project includes:

schema.sql

Apply it to your remote D1 database:

npx wrangler d1 execute domain-notifier-db --remote --file=./schema.sql

Verify the tables:

npx wrangler d1 execute domain-notifier-db --remote --command="SELECT name FROM sqlite_master WHERE type='table';"

You should see:

watched_domains
user_sessions

6. Configure the Telegram Bot Token

Store the Telegram token as a Cloudflare Worker secret:

npx wrangler secret put TELEGRAM_BOT_TOKEN

Wrangler will prompt you to enter the token.

Do not put the token inside wrangler.jsonc.


7. Deploy the Worker

Deploy the Worker:

npx wrangler deploy

After deployment, Cloudflare will provide a Worker URL similar to:

https://domain-notifier-worker.<your-subdomain>.workers.dev

8. Configure the Telegram Webhook

Set the Telegram webhook to your deployed Worker URL.

Using PowerShell:

$token=$env:TELEGRAM_BOT_TOKEN

Invoke-RestMethod `
  -Method Post `
  -Uri ("https://api.telegram.org/bot" + $token + "/setWebhook") `
  -ContentType "application/json" `
  -Body (@{
      url="https://YOUR_WORKER_URL"
  } | ConvertTo-Json)

Replace:

YOUR_WORKER_URL

with your deployed Cloudflare Worker URL.

Telegram should return:

ok     result     description
--     ------     -----------
True   True       Webhook was set

πŸ€– Using the Bot

Open your Telegram bot and send:

/start

The bot will ask for a domain.

For example:

sanskargupta.dev

The bot checks the domain and returns its current status.

Registered Domain

❌ Domain unavailable.

🌐 example.com

This domain is currently registered.

What would you like to do?

The user can then select:

πŸ”” Notify Me

The domain is stored in D1 and will be checked automatically.

Available Domain

If the domain is available:

πŸŽ‰ Good news!

🌐 example.com

The domain appears to be AVAILABLE.

πŸ”” Domain Monitoring

When a user selects:

πŸ”” Notify Me

the domain is stored in the watched_domains table.

Example:

user_id:    1570694216
domain:     example.com
status:     registered

The Worker periodically checks all monitored domains.


⏰ Scheduled Monitoring

The project uses a Cloudflare Cron Trigger:

0 0,12 * * *

Cron schedules use UTC.

For India Standard Time:

00:00 UTC β†’ 05:30 AM IST
12:00 UTC β†’ 05:30 PM IST

The scheduled Worker executes:

scheduled()
    ↓
checkWatchedDomains()
    ↓
getAllWatchedDomains()
    ↓
checkDomain()
    ↓
sendMessage()
    ↓
updateDomainStatus()

πŸ—„οΈ Database

The project uses two main D1 tables.

watched_domains

Stores domains that users want to monitor.

CREATE TABLE IF NOT EXISTS watched_domains (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    user_id TEXT NOT NULL,
    username TEXT,
    domain TEXT NOT NULL,
    status TEXT NOT NULL DEFAULT 'registered',
    notified INTEGER NOT NULL DEFAULT 0,
    created_at TEXT NOT NULL,
    updated_at TEXT NOT NULL,
    UNIQUE(user_id, domain)
);

user_sessions

Stores the current state of each user's bot interaction.

CREATE TABLE IF NOT EXISTS user_sessions (
    user_id TEXT PRIMARY KEY,
    username TEXT,
    step TEXT NOT NULL,
    domain TEXT,
    status TEXT,
    updated_at TEXT NOT NULL
);

Persistent sessions are important because Cloudflare Workers are serverless and should not rely on an in-memory JavaScript Map for user state.


πŸ”Ž Domain Availability Detection

The bot uses the IANA RDAP bootstrap registry:

https://data.iana.org/rdap/dns.json

The TLD is extracted from the domain.

For example:

example.com
       ↓
      com

The IANA bootstrap registry is used to find the appropriate authoritative RDAP server.

The Worker then performs a request similar to:

https://rdap-server.example/domain/example.com

The result is interpreted as:

RDAP Response Bot Status
HTTP 404 Available
HTTP 200 Registered
Other response Unknown
Request failure Error

πŸ§ͺ Local Development

Start the Worker locally:

npx wrangler dev

The local Worker normally runs at:

http://127.0.0.1:8787

Testing Cron Locally

Cloudflare does not automatically trigger scheduled events during local development.

Trigger one manually:

curl "http://127.0.0.1:8787/cdn-cgi/local/scheduled"

You should see logs similar to:

⏰ Cron triggered!
πŸ”Ž Checking watched domains...
πŸ“­ No watched domains.

If your local D1 database contains watched domains, the Worker will check them.


πŸ§ͺ Testing the Remote Database

To inspect the production D1 database:

npx wrangler d1 execute domain-notifier-db --remote --command="SELECT * FROM watched_domains;"

Example:

id | user_id | username | domain | status
1  | 123456  | username | example.com | registered

πŸ” Security

Never commit secrets.

The following files should not be committed:

.env
.dev.vars
.wrangler/
node_modules/

The repository's .gitignore already excludes sensitive/local files.

Telegram bot tokens should be stored using Cloudflare Worker secrets:

npx wrangler secret put TELEGRAM_BOT_TOKEN

If a bot token is accidentally exposed, immediately revoke/rotate it through BotFather.


πŸ“¦ Deployment

The normal production deployment process is:

npm install
npx wrangler deploy

Cloudflare will deploy:

  • Worker code
  • D1 binding
  • Cron configuration

The production Worker is then available through its Cloudflare Workers URL.


πŸ”„ Updating the Bot

After making code changes:

git status

Review the changes.

Then:

git add .
git commit -m "describe your change"
git push

Deploy the new version:

npx wrangler deploy

🧹 Useful Wrangler Commands

Start local development

npx wrangler dev

Deploy

npx wrangler deploy

View D1 tables

npx wrangler d1 execute domain-notifier-db --remote --command="SELECT name FROM sqlite_master WHERE type='table';"

View watched domains

npx wrangler d1 execute domain-notifier-db --remote --command="SELECT * FROM watched_domains;"

View user sessions

npx wrangler d1 execute domain-notifier-db --remote --command="SELECT * FROM user_sessions;"

Update D1 schema

npx wrangler d1 execute domain-notifier-db --remote --file=./schema.sql

πŸ“Œ Current Limitations

The current version intentionally keeps the bot simple.

Currently implemented:

  • Domain checking
  • Domain monitoring
  • Scheduled checks
  • Telegram notifications
  • D1 persistence

Possible future improvements include:

  • /help
  • /list
  • /add
  • /remove
  • Multiple domain management through Telegram commands
  • Inline keyboards
  • Configurable monitoring intervals
  • Retry handling for temporary RDAP failures
  • Rate limiting
  • Better monitoring statistics
  • Domain expiration information
  • More detailed RDAP information

πŸ›£οΈ Roadmap

Version 1.0

  • Telegram bot
  • Domain availability checking
  • RDAP integration
  • Cloudflare Worker
  • Cloudflare D1
  • Telegram webhook
  • Domain monitoring
  • Cron-based checking
  • Telegram notifications

Future

  • /help
  • /list
  • /add
  • /remove
  • Multiple domains per user management
  • Inline keyboard interface
  • Better error/retry handling
  • Rate limiting
  • Monitoring dashboard

🀝 Contributing

Contributions are welcome.

  1. Fork the repository.
  2. Create a new branch:
git checkout -b feature/my-feature
  1. Make your changes.
  2. Test the Worker locally.
  3. Commit your changes:
git commit -m "feat: add my feature"
  1. Push the branch:
git push origin feature/my-feature
  1. Open a Pull Request.

πŸ“„ License

This project is licensed under the MIT License.

See the LICENSE file for details.


πŸ‘¨β€πŸ’» Author

Aman Raidas

GitHub:

https://github.com/igamanraj


⭐ Support

If this project was useful, consider giving the repository a ⭐ on GitHub.

About

A serverless Telegram bot that monitors domain availability using RDAP, Cloudflare Workers, D1, and Cron Triggers, and notifies users when domains become available.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages