Skip to content

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

worth-a-ping

An intelligent email-to-Telegram urgency filter that watches your inbox, judges each message for genuine urgency using AI, and proactively alerts you via Telegram only when something actually warrants an interruption.

ChatGPT Image

Built for people drowning in email who need their attention protected, not just their notifications filtered.

Why This Needs Two Channels + Real Judgment

Most notification systems are binary: all or nothing. Email filters and rules are static — they can't understand context, urgency, or whether "the third follow-up today from this person" means something different than the first.

worth-a-ping solves this by:

  1. Watching a noisy channel (email) where anyone can reach you
  2. Judging each message contextually using Gemini, which considers:
    • Message content and tone
    • Sender identity
    • Recent conversation history (is this the 3rd follow-up today?)
    • Time-sensitive signals (production down, hard deadlines)
  3. Alerting on a clean channel (Telegram) that you actually check, only when something genuinely needs you right now

This isn't message routing — it's intelligent triage. The agent learns from your conversation patterns, defaults to silence, and only interrupts when precision is high.

Tech Stack

  • caspian-sdk — Email monitoring with automatic message routing
  • python-telegram-bot — Direct Telegram Bot API integration for proactive alerts
  • Gemini API (gemini-3.5-flash-lite) — Low-latency, cost-effective urgency classification
  • SQLite — Conversation history for context-aware judgments
  • Python 3.11+ — Single long-running backend process

Setup

1. Create Virtual Environment & Install Dependencies

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

2. Get API Keys

Gemini API:

Caspian API:

  • Install the CLI: pip install caspian-cli
  • Run caspian init to generate your API key automatically
  • This will create your Caspian identity and write credentials to .env

3. Create Telegram Bot

  1. Open Telegram and search for @BotFather
  2. Send /newbot and follow the prompts
  3. Give it a name (e.g., "Worth A Ping Alert Bot")
  4. Give it a username ending in "bot" (e.g., "worthaping_bot")
  5. Copy the bot token (format: 123456789:ABCdef...)

4. Get Your Telegram Chat ID

  1. Open Telegram and search for @userinfobot
  2. Send it any message
  3. Copy your numeric user ID (e.g., 123456789)

5. Configure Environment

cp .env.example .env

Edit .env and fill in:

CASPIAN_API_KEY=<auto-generated by caspian init>
CASPIAN_BASE_URL=https://api.trycaspianai.com
GEMINI_API_KEY=<your_gemini_api_key>
TELEGRAM_BOT_TOKEN=<bot_token_from_botfather>
TELEGRAM_CHAT_ID=<your_numeric_chat_id>

6. Connect Email Channel

caspian connect email

This will give you an email address like:

agt-xxxxxxxx@agents.trycaspianai.com

Save this address — all emails sent to it will be monitored by the agent.

7. Start a Chat with Your Bot

Before the agent can send you alerts:

  1. Open Telegram and search for your bot's username
  2. Start a chat and send /start

8. Run the Agent

source venv/bin/activate
python main.py

You should see:

🔌 Initializing worth-a-ping agent...
✅ Agent ready. Listening for messages...

9. Test the Complete Flow

Test 1: Urgent Message

Send an email to your agent's email address with urgent content:

To: agt-xxxxxxxx@agents.trycaspianai.com Subject: Production Emergency Body:

URGENT: The production database is completely offline.
Users cannot login and we're losing customers.
Need immediate assistance!

Expected result:

  • Terminal: [inbound] "URGENT: The production database..." → ALERT → Telegram sent
  • Telegram: You receive an alert from your bot with the message + AI reasoning

Test 2: Non-Urgent Message

Send a casual email:

Body:

Hey! Are we still on for lunch tomorrow?
Let me know what time works for you.

Expected result:

  • Terminal: [inbound] "Hey! Are we still on for lunch..." → SKIP (casual social message...)
  • Telegram: No alert (proving the precision bias works)

How the Judgment Works

Every inbound email is evaluated by Gemini using a carefully designed prompt that:

  1. Defaults to NOT urgent — Precision over recall. False alarms defeat the purpose.
  2. Considers conversation context — If this is the 3rd message today from someone, that matters.
  3. Looks for genuine urgency signals:
    • Production outages, system failures, security incidents
    • Time-sensitive opportunities with hard deadlines (today/tonight)
    • Critical personal emergencies
    • Explicit "need you now" from VIPs
  4. Filters out noise:
    • Newsletters, marketing, automated notifications
    • Meeting invites for future dates
    • FYI updates without time pressure
    • Routine follow-ups
    • Social messages that can wait

The model returns structured JSON with a boolean urgency flag and a one-line reason. The reason is logged to the database and included in Telegram alerts so you can see why the agent thought something was urgent.

Precision Over Recall

The system is intentionally biased toward not interrupting you. A false negative (missing an urgent message) is recoverable — you'll see it eventually when you check email. A false positive (getting pinged for non-urgent stuff) trains you to ignore the alerts, which defeats the entire purpose.

This is reflected in the prompt design, the default-to-skip logic, and the fallback behavior (if the AI fails to parse, assume not urgent).

Project Structure

worth-a-ping/
├── main.py              # Entrypoint: client setup, message handler, event loop
├── triage.py            # Gemini judgment logic (isolated for easy tuning)
├── db.py                # SQLite helpers: logging, context retrieval, alert tracking
├── requirements.txt     # Python dependencies
├── .env.example         # Template for configuration
├── .gitignore           # Excludes .env and *.db
└── README.md            # This file

Demo Video

[Link to demo video will be added here]

How to Tune the Judgment

If you're getting too many or too few alerts, edit the SYSTEM_PROMPT in triage.py to adjust the criteria. The model is instruction-following, so clear natural language changes (e.g., "Be more conservative about what counts as urgent") will directly affect behavior.

You can also test the judgment in isolation:

python triage.py

This runs a few hardcoded test cases and prints the model's verdicts.

License

MIT

About

An agent that reads your inbox and only interrupts you when it's actually worth it — with a reason why. Built on caspian-sdk, spans email + Telegram.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages