DEV Community

aaamosh
aaamosh

Posted on • Originally published at gist.github.com

I Built an Open-Source Telegram Bot for the OpenAI Codex Referral Promo

OpenAI dropped Codex referral links on June 12. Seven days of free Codex Pro for you, seven days for a friend. The catch? Each referral code can only be used once. Post your link on social media and the first person to click it claims it — everyone else gets "this referral has already been used." One shot, gone.

That's a poor user experience. And it's wasteful: every unused referral is a missed opportunity for someone who actually wants to try Codex.

So I built @codexHuddbot — a Telegram bot that solves the one-shot matching problem.

How it works

A user sends their Codex referral link to the bot. The bot stores it in a queue. When another user asks for a referral, the bot dequeues the oldest link, marks it as claimed, and sends it privately. No public link dumps. No race conditions. No wasted referrals. One-to-one matching, on demand.

The bot handles duplicates (you can't submit the same link twice), tracks which links have been consumed, and provides a /status command.

Architecture: boring tech, fast delivery

I wanted something that could ship in an afternoon and run reliably for the two-week promo window.

  • buddy-server: A ~500-line Python aiohttp server on a VPS behind nginx with a self-signed certificate. REST API for submitting and claiming referrals, backed by SQLite. No ORM, no migrations, no Docker — just pip install aiohttp and systemctl start codex-buddy. This is the live, running component.
  • buddy-bot: A Cloudflare Worker (free tier) planned to proxy between Telegram's Bot API and the buddy-server — keeping the server's IP hidden and handling webhook requirements. Currently the bot uses Telegram polling directly; the Worker is the next step.
  • codex-reset: A companion CLI that consumes "banked" rate-limit reset credits via the OpenAI Codex wham/rate-limit-reset-credits/consume endpoint. For Linux and headless users who never see the in-editor popup — they'd otherwise leave those credits unused.

~500 lines of application code. Two repos, MIT-licensed.

Why open source?

The promo ends June 24. After that, the bot's core function retires. But the architecture — a lightweight Python aiohttp server behind nginx, backed by SQLite — is reusable for any time-limited Telegram bot. The code is clean enough to serve as a reference, and the referral-matching logic is a simple queue pattern you can adapt.

Try it

Both MIT-licensed. Stars, issues, and PRs welcome. The promo ends June 24 — if you've got an unused referral link, now's the time to share it.

Top comments (0)