DEV Community

Cover image for I built a coupon search for AI assistants and Telegram: an MCP server, a bot, and posts that delete themselves
Coupossum.com
Coupossum.com

Posted on AI-assisted

I built a coupon search for AI assistants and Telegram: an MCP server, a bot, and posts that delete themselves

Coupon sites have a reputation problem: half the codes are expired, the other half were never real. I wanted to build one that only shows what a store's affiliate program actually published, with end dates, and then make that data usable where people already are: in their AI assistant and in Telegram.

The result is Coupossum: a website, a public MCP server, a Telegram channel and a Telegram bot, all answering from the same PostgreSQL database. Right now that's about 35,000 codes and deals from about 5,000 stores, refreshed every two hours.

This post covers the parts that turned out to be interesting:

  1. One database, four front ends
  2. An MCP server that AI directories accept
  3. Telegram posts that disappear when the offer ends
  4. A Telegram bot without an AI model
  5. Links that are never opened by a machine

1. One database, four front ends

The data comes from Feedico's Partner API, which aggregates coupons and products from affiliate networks. Coupossum is my own product built on that data, not an official Feedico service.

A sync job pulls coupons every two hours, stores daily, products daily. Everything shown publicly goes through one file of read queries, so the visibility rules exist exactly once:

export const COUPON_VISIBLE = `
  c.is_active AND m.is_eligible AND NOT c.is_duplicate
  AND (c.ends_at IS NULL OR c.ends_at > now())
  AND (c.starts_at IS NULL OR c.starts_at <= now())
  AND (c.link_status IS NULL OR c.link_status NOT IN ${BAD_LINK})
  AND c.is_offer`;
Enter fullscreen mode Exit fullscreen mode

Note ends_at > now() is checked at query time, not at sync time. An offer that ends at 14:00 disappears at 14:00, not at the next sync.

The website, the MCP server and the Telegram bot all import these queries. When I fix a ranking or filter bug, it's fixed everywhere.

Stack: Node 22, Fastify 5, PostgreSQL, the official MCP TypeScript SDK, node:test with PGlite (Postgres in WebAssembly) so the tests run against a real Postgres without Docker. pm2 and cron on a small VPS.

2. An MCP server that AI directories accept

The MCP server is public: https://coupossum.com/mcp, Streamable HTTP, no authentication, read-only. Four tools:

Tool What it does
search_coupons Codes and deals by keyword and/or store, optionally by country
get_store_offers One store's current offers
search_stores Stores by name or domain
search_products Products on sale, with max price and currency

Add it to Claude, ChatGPT, Cursor or VS Code as a remote MCP server and ask "any codes for Belleek?" or "running shoes under 80 euros on sale".

A few things I learned getting it into directories (Anthropic's connector directory, the official MCP Registry as com.coupossum/coupossum, Glama, LobeHub):

Tool descriptions must describe, not instruct. My first version had rules like "always show both links" inside the tool descriptions. Anthropic's directory policy doesn't allow that: tool descriptions are for what a tool does. The rules moved into the server's instructions, which every client receives on connect:

const server = new McpServer(
  { name: 'coupossum', version: '0.2.5', websiteUrl: SITE.origin },
  { instructions: INSTRUCTIONS },
);
Enter fullscreen mode Exit fullscreen mode

Annotations matter. Every tool is marked readOnlyHint: true, destructiveHint: false, idempotentHint: true and openWorldHint: false, with a human-readable title. Reviewers and clients both use them.

Cap and say so. Every tool returns at most 10 results and tells the model when there are more, with a link to the full list. That keeps answers short and stops a model from paging through the whole database.

Rate limit in memory only. A fixed window per IP, kept in a Map for a few minutes and never written anywhere. Search terms are logged for statistics, IPs are not.

3. Telegram posts that disappear when the offer ends

The Telegram channel @coupossum posts one offer an hour during the day. Each post is a generated image plus a caption:

The images come from @napi-rs/canvas with the Inter font bundled from @fontsource/inter, so the server doesn't depend on system fonts. Store names are text only: no logos, no product photos.

The interesting part isn't posting. It's un-posting. A deals channel full of expired codes is exactly the reputation problem I wanted to avoid, so every post is stored with its message id, and every hour the job checks which posted offers are no longer visible:

for (const p of await endedPosts(db, chat)) {
  try {
    await tg.deleteMessage(chat, p.message_id);
    await setStatus(db, p.id, 'deleted');
    continue;
  } catch (err) {
    if (notFound(err)) { await setStatus(db, p.id, 'gone'); continue; }
  }
  // Telegram may refuse: replace the post instead
  await tg.editPhoto(chat, p.message_id, await endedImage(p), endedCaption(p.store_name));
  await setStatus(db, p.id, 'ended');
}
Enter fullscreen mode Exit fullscreen mode

Why the fallback? The Bot API docs say a message "can only be deleted if it was sent less than 48 hours ago", and in the same list that a channel admin with the delete right "can delete any message there". It's not clear which wins for old channel posts, and most offers run longer than 48 hours. Editing has no such limit for a bot's own messages, so if deletion fails, the post becomes an "offer ended" card without the code. I'm running a test post past the 48-hour mark to find out which path Telegram actually takes.

This is also why Telegram is the first social channel and not Pinterest or WhatsApp. On Pinterest, deleting pins through the API needs an approved developer app, and free schedulers like Buffer can't delete published pins. WhatsApp Channels have no official API at all. A channel only gets added once its expired posts can be removed automatically.

4. A Telegram bot without an AI model

@coupossum_bot answers in private chats: send "homary" and you get that store's current codes; send "shoes 20% off" and you get a keyword search. It also works inline: type @coupossum_bot nike in any chat and pick an offer to share.

No LLM involved. A store name match is checked first, then a plain keyword search over the same queries as the website. It's instant, free to run, and it can't hallucinate a code.

The bot runs on a webhook inside the existing Fastify app, not a separate process. Telegram sends a secret token header with each request, which I derive from the bot token so there's no second secret to manage:

export const webhookSecret = (token) =>
  createHmac('sha256', token).update('coupossum-telegram-webhook').digest('base64url').slice(0, 48);

app.post('/telegram/webhook', async (req, reply) => {
  const got = Buffer.from(String(req.headers['x-telegram-bot-api-secret-token'] || ''));
  if (got.length !== expected.length || !timingSafeEqual(got, expected)) return reply.code(403).send('forbidden');
  // handle the update, always answer 200 so Telegram doesn't retry our own errors
});
Enter fullscreen mode Exit fullscreen mode

Nothing about Telegram users is stored. Search terms are logged without user or chat ids; user ids live in memory for a minute for the rate limit.

5. Links that are never opened by a machine

Every store link is an affiliate link, and affiliate networks treat automated clicks as invalid traffic. That shaped more of the design than I expected:

  • Website: store links point to /go/<token> on my own domain (disallowed in robots.txt), and the actual partner URL is opened by JavaScript on a real click. I added this after a crawler that ignores robots.txt started following plain affiliate links.
  • MCP: the server instructions tell assistants to show links and never open them.
  • Telegram: the bot and channel only ever link to the offer's page on coupossum.com, and link previews are switched off, so Telegram's servers never fetch a link on their own.

If you build anything on affiliate data, design for "a human clicked this" from day one.

Try it

I'd love feedback on the MCP tool design in particular: what would you want a shopping tool to return that it doesn't?


Disclosure: Coupossum's store links are affiliate links; if you buy through one, I may earn a commission at no extra cost to you. Coupossum is independent: the stores don't run or endorse it. Offers come from the Feedico partner network; Coupossum is not an official Feedico product.

Top comments (0)