# Read It Later, For Real This Time: A Telegram Bot in Rust


## Link sprawl

It happens to me every day: I open a newsfeed on my phone (Twitter, Telegram, LinkedIn –
anything), I see an interesting article and tell myself, "It's really interesting but I can't
read it right now from the phone." So I save it to "read later." Over the years I never found a
method I stuck with. I tried:

- Sending an email to myself
- Sending a Slack message to myself
- Saving it in Google Keep
- Sending it via WhatsApp or Telegram to one of my friends (if I needed that link later, I
  would recall that I sent it to Bob and open our chat)

None of the methods stuck. I forgot where I saved them or I didn't open my Keep for months…
Embarrassing.

## Telegram bot

What is the easiest way to share something from a browser on your phone? The Share button lets
you send the link via WhatsApp, Telegram, Slack, or email. Which of them makes it easiest to
write a bot that collects those links? Telegram, of course. I had already created several test
bots, and it was easy. A couple of minutes – and you have your own bot (yes, picking the name
takes about half of that time). Five minutes with an AI agent – and you have basic
functionality. Most importantly, I can run it on my home server and it doesn't require opening
a port on my router or creating tunnels.

Here is the initial plan:

- Create a Telegram bot via BotFather
- The bot will save links I send to it in a database
- I will list them later and read them

Wait, with AI agents everywhere, it would be a shame not to use them! What if I ask the bot to
pull the linked content, summarize it, and save the summary in the database, too? What if the
bot also worked as an MCP server, so I could talk to it from Claude Code, OpenCode, or Codex?
That way I wouldn't need a separate client to access the database and could use natural
language to list the stories, review the summaries, mark them read, etc.

## Hey, Claude

These days the path from an idea to the first implementation is ridiculously short. You explain
your idea to Claude, Codex, or whatever your favorite agent is – and you have a first working
version in an hour or so. Especially if you are not very picky about language choice, overall
architecture, and implementation details.

I decided to be picky. After all, where's the fun in building your idea if it's too easy?

I wanted to deploy it on my home server, which currently runs RHEL 10.3. Obviously, I wanted to
use Podman to run it in a container. Of course, the container should be built using Red Hat's
Universal Base Image (UBI). And of course, it should be deployed using Podman Quadlets.

I also wanted to use this project to continue learning Rust. I had used Rust in a couple of
simple learning projects, but never for anything serious, and never for something I'd use
myself.

I shared all this with Claude and added:

> Since I'm learning Rust, please give me explanations along the way so I could understand your
> decisions and actions. Please give me tasks that I have to complete myself to learn and
> practice Rust.

Claude did a great job balancing writing code and giving me exercises. Claude split the project
into several phases and in each phase it would give me a couple of functions to write myself.
The functions were relatively simple, but each of them taught me some specific Rust concept or
an idiomatic way to do something. Even with familiar concepts it never hurts to use them in
real code several times to develop muscle memory.

For example, Claude asked me to write the function `format_story_list()`. Seems simple, right?
While working on it I had to use maps, iterators, vectors of strings – and keep in mind
variable ownership all the time.

Another task was to process various error codes and decide if we should retry later (the error
is transient, like a timeout or 5xx), pause the whole queue (we ran out of credit, or the API
rejected the key or the model, like 401 or 404), or count it as a failed attempt for this one
article (everything else). Here is the code:

```rust
/// How the worker treats a model error.
pub fn classify_llm_error(err: &LlmError) -> Disposition {
    match err {
        LlmError::QuotaExhausted => Disposition::Pause(Pause::Quota),
        LlmError::Http(code @ (401 | 403 | 404), _) => Disposition::Pause(Pause::Rejected(*code)),
        LlmError::Http(500..=599, _)
        | LlmError::Http(408, _)
        | LlmError::RateLimited
        | LlmError::Network(_) => Disposition::Transient,
        // covers 400, 413, 422: the request for this article is bad
        LlmError::BadResponse(_) | LlmError::Http(..) => Disposition::Attempt,
    }
}
```

I had never used patterns with `match` before, and in this example I switched from using `if`
guards to patterns since I learned that guards don't tell the compiler about exhaustiveness of
the arms.

## What I learned

- Borrowing and ownership tricks and gotchas (will I _ever_ learn them all?)
- String methods, bytes vs. characters
- Async and Tokio: don't block the runtime; how to use `spawn_blocking`
- `match` nuances: patterns vs. guards (exhaustiveness)
- How to become fluent in Rust: Claude collected some advice including what to pay attention
  to, how to let `clippy` teach me, where to search for useful crates, etc.

## Ship it

We all know that AI agents are good at writing code, but we often forget that code is only a
small part of a working and useful application. Every deployment scenario consists of many
minor decisions and details, and here is my list.

1. I wanted to run this bot on my RHEL server, using Podman Quadlets. It's a good way to make
   your containers standard `systemd` services. You just have to write the
   `reading-list.container` configuration file and place it in your home directory in
   `~/.config/containers/systemd`.
2. Even though the bot (which is also an MCP server) runs on my home network, I wanted Claude
   Code to use an `https://` address, so I set up Caddy. We configured Caddy together with
   Claude so I could use the address `https://rhel01.internal/mcp` for my MCP server
   configuration.
3. Claude Code had no trouble reaching the MCP server on my home network, but Claude Desktop
   couldn't use a custom `Authorization` header. Claude suggested adding `mcp-remote` and we
   did it. It runs on my laptop as a STDIO MCP server and talks to the HTTP MCP server on RHEL.
   Ideally, to make both Claudes happy and also be able to access my reading list from the
   phone I should run the MCP server (which is part of the bot) in the cloud – but this will
   come next.

## It works!

I opened my phone, found an article about SSH keys that I was reading and sent it to the bot.
It responded with a short message, "Saved, tagged #ai." I sent a couple more. I opened Claude
Desktop and added the MCP server (see the instructions in the repository – link at the end of
the post). I held my breath and typed "_Please list the stories from my reading list._" After a
few seconds Claude printed out a nicely formatted table with the stories, their IDs, story
types, and tags. Several articles can be grouped into a single story – see the SPIFFE story
with two articles. Look at the output:

![Claude Desktop showing the list of unread stories](reading_list_desktop.webp)

I typed "_please show story 3_" and got the summary with a list of main ideas, the original
URL, and a comment about potential future steps. It really worked – and even better than I
expected.

After reading the summary you can decide if you want to pull its original text using the URL.
You can say "mark story 3 read" and Claude won't show it next time.

## Never stop improving

Collecting articles is easy. The hard part is reviewing them later and actually reading them.
What if the bot sent me messages like: "You have 7 unread stories; the oldest has been waiting
for 8 days"? This will be my next step in improving the bot.

Of course, it's tempting to make it multi-tenant and let other people share their finds in a
common pool. Or let each of them keep their own collection of articles. This is the long-term
plan.

## But you could instead…

Yes, I know. All of this could be done using one of the popular personal assistants such as
OpenClaw, Dot, or Duet. But: I wanted _this specific functionality_ and not a full-featured
agent with lots of knobs and levers that I have to learn first. Don't forget about the tokens a
generic agent burns running all the time doing stuff I didn't ask it to do. My bot spends
tokens only when I send it a link: two short model calls per article, and nothing in between.
I'll share real numbers after a few weeks of use.

## Try it yourself

I documented all my deployment steps as clearly as I could. Your situation might be different,
so feel free to try other ways: Docker Compose, cloud deployment, etc. If you'd like to add
other deployment scenarios or use cases, open an issue or a PR. And, of course, let me know
about your ideas on future improvements of this bot. Here is the repo:
[reading-list on GitHub](https://github.com/pavelanni/reading-list).

