TinyFrens × Telegram & Discord — Integration Plan & Alignment Log

Living document. Start here. It explains the goal, the architecture decisions, what is already scaffolded, and an up-to-date checklist of where we are. Update the "Progress log" at the bottom every time we land something.

Last updated: scaffolding pass 1 (Telegram-first + Discord Phase-2 skeleton, all tests green).


1. The idea

TinyFrens is a pocket pet. Today it "follows you" in two ways:

We want to bring the fren inside Telegram and Discord as bots / mini-apps, and map our existing "party room" concept onto a platform "public chat" — so a Telegram group or a Discord channel is a shared room where everyone's frens hang out together.

The "hover" question (bonus) — read this first

"currently we can load the char on top of our phone screen and our desktop, but it would be cool to have them inside telegram and discord."

Hard platform limit: a true always-on-top OS overlay cannot exist inside Telegram (a sandboxed iframe) or Discord (an Activity iframe). Both platforms forbid drawing over other apps — that's why Android/desktop can do it and these cannot. We are being honest about this instead of promising something that won't ship.

What we build instead (the closest equivalent): an in-app floating companion — a draggable fren pinned inside the Mini App / Activity with quick Feed / Play / Nap / Wave care bubbles, so it still feels like it "follows you around" within the platform surface. That lives in web/companion.js. It's gated to only run inside Telegram/Discord (the real overlay on Android/desktop is left untouched).


2. How it maps to the existing codebase

TinyFrens already ships a Farcaster Mini App + Snap integration — that is our template, and we deliberately mirror it. Key existing pieces:

Existing thing File How we reuse it
Pet state + rendering (#pet CSS sprite) web/app.js, web/customize.js, web/style.css Unchanged — the same pet renders inside Telegram/Discord
Multiplayer relay + identity {id,token,code} server/app.py (aiohttp + SQLite), web/friends.js Telegram/Discord auth returns the same identity so friends + party work unchanged
Party rooms (public / private:CODE) server/app.py party-join, web/party.js We add a chat room kind keyed by platform + chat/channel id
Farcaster mini-app client adapter web/farcaster.js Blueprint for web/telegram.js + web/discord.js
Server bot endpoints (Neynar) server/app.py farcaster routes Blueprint for the Telegram webhook + Discord interactions routes

Identity flow (the crux)


3. What's built so far (Pass 1 — Telegram-first)

Server (server/)

Web (web/)


4. Alignment checklist

Legend: ✅ done · 🟡 partial · ⬜ not started

Telegram (primary — Phase 1)

Discord (Phase 2 — skeleton only)

Cross-platform polish


5. To actually turn it on (ops checklist)

Nothing here is committed to a live bot — these are the real-world steps.

Telegram

  1. Create a bot with @BotFather → get TELEGRAM_BOT_TOKEN.
  2. Deploy the relay (server/) behind HTTPS (existing Caddy setup works).
  3. Set env on the server:
    • TELEGRAM_BOT_TOKEN=…
    • TELEGRAM_MINIAPP_URL=https://tinyfrens.lol/web/ (must be HTTPS)
  4. Point the webhook at the server once: https://api.telegram.org/bot<TOKEN>/setWebhook?url=https://<your-server>/api/telegram/webhook
  5. In BotFather: Bot Settings → Menu Button to the Mini App URL, and set the Main Mini App.
  6. Add the bot to a group → it posts the "Open the room" button → everyone shares the room.

Discord

  1. Create an app at the Discord Developer Portal.
  2. pip install PyNaCl (added to requirements.txt) for interaction verification.
  3. Set env: DISCORD_CLIENT_ID, DISCORD_CLIENT_SECRET, DISCORD_REDIRECT_URI, DISCORD_PUBLIC_KEY.
  4. Configure the Activity + URL mapping in the portal, set the interactions endpoint to /api/discord/interactions.
  5. Set window.TINYFRENS_DISCORD_CLIENT_ID in web/social-config.js (or an equivalent config).

6. Known limitations (being explicit)


7. Progress log

Telegram client ──initData (HMAC-signed)──▶ POST /api/telegram/auth
   server validates signature with TELEGRAM_BOT_TOKEN
   maps telegram user.id ─▶ a stable TinyFren pet (tg_users table)
   returns the SAME {id, token, code} the friends relay uses
client stores identity ─▶ friends.js connects the WebSocket ─▶ party.js works as-is

This means zero changes are needed in friends.js/party.js core logic — a Telegram user is just another device identity that happens to be authenticated by Telegram.

Party room = public chat