A simple to configure, pre-built Cloudflare Worker that monitors DNS records for any list of user-specified domains and sends notifications via Telegram when changes are detected.
The project is designed to stay comfortably within Cloudflare's free tier for it's Worker and KV storage services.
- Node.js (v20 or later)
- npm (comes with Node.js)
- Wrangler CLI (v4 or later)
-
Clone the repository:
git clone https://github.com/wavey0x/dns-bot.git cd dns-bot
-
Install dependencies:
npm install
-
Configure your bot and secrets:
-
Create a
.env
file in the project root and supply values:cp .env.example .env
-
Supply the same variables and values as github actions secrets within your repository's settings.1
-
Update
config.json
with your settings:{ "domains": ["domain1.com", "domain2.com"], "cron": "*/5 * * * *", "kvNamespace": { "id": "your-kv-namespace-id" } }
-
Get your Cloudflare API token2
-
-
Deploy the bot:
-
Option 1: Deploy locally
Run the deploy script:
npm run deploy
This will:
- Set up the KV namespace if needed
- Configure Telegram secrets
- Update the worker configuration
- Deploy to Cloudflare Workers
-
Option 2: Deploy via GitHub Actions
- Push your changes to the
main
branch. - The GitHub Action will automatically deploy the bot.
- Push your changes to the
-
To view the logs for your deployed worker:
- Go to the Cloudflare Dashboard.
- Navigate to Workers & Pages.
- Select your worker (
dns-bot
). - Click on Logs to view the worker's logs.
- Wrangler not found: Ensure Wrangler is installed globally or use
npx wrangler
. - Deployment fails: Check your API token and ensure all environment variables are set correctly.
- No logs: Ensure logging is enabled in your
wrangler.toml
file. - GitHub Actions fails: Verify that all required secrets are set in your repository's Settings > Secrets and variables > Actions.
Footnotes
-
Required secrets must be set in both your local
.env
file and GitHub Actions repository secrets. Go to your repository's Settings > Secrets and variables > Actions and add:CLOUDFLARE_API_TOKEN
,TELEGRAM_BOT_TOKEN
, andTELEGRAM_CHAT_ID
. ↩ -
To get your Cloudflare API token:
- Go to the Cloudflare Dashboard
- Navigate to My Profile > API Tokens
- Click Create Token
- Choose Create Custom Token
- Set the following permissions:
- Account > Workers > Edit
- Zone > DNS > Read
- Set the Account Resources to All accounts
- Set the Zone Resources to All zones
- Click Continue to summary and then Create Token