A Cloudflare Worker that processes Ingress portal attack notification emails and forwards them to Telegram as formatted messages. Includes agent registration, invitation system, and rule-based notification filtering.
- Processes Ingress portal attack notification emails
- Parses both HTML and text content formats
- Extracts critical information:
- Portal name and location
- Attack details (attacker, time, damage)
- Portal status
- Portal images and map links
- Multiple rule types support:
- Agent-based rules (match specific agents)
- Geographic rules (polygon/radius areas)
- Portal name rules
- Rule combination support
- Attack history tracking
- Rule set management API
- Sends formatted notifications to Telegram
- Includes Intel Map links for quick response
- Interactive bot commands
- Registration system with invitations
- Invitation-based registration system
- Agent faction selection (Resistance/Enlightened)
- Unique notification email per agent
- Agent status tracking
- Cloudflare Account
- Telegram Bot Token
- Wrangler CLI installed
- D1 Database instance
- Create D1 database:
wrangler d1 create email_notification_db
- Configure
wrangler.toml
:
name = "mail-notification-worker"
main = "src/index.js"
compatibility_date = "2024-01-01"
[vars]
TELEGRAM_BOT_TOKEN = "" # Set via secrets
WEBHOOK_SECRET = "" # Set via secrets
TELEGRAM_CHAT_ID = "" # Set via secrets
EMAILSUFFIX = ""
[[d1_databases]]
binding = "emaildb"
database_name = "email_notification_db"
database_id = "YOUR_DATABASE_ID" # From step 1
- Set up secrets:
wrangler secret put TELEGRAM_BOT_TOKEN
wrangler secret put WEBHOOK_SECRET
wrangler secret put TELEGRAM_CHAT_ID
- Create initial admin invitation:
wrangler d1 execute email_notification_db --command "INSERT INTO invitations (invitation_code, expires_at, status) VALUES ('ADMIN2024', datetime('now', '+100 years'), 'active');"
npm install
npm run deploy
curl https://your-worker.workers.dev/rulesets
Response:
{
"success": true,
"data": [
{
"uuid": "test-agent-rule-001",
"name": "Agent Rule",
"description": "Monitor specific agent",
"rules": [{
"type": "agent",
"value": "AgentName"
}],
"record_count": 42,
"last_record_at": "2024-03-11T12:34:56Z"
},
{
"uuid": "test-area-rule-001",
"name": "Area Rule",
"description": "Monitor specific area",
"rules": [{
"type": "polygon",
"points": [
{"lat": 22.5924, "lng": 113.8976},
{"lat": 22.5616, "lng": 113.8468}
]
}],
"record_count": 15,
"last_record_at": "2024-03-11T10:30:00Z"
}
]
}
curl "https://your-worker.workers.dev/ruleset/test-agent-rule-001?startDate=2024-03-01&agent=AgentName"
Response:
{
"success": true,
"data": [
{
"id": 1,
"portal_name": "Test Portal",
"portal_address": "Test Location",
"latitude": 22.5924,
"longitude": 113.8976,
"agent_name": "AgentName",
"timestamp": "2024-03-11T12:34:56Z",
"meet_rule_sets": ["test-agent-rule-001"]
}
]
}
/start
- Start registration with invitation code/invite
- Generate new invitation link/status
- Check agent status/help
- Show available commands/cancel
- Cancel current operation
The bot sends formatted Telegram messages containing:
🚨 Portal Attack Alert!
🏛 Portal Information
Name: [Portal Name]
Address: [Portal Address]
[Portal Image]
👤 Attack Details
Attacker: [Attacker Name]
Time: [Attack Time] GMT
💥 Damage Report
[Damage Details]
📊 Current Status
[Portal Status]
🗺 [Intel Map Link]
👮 Defending Agent
Agent: [Agent Name] (Faction)
PostalMime
: Email parsingGrammy
: Telegram bot interactionsD1
: SQLite database for agent management- Cloudflare Workers: Email and webhook processing
agents
: Stores agent informationregistrations
: Manages registration processinvitations
: Handles invitation systemrule_sets
: Stores notification rulesrecords
: Stores attack records
- Invitation-based registration
- Webhook secret verification
- Per-agent email addresses
- Expiring invitations
- Comprehensive error catching and reporting
- Database operation validation
- Debug logging for troubleshooting
- Error notifications via Telegram
- Registration state management
- Relies on Ingress email notification format
- Requires Cloudflare Workers and D1
- Email must be properly formatted (HTML or text)
- One Telegram account per agent
npm run dev
# Access D1 shell
## Error Handling
- Comprehensive error catching and reporting
- Database operation validation
- Debug logging for troubleshooting
- Error notifications via Telegram
- Registration state management
## Limitations
- Relies on Ingress email notification format
- Requires Cloudflare Workers and D1
- Email must be properly formatted (HTML or text)
- One Telegram account per agent