Telegram gateway built on top of libtacky (in component mode)
  • Go 62.8%
  • Tcl 36%
  • Python 0.7%
  • Shell 0.3%
  • Makefile 0.1%
  • Other 0.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-12 03:50:23 +02:00
component tz.tcl: the user gone from the gateway (forget with drop) takes its devices' "said once" marks with it. The beta2 log fix (a4fd5242) kept ::tg::tz::silent per device for the run, and the gone check of the full gate (nothing of a user left in the gateway's tables, B2-C14) found it left behind for a user who never linked (priv1 and the coverage run); a device's reconnect, forget without drop, still keeps the mark, as the once-a-run check wants. Checked: the shards history/stickers/packs/media/typing and profile/messages/e2edevices/relink/gone/upload/gwupload at 20000, both privilege modes, twice: 1671/0, then 1670/1 (adhoc phone's cooldown timing, passed in the first run and in every earlier gate). 2026-11-12 03:14:42 +02:00
docs docs for 0.5.0-beta2's log fixes: next.md's new "In 0.5.0-beta2" with the four items (the engine's one-line failures, expected refusals at debug; no admins asked where Telegram shows none, CHAT_ADMIN_REQUIRED kept for the run; a device's time no answer once a run at info; the blocked list's permanent refusals kept, one line a reconcile), DESIGN's channel occupants, time zone and both blocked-list paragraphs saying the new behaviour, README's troubleshooting line for no answer at info. 2026-11-12 02:12:53 +02:00
engine tackygram 0.5.0-beta2 (the user, 2026-11-12: "ship beta2 when green"): paperplaned reports 0.5.0-beta2, README's Status names it, and the README figures by make coverage-all on this tree: Tcl 98.0 % of procs and Go 98.0 % of statements, 53,170 lines of code and 50,385 of tests, 1,031 Go test functions and 1,567 e2e checks defined. In it, since beta1, the prod log's noise and one loop: Telegram's expected refusals logged at debug in one line, no admin list asked of a channel where the user is no admin, a device's unanswered time query said once a run at info, and a block Telegram refuses for good (an id the account cannot resolve) no longer retried at every reconcile. Gate: make test green (vet, -race, 98.0 %); make e2e at 20000 on 8c7528c5 (this code but the version strings) 3982 passed, 0 failed over 20 rigs in both privilege modes; the coverage run's unsharded e2e 1561/0 with the privilege and 1517/0 without (rig on 41222); make stats-check clean. 2026-11-12 03:50:23 +02:00
libtacky@a9ad459b5b libtacky to v1.2.11 (a9ad459b) for tackygram 0.5.0 (the user, 2026-11-12: pin to 1.2.11 when out). It carries the client side of this round, a file for a user or a room behind a gateway going to the gateway's own XEP-0363 service, asked of the peer's JID and plain over TLS (feat/tg05-gateway, 07771406), and libtacky's 1.2.9 to 1.2.11 patches; the component's libtacky (tacky::xmpp::component) is unchanged in use. Gated after this commit. 2026-11-12 00:04:56 +02:00
tests/e2e Blocked list: a permanent refusal is not retried (0.5.0-beta2, LOGNOISE item 4, from the prod log's ~30 warns a reconcile): an id on the user's own XEP-0191 list that Telegram refuses for good to block (peer-not-found: the account does not know the user, no access hash; or USER_ID_INVALID, INPUT_USER_DEACTIVATED, USER_DEACTIVATED, USER_DEACTIVATED_BAN, PEER_ID_INVALID, CONTACT_ID_INVALID) stays agreed as blocked and is kept for the run (unknown): the merge counts it as blocked on Telegram, so it is neither asked again nor taken off the user's list, and it leaves the set when the user unblocks it at the server (nothing asked of Telegram then). Each reconcile's blocks are counted (batch) and the last answer logs one info line, "N blocked on the server could not be blocked on Telegram: not known to the account", instead of a warn per id; any other failure (a flood wait) still warns and undoes its part so the next reconcile retries. The fake logs a refused block with what it said (refused) and takes "refuse the next block" (FLOOD_WAIT_3 once); organize.tcl's blocking part checks an unknown id asked once over two reconciles, kept on the server's list, no warn, the summary once, and a flood-refused block retried. folders blocking green: priv1 91, priv0 62 passed, 0 failed; make test green, 98.0 %. 2026-11-12 02:12:53 +02:00
tools Merge fix/tg05-stickers2 (F5) into integ/0.5: F2's upload pool kept (puts) beside F5's pack lane (packs.go's packsPerUser, packsWaiting and packLane; F2's own packs fields and constants, the same lane under other names, dropped), frames.md's upload row from F5 (set) and file.data's from F3 (12 KiB unsaid), and the photo row and DESIGN's Storage line now say what F1's code does: profile photos are kept in the sealed store in link mode too and the /tg/a/ link serves from them. 2026-11-11 22:18:57 +02:00
.dockerignore tackygram ships as two executables, dist/tackygram and dist/paperplaned (the user: "We do not want to ship the Tcl! We want to ship two binaries: tackygram and paperplaned"): libtacky is a submodule (libtacky/, branch feat/stream-core, at 370ba3c1), whose dist/tackyd is libtacky.a's interpreter running a program, and make component appends component/ (main.tcl at its top, zipped by tackyd's own zipfs mkzip) to a copy of it, so the component carries its Tcl, libtacky and scripts and needs only the C library; make engine is the Go binary as before, make build both, make libtacky builds the submodule's tackyd in libtacky's own container, make clean takes dist/ and the submodule's build. The image is the two executables and the CA roots on Debian's slim base, tackygram the entrypoint running paperplaned from beside it (main.tcl looks for the engine beside the executable, then on PATH); deploy/ goes (the user: tackygram builds a binary or an image and nothing more; running it is anotherim-server's, whose ejabberd.yml and compose file carry what deploy/ held). make e2e runs in libtacky's build image through its ejabberd rig, the client under dist/tackyd. README and DESIGN follow. 2026-10-07 18:11:47 +03:00
.gitignore Code lines and coverage counted as libtacky counts them, after the user's ask of 2026-10-25, "please count tackygram code lines same as in libtacky (and test coverage) in next commit": tools/stats.py (standard library Python, adapted from libtacky's) counts the files git tracks, without blank lines, comments and generated files, by functional component and language (account, avatars, calls, engine, fake, gateway, history, media, roster, stickers, storage, alphabetical, one row per language, the component named on its first row, a file going to the component with the longest matching path prefix, so photo.go or history.go of the account package count under avatars and history), each row with its code, its test lines (the engine's _test.go files and the e2e's suites, e2e.tcl as the gateway's) and its coverage; the total counts code per language (Tcl · Go · C), the everything-else row (Makefile, Dockerfile, the e2e's scripts, tools/) is shown and not counted, and the libtacky submodule is not counted at all. The table is generated into README.md's Layout section and a totals line into a new Status and tests section, between stats markers, by make stats (which reads the last coverage back from the README) and checked by make stats-check (stats.py --readme --check), Python running in libtacky's build image with the repository's git directory mounted for a worktree. make coverage-all runs the engine's tests under go test -race -coverprofile in the Dockerfile's base stage (statements, per file) and both e2e runs over a dist/tackygram whose main.tcl is tools/cov-main.tcl: tools/cov.tcl, after libtacky's tests/cov.tcl (whose root is its own tacky/ and cannot be pointed here), records each procedure of component/ when it is defined and on its first call, line by line since the e2e kills and restarts the gateway, and the plain dist/tackygram is packed again afterwards; COV_DIR (_build/cov, now ignored) gets REPORT.md and RUN with the date and commit. Measured on 2026-10-25 at 0dfac5d: Tcl 96.4 % of procedures (267 of 277), Go 90.5 % of statements (4,271 of 4,720), over 13,660 lines of code (Tcl 4,002, Go 9,648, C 10) and 12,902 lines of tests; the C resolver shim and ntgcalls' Go side, tested only in the image build with the real library, are not measured. Checked: make coverage-go, make coverage-tcl (e2e 230 of 230 with the roster privilege, 253 of 253 without) and make stats-check pass. 2026-10-25 18:45:36 +02:00
.gitmodules libtacky to 4c16a158, develop's tip (v1.0.0-alpha10 and the Windows threads fix), and .gitmodules tracks develop, the branch libtacky develops on now that feat/stream-core is merged. None of what the component calls changed (tacky::xmpp::component's new, handle, reply, error, fail, disco entity, adhoc with -allow, resume and deferred stages, bob put and drop). Checked: make component builds the new tackyd, make e2e 37 of 37. 2026-10-10 12:07:18 +03:00
Dockerfile B2-L4, B2-L5 (image part), B2-L6, B2-E3 and B2-E9's SIGPIPE: the container stops cleanly, says whether it is healthy, and the engine takes no test hook and no too-long-line hang in production. tackygram was the image's PID 1 with no SIGTERM handler, so the kernel never delivered the stop signal and every stop was a 10 s wait and a SIGKILL of both processes, the engine's clean stop never running; PID 1 is now tools/container-init.sh (tackygram-init), which runs tackygram, turns SIGTERM/SIGINT into SIGTERM to paperplaned (calls ended, stores closed; tackygram follows as on any engine exit) and exits 0 after a requested stop; the same script is the HEALTHCHECK (paperplaned running and one of tackygram's own sockets established to its -port). The compose limits (mem_limit, pids_limit, init) live in anotherim-server: README now says to set them. paperplaned refuses every -fake-* flag without -fake (-fake-prefs-fail failed real users' prefs.get, L6), ignores SIGPIPE so a component gone mid-stop leaves the engine its own stop path (E9), and reads request lines up to 8 MiB, so the documented 5 MiB chat.photo (6.7 MiB in base64) is no longer skipped and answered with id 0 for a 150 s hang (E3). Checked: the image built and run with -fake: podman stop returned in 0.5 s with the engine's "engine stopped" logged and exit 0, the health check unhealthy without a server and healthy against a listener on -port; TestFakeHooksNeedFake; TestSIGPIPEIgnored (a subprocess whose stdout reader is gone ends on its own path, not by a signal; fails with the Ignore removed); the chat.photo test sends a 3 MiB photo (skipped before) and a 5 MiB+1 one is bad-request; go test -race of cmd, engine, frame green. docs/frames.md says 8 MiB. 2026-11-02 11:33:00 +02:00
LICENSE GPL-3.0; integration test against Telegram's test servers 2026-10-07 13:11:15 +03:00
Makefile Animated stickers as Telegram's static preview (the user's ruling of 2026-10-27 for the 0.3 line: no conversion, no sandbox, no extra complexity). A TGS or WebM sticker, in a message or a set, is given by the engine as the largest of its document's thumbnails of at most 512 px either way (account.stickerPreview over PhotoSize and PhotoSizeProgressive, file id t<document id>, fetched as an InputDocumentFileLocation with that thumb size, renewed as the sticker's file is), image/webp with the thumbnail's own size and dimensions, its bytes forwarded as Telegram gives them; without such a thumbnail the sticker has no file and the component sends the emoji alone. The component (sticker.tcl, packs.tcl, mam.tcl) uploads the preview as it does a static sticker, imports it into a pack the same way and skips one without a preview. Gone: the engine's sticker.convert and the package convert (the converters' runner and sandbox, the WebM and Lottie checks, the converted WebPs' cache, the per-user converter place and the failure memory), convert/stickerconv.c and convert/convjail.c, paperplaned's -stickerconv, -ffmpeg and -convjail, the Dockerfile's convert stage (rlottie, libwebp, the minimal ffmpeg; libvpx stays in the base stage for the video calls) and the tools beside paperplaned in dist/ and the image, which is 168 MB again as 0.3.6's was (the converters added about 12 MB); the fake's real TGS and WebM files give way to two still previews (128 and 256 px) and "broken sticker" is a TGS without one. With the converter the delta audit's converter findings D1, D2, D5 and D7 are moot. README (features, running, the options, layout), docs/DESIGN.md (Stickers, the layout, testing), docs/frames.md (Sticker, stickerset.get, the fake, the history) and tools/stats.py say so; make stats regenerated. Tests: account's TestStickerOf (a TGS's 128 px preview among a stripped, a 64 px and an 800 px thumbnail, a WebM's progressive one, a TGS without one) and the remembered preview with its thumb size, the set's; the fake's previews as still WebPs; the engine's upload of a preview and sticker.convert unknown; e2e: both animated stickers as still WebPs (VP8L) of 128 and 256 px with their metadata, uploaded once, the one without a preview its emoji alone, the packs with the WebM's preview. make build test pass (Go 99.1 %); the e2e's stickers, packs, media and history parts in both modes 428 passed, 0 failed. 2026-10-27 17:38:08 +02:00
README.md tackygram 0.5.0-beta2 (the user, 2026-11-12: "ship beta2 when green"): paperplaned reports 0.5.0-beta2, README's Status names it, and the README figures by make coverage-all on this tree: Tcl 98.0 % of procs and Go 98.0 % of statements, 53,170 lines of code and 50,385 of tests, 1,031 Go test functions and 1,567 e2e checks defined. In it, since beta1, the prod log's noise and one loop: Telegram's expected refusals logged at debug in one line, no admin list asked of a channel where the user is no admin, a device's unanswered time query said once a run at info, and a block Telegram refuses for good (an id the account cannot resolve) no longer retried at every reconcile. Gate: make test green (vet, -race, 98.0 %); make e2e at 20000 on 8c7528c5 (this code but the version strings) 3982 passed, 0 failed over 20 rigs in both privilege modes; the coverage run's unsharded e2e 1561/0 with the privilege and 1517/0 without (rig on 41222); make stats-check clean. 2026-11-12 03:50:23 +02:00

Tackygram

A Telegram gateway for XMPP. Run it beside your own XMPP server, link your Telegram account, and your Telegram contacts become XMPP contacts. One-to-one chats, and Telegram groups, supergroups and channels as rooms (XEP-0045).

  • Its own Telegram engine on gotd, no TDLib.
  • Sessions are encrypted at rest. A copy of the data directory is useless without the key, which is kept outside it. The XMPP side stores nothing: the engine's sealed store holds your login, its working state and your four gateway settings; the rest is derived again after a restart.
  • Plain XMPP: service discovery, in-band registration (XEP-0077, XEP-0100), ad-hoc commands, and chat-line commands for clients without them.

Licence: GPL-3.0 (LICENSE).

Features

One-to-one chats and groups; messages go both ways.

  • Linking by QR code or phone number, with 2FA; a login left behind is dropped by the next start
  • Contacts and chats in the roster (XEP-0356): mutual contacts only, not the phone book's; Saved Messages as one contact. Without the roster privilege they are a list in service discovery (node contacts, paged with XEP-0059) and each comes in on first use; either way at most -roster-pace contacts' stanzas a second, however many chats
  • Telegram's chat folders as roster groups, the archive as "Archived Chats", following Telegram's changes; your own groups stay
  • Pinned and muted chats as "Pinned Chats" and "Muted Chats" (a mute's end too); a contact's commands Mute, Pin and Archive (and their undoing) change them on Telegram
  • The blocked list: Telegram's blocks in your server's blocked list and yours on Telegram (XEP-0191, with the server's IQ privilege), and Telegram's list at the gateway (XEP-0191, the blocked command)
  • Lookup by @username, phone number or id
  • Texts, replies, delivery and read receipts
  • Reactions (XEP-0444)
  • Corrections and retractions (XEP-0308, XEP-0424)
  • Typing (XEP-0085)
  • Silent and scheduled messages
  • Your messages from other Telegram devices, mirrored as yours
  • Photos, videos, GIFs, audio and files, as links the gateway serves from Telegram (nothing stored on the server; a year's life, the renew-link command after), or copied into the server's upload service where the server has no /tg/ route
  • The gateway as an upload service (XEP-0363) for files to Telegram, in proxy mode: nothing stored on the XMPP server
  • Albums and captions
  • Voice notes and round videos
  • Stickers (XEP-0449), in chats and rooms, the animated ones as Telegram's still preview of them, each naming its set's pack, which the gateway serves itself (your installed Telegram sets listed at its urn:xmpp:stickers:0 node)
  • Places and live locations, contact cards, forwards
  • Link previews both ways (XEP-0511): Telegram's with its picture inline, your client's link Telegram's to preview
  • Polls as ProcessOne's polls (urn:fluux:poll:0), in chats and rooms: votes as reactions, the close with its tally, the author's results for anonymous polls; quizzes as plain polls
  • Formatting (XEP-0393, XEP-0394); custom emoji as the plain emoji they stand for
  • Auto-delete timers as ephemeral messages (XEP-0466), both ways
  • Report spam or abuse with a block (XEP-0191, XEP-0377)
  • Pins and other service messages
  • History as an archive at each contact's JID (XEP-0313), searched with Telegram's search (XEP-0431)
  • Avatars and profile cards (vcard-temp and vCard4): name, @username, phone when shared, birthday, bio
  • A contact's commands: block, unblock, mute, pin, archive, a bot's own commands
  • Bots' buttons (XEP-0439): inline buttons to press, reply keyboards as quick responses, links in the text; for other clients a Buttons command at the bot (Settings turns it off)
  • Your Telegram bio, name, username and photo, and Sync my XMPP profile: your XMPP nickname and avatar as your Telegram name and photo, once, when you ask
  • Your Telegram sessions, two-step password and privacy settings
  • Online on Telegram only while you are online on XMPP, so your phone keeps notifying while you are away
  • The gateway's commands follow the link: before it, Link and Status alone
  • Last seen in your own time zone
  • Voice and video calls, one to one, both ways (VP8 towards XMPP)
  • Telegram secret chats, relayed to one of your devices; the gateway holds no key
  • Groups and supergroups as rooms of the gateway's MUC service, joined by the join command or from their bookmarks: occupants with roles from Telegram's rights (a group whose members may not write is moderated), texts, files and stickers, replies, mentions both ways (XEP-0372 and XEP-0513, on Telegram's entities), reactions, typing, corrections and retractions, the group's service messages, the room's archive; a refused message (slow mode, no right to write) comes back with the reason; forum topics as XEP-0201 threads (tg-topic-<id>) both ways, a topics command, each topic read on its own; a basic group that becomes a supergroup moves to its new room; administration through muc#admin, muc#owner, moderation (XEP-0425), search (XEP-0055) and the room's commands; admins' Telegram titles as XEP-0317 hats (and the promote command to give one), bans for a time (ban-member), the requests to join (join-requests, and a new one said in the room), the room's online count, the service messages in the room's archive, Telegram's mute kept in step with the bookmark's XEP-0492 notification setting
  • Channels and gigagroups as moderated rooms: the admins the occupants, posts from the channel itself with the admin's signature as the nick, posting where Telegram lets you, the rest reading; a post's comments are a thread (XEP-0201) of the channel's discussion group, which is a room of its own

Not bridged: creating forum topics from XMPP, read points in rooms (MDS stays between your XMPP clients), custom-emoji and paid reactions, custom emoji from XMPP to Telegram. Mirroring your own messages, reactions and edits needs the server's message privilege (XEP-0356).

Details: docs/DESIGN.md ("What is bridged, in detail"). For client authors: docs/linking.md, docs/history.md and docs/rooms.md.

Status

The latest release is v0.5.0-beta2, a beta of the 0.5 line, on libtacky v1.2.11: the line in which the gateway serves Telegram's files itself (signed links on its own HTTP side, nothing copied to the server), is the upload service for its own contacts, serves sticker packs itself and bridges link previews (XEP-0511). The 0.4 line brought groups, supergroups, channels and forums as rooms. another.im runs the released versions.

Run against Telegram itself: linking by QR code and by phone with a password, one-to-one texts, media and stickers, read markers, presence and last seen with the time zone, a large contact list, calls both ways (a hang-up on Telegram ends the XMPP call), and channels and groups on real accounts for presence and alerts.

Tested against ejabberd and a scripted Telegram (paperplaned -fake) only: posting in groups and channels, admin actions, forums, a group's move to a supergroup, recovery of missed updates, secret chats, silent and scheduled messages, polls. The rest of what came after v0.3.2 (corrections, albums, profiles and commands, the account's sessions, password and privacy) has not been checked one by one against Telegram.

53,170 lines of code (Tcl 18,711 · Go 34,449 · C 10) and 50,385 lines of tests (the table under Layout); 1,031 Go test functions and 1,567 e2e checks defined. Coverage: Tcl 98.0 % procs · Go 98.0 % stmts (the make coverage-all run on 2026-11-12 at commit 8c7528c5).

The full coverage report of the last run is _build/cov/REPORT.md.

Running it

dist/tackygram is the XMPP component. It runs dist/paperplaned (the engine) from beside it. anotherim-server runs both in its compose deployment: make env ... TACKYGRAM=1 adds telegram.<domain>.

paperplaned keygen > /etc/tackygram/key && chmod 0400 /etc/tackygram/key
COMPONENT_SECRET=… TG_API_ID=… TG_API_HASH=… \
    tackygram -domain telegram.example.org -data /var/lib/tackygram \
    -engine-args '-key /etc/tackygram/key'

TG_API_ID and TG_API_HASH come from https://my.telegram.org. Without -key the engine reads the systemd credential gateway-key.

In the image, PID 1 is tackygram-init (tools/container-init.sh): a stop (SIGTERM) becomes the engine's clean stop, calls ended and stores closed, in well under the runtime's 10 s; its HEALTHCHECK is healthy while the engine runs and the component is connected to the server's component port. The health check only marks the container unhealthy: neither docker nor podman restarts it for that unless told (podman --health-on-failure=restart, or an orchestrator that acts on the status; compose's restart: covers an exit, not a wedged component). Bound the container's memory and processes in the deployment (compose mem_limit, pids_limit): the engine holds up to -max-accounts users, their calls and files in transfer.

What the XMPP server needs

  • An XEP-0114 component listener on localhost (port 5347). Never expose it: XEP-0114 has no TLS.
  • mod_privilege granting the gateway roster (both) and message (outgoing), and IQ (both) on urn:xmpp:blocking for the blocked lists. Without the roster privilege the contacts are not put in the roster at once: a client finds them in the list at the gateway's node contacts (disco#items with RSM), and a contact comes in (an XEP-0144 offer and its subscription request) the first time you write to it or it writes to you; the status command says so. Without the message privilege your messages from other Telegram devices are not mirrored. Without the IQ privilege your server's blocked list and Telegram's are apart: Telegram's is at the gateway (XEP-0191 addressed to it, the blocked command).
  • An XEP-0363 upload service that gives the gateway's domain slots; and, so that Telegram's files are not copied into it, its HTTPS host passing /tg/ to the engine (Settings).
  • For the groups' rooms: nothing of the server's MUC (the gateway is the rooms' service); mod_privilege granting IQ (both) on http://jabber.org/protocol/pubsub, so the gateway keeps the rooms in your bookmarks (XEP-0402). Without it each room comes as a direct invitation (XEP-0249) instead, once per link (a restart of the gateway invites to new rooms only).
  • Nothing for stickers since 0.5 (the gateway serves its sticker packs itself). The packs a gateway before 0.5 published into the server's catalogue are still read, for their stickers to go back as their sets' own; on ejabberd with mod_privilege that read needs anotherim-server's mod_component_iq (processone/ejabberd#4472).

anotherim-server's configuration has all of it (the IQ privilege on urn:xmpp:blocking since its master 819f3b7, on the pubsub namespace for the rooms' bookmarks since 41494b8).

Component options

option default meaning
-domain (TACKYGRAM_DOMAIN) required the gateway's JID
COMPONENT_SECRET required the XEP-0114 secret, from the environment only
-data required the engine's data directory
-host, -port 127.0.0.1, 5347 the server's component listener
-server -domain minus its first label the server's domain
-allow -server domains whose users may use the gateway
-upload upload.<server> the XEP-0363 service files go to
-pubsub pubsub.<server> the old sticker catalogue's service (before 0.5), read only
-name Telegram the name in service discovery
-phone-cooldown 60 seconds between two phone logins of one account
-login-idle 60 seconds a client's QR login lives with no request of its held (then it is cancelled)
-asked-window 60 seconds an unsubscribed from a user is logged as the answer to the gateway's own subscribe or unsubscribe (docs/linking.md, "The subscription cancelled")
-gone-window 10 seconds within which an unsubscribe and an unsubscribed from a user unlink it with a notice (what its server sends when the account is deleted or the gateway taken out of its roster); either alone keeps the link (docs/linking.md, "The subscription cancelled")
-roster-pace 50 the contacts' presences, avatars, roster pushes and subscription requests sent per account a second
-room-cold 16 rooms of an account whose tables are kept while none of the user's resources is in them, the least recently touched freed past that
-upload-daily (TACKYGRAM_UPLOAD_DAILY) 2GiB bytes a day the gateway puts into the upload service for one account, live and archive pages alike; past it a file is held to be fetched on request; 0 for no bound
-upload-parked 1024 files from Telegram kept waiting for the upload service while the gateway's stream to the server is down (asked for again once it is up); past it the oldest is sent as a notice that it could not be bridged
-room-autojoin 20 new room bookmarks made autojoin at once for a user (the first in Telegram's chat list, never an archived chat); the rest are bookmarked without autojoin
-album-wait 8 albums (and files waiting for their caption) one account may have waiting for their files; a new one past that sends the oldest as it is, the files that came, the rest bounced to the sender
-album-wait-all 256 the same for all accounts together
-log info debug logs where each message went (never its text)

Settings

Environment variables of the engine (or paperplaned flags):

variable flag default meaning
TACKYGRAM_MEDIA_MAX -media-max 100MiB the largest file the gateway moves, either way; 0 for no limit of its own. TACKYGRAM_MEDIA_MAX_MIB (a number of MiB) is the old name and still read
TACKYGRAM_MEDIA_MAX_FORCED -media-max-forced 4000MiB the largest file over the limit a user may still fetch on request; 0 turns that off
TACKYGRAM_FETCH_ALLOW -fetch-allow hosts besides the upload service's that shared files may be fetched from, host or host:port, comma-separated: needed only for an upload host on a private or LAN address, over plain http or on a port other than 443. A host without a port is every port of it, plain http included: name host:port for one on the loopback or the LAN (the server's own services listen there); the engine warns at start about a loopback host listed without one. Where files are fetched from: the upload service's slot hosts (an https one on its slot's port and on 443), these, and any other host over https on 443 whose addresses are all public and none this machine's own (files on another XMPP server's upload host need no listing). A refused file names its host to the user ("not an https address (files.example.org)", "not the upload service's host (files.example.org:8443)", "a private address (files.lan)", "the gateway's own address (gw.example.org)") and the engine logs fetch refused at warn with the scheme, host, port and the hosts it trusts: list that host here if it is yours
TACKYGRAM_OWN_HOSTS -own-hosts the component's -domain and -server more of the gateway's own host names or addresses, comma-separated: a file on a host that resolves to an address of these (or of the upload slots' hosts, or TACKYGRAM_CALL_IP) is refused as "the gateway's own address", as one on this machine's interfaces is, for a gateway in a container whose interfaces do not carry the host's public address. A host sharing such an address (a CDN in front of the server's domain) is refused too unless listed in TACKYGRAM_FETCH_ALLOW
TACKYGRAM_HTTP_LISTEN -http-listen 127.0.0.1:5380 the engine's HTTP side: plain HTTP on the loopback, behind the server's HTTPS front, which passes it the path /tg/ (below); off for none. A busy port only warns (the gateway copies files then), unless TACKYGRAM_PROXY_URL is set
TACKYGRAM_HTTPS_LISTEN -https-listen off where no front passes /tg/ to the loopback listener (anotherim-server's compose): the engine's HTTP side over HTTPS itself, host:port (e.g. :5444), the same routes; needs TACKYGRAM_TLS_CERT, TACKYGRAM_TLS_KEY and TACKYGRAM_PROXY_URL. Its clients are the connections' own addresses (no header is trusted there)
TACKYGRAM_TLS_CERT, TACKYGRAM_TLS_KEY -tls-cert, -tls-key the HTTPS listener's certificate (with its chain) and private key, PEM files, e.g. the server's own, mounted read-only; looked at every 10 s and read again when they change, so a renewal needs no restart (a pair that does not load, the key replaced before its certificate, keeps the old one and is tried again); not there yet at start, the listener opens all the same and takes them when they come
TACKYGRAM_PROXY_URL -proxy-url learnt the public base of the gateway's links, e.g. https://upload.example.org/tg/, or the HTTPS listener's https://example.org:5444/tg/. Unset, the gateway tries the upload service's HTTPS host with /tg/ and checks it reaches the engine there (GET /tg/health/<challenge>); when it does not, files are copied into the upload service as before. Set, it is checked the same way. The gateway's own upload service is offered only when a file's worth (PUT /tg/health/<challenge>, 1088 KiB) passes the front too
TACKYGRAM_RETENTION_MIN -retention-min 30d how long a stored item the size of the media limit is kept
TACKYGRAM_RETENTION_MAX -retention-max 365d how long a small one is kept; 0 keeps all until the quota needs room
TACKYGRAM_STORE_MAX -store-max 0 (none) a quota on what traffic stores, all users together
TACKYGRAM_E2E_QUEUE_MAX -e2e-queue-max 10000 items kept per secret chat for an offline device; -1 unlimited
TACKYGRAM_E2E_QUEUE_MAX_MIB -e2e-queue-max-mib 64 the same in MiB
TACKYGRAM_ROOM_RECENT -room-recent 100 a supergroup's most recent members present in its room on join; 0 none
TACKYGRAM_ROOM_OCCUPANTS -room-occupants 500 the most members present in a room for one user, the least recently active leaving first
TACKYGRAM_ROOM_LIST_MAX -room-list-max 1000 the most members a room's member list walks
TACKYGRAM_ROOM_HISTORY_MAX -room-history-max 50 the most messages a room replays on join
TACKYGRAM_CALL_PORTS -call-ports any the UDP port range for calls, e.g. 50000-50199
TACKYGRAM_CALL_IP -call-ip the public address(es) for calls' candidates
TACKYGRAM_CALL_STUN -call-stun stun: server URL(s), instead of or beside TACKYGRAM_CALL_IP
TACKYGRAM_CALL_PRIVATE_PEERS -call-private-peers off 1: a calling device's ICE candidates may be on private addresses (users on the gateway's own LAN); without it they are dropped, as loopback and link-local ones always are, so that no device points the connectivity checks at the gateway's own network

The media limit is 100 MiB because that is what upload services usually take (ejabberd's default), and because one 4 GB Telegram file would tie up the gateway and the upload service for everyone. A file over it arrives as a notice that says how to fetch it anyway (fetch ID to the gateway, within seven days); so does a file past the account's daily upload budget (-upload-daily). XEP-0363 has no delete and the slots are asked as the contacts, outside a user's quota at the server: run the upload service with an expiry (ejabberd: mod_http_upload_quota's max_days).

Files from Telegram go as links the gateway serves itself when the server's HTTPS host passes it /tg/: nothing is copied onto the server. Behind nginx, one location in the vhost that already fronts the uploads (no new certificate or DNS):

location /tg/ {
    proxy_pass http://127.0.0.1:5380;
    proxy_set_header X-Real-IP $remote_addr;
    access_log off;
    proxy_buffering off;
    proxy_request_buffering off;
    client_max_body_size 4000m;
    proxy_read_timeout 1h;
    proxy_send_timeout 1h;
}

In anotherim-server's compose deployment there is no such front: the gateway serves HTTPS itself on a port of its own (TACKYGRAM_HTTPS_LISTEN, the server's certificate in TACKYGRAM_TLS_CERT/TACKYGRAM_TLS_KEY, and TACKYGRAM_PROXY_URL=https://<domain>:<port>/tg/), published by the compose file; curl https://<domain>:<port>/tg/health answers tackygram. Behind nginx the front must set X-Real-IP (the engine's per-client limit reads only it, and only from the loopback; without it every client shares one limit, and the engine warns), and should not log the paths: the token in a link's path opens its file for a year (access_log off; ejabberd logs paths only at debug level). A link lives a year; an expired one answers 410 and the ad-hoc command Renew a file link at the gateway gives a fresh one. Without the route the gateway finds it has none and copies files as before; it probes again later (30 s, doubling to 10 minutes, and every 10 minutes while links are on), so a front that comes up after the gateway needs no restart.

For calls, publish the UDP range one to one, open it in the firewall and set TACKYGRAM_CALL_IP to the host's public address. The Telegram side needs nothing opened. paperplaned -no-calls turns calls off. TACKYGRAM_CALL_CAPTURE_DIR records every call's audio to files; it is for debugging only.

Troubleshooting

  • "Last seen" in UTC, not the user's zone. The gateway asks each of the user's devices for its time (XEP-0202) when it comes online and logs the outcome once per device: time zone of USER: +02:00 from RESOURCE at info, or at warn time of USER/RESOURCE: service-unavailable (or another condition) or no usable tzo; no answer (a client without XEP-0202) at info, once a device a run. A refusal mostly means the gateway is not a roster contact of the user (both ways), and clients such as libtacky's answer urn:xmpp:time to roster contacts only: check that the gateway's JID is in the user's roster with subscription both. Until a device answers, times are written in UTC.

Layout

path what
engine/ paperplaned (Go): Telegram sessions, the encrypted store, the JSON-lines protocol
component/ the XMPP component (Tcl 9 on libtacky's tacky::xmpp::component)
libtacky/ libtacky, a submodule: the interpreter and the tacky::* packages
tests/e2e/ the end-to-end test: ejabberd, the component, the fake engine, a user with two devices
docs/DESIGN.md the design, and what is bridged in detail
docs/frames.md the engine ⇄ component protocol
docs/linking.md, docs/history.md, docs/rooms.md what a client may rely on: linking; history and avatars; a room's kind and a bot
docs/next.md what 0.4.1 holds: the findings left open at 0.4.0, with their reasons

The code by component and language, generated by tools/stats.py (make stats; the coverage column by make coverage-all):

component language what it is code tests coverage
account Tcl register.tcl: linking an account, by ad-hoc command or chat line 820 0 97.1 % procs
Go internal/account: one Telegram session on gotd (login, updates, contacts, sending); internal/qrtext: the login QR code 4,261 5,429 98.3 % stmts
auto-delete, reports Tcl ephemeral.tcl: auto-delete as XEP-0466; spam.tcl: XEP-0377 reports in blocks 137 116 100.0 % procs
Go account/ephemeral.go, report.go, engine/extras.go, fake/extras.go: the same in the engine 373 382 93.5 % stmts
avatars Tcl avatar.tcl: profile photos as avatars (XEP-0084, XEP-0153) 133 0 100.0 % procs
Go account/photo.go: profile photos fetched and announced 274 179 98.6 % stmts
calls Tcl calls.tcl: call signalling (Jingle, XEP-0353) 576 416 100.0 % procs
Go internal/calls: the audio and video bridge, ntgcalls to Telegram, pion to XMPP; account/calls.go 4,285 5,956 98.5 % stmts
C calls/ntg/resolv_shim.c: resolver names ntgcalls' glib needs 10 0 --
buttons Tcl buttons.tcl: bots' buttons as XEP-0439, the press 296 156 100.0 % procs
Go account/markup.go, engine/buttons.go, fake/buttons.go: the keyboards and the callback 256 262 98.3 % stmts
content Tcl content.tcl: places, cards, polls, service messages, forwards; format.tcl: formatting both ways; preview.tcl: link previews (XEP-0511) 1,704 686 100.0 % procs
Go account/content.go, entities.go, service.go, webpage.go, engine/content.go, fake/content.go: the same in the engine 3,246 3,392 99.0 % stmts
edits Tcl edits.tcl: corrections and retractions (XEP-0308, XEP-0424) 298 164 100.0 % procs
Go account/edits.go, engine/edits.go, store/msgs.go, fake/edits.go: edits, deletions and the message index 939 998 97.9 % stmts
engine Tcl engine.tcl: the link to paperplaned 145 0 84.6 % procs
Go cmd/paperplaned: the process; internal/engine: requests and events; internal/frame: the wire 4,098 6,774 97.3 % stmts
fake Go internal/fake: a scripted Telegram account for tests (-fake) 2,639 2,344 94.9 % stmts
gateway Tcl main.tcl: options and the XEP-0114 component; gateway.tcl: presence, disco, lookup, messages, receipts, reactions, mirroring 1,630 1,923 98.8 % procs
groups Tcl muc.tcl: Telegram groups and supergroups as rooms of the gateway's own MUC service: joins, occupants with occupant ids, groupchat both ways with mentions, replies, reactions and typing, the room's archive; rooms.tcl: their administration (muc#admin, muc#owner, moderation, search, vCard), bookmarks or invitations, commands, admins' titles as hats, bans for a time, the requests to join, the two-way mute; forums.tcl: a forum's topics as XEP-0201 threads, the topics command; nickprep.tcl: the resourceprep tables a nick is kept to 4,260 1,624 98.0 % procs
Go account/groups.go, groups_participants.go, groups_updates.go, groups_reactions.go, mentions.go: Telegram's groups and supergroups for the rooms: the dialog list's groups, a group's full chat and members, its changes, typing, reads, pins and named reactions, mentions both ways; groups_admin.go: the admin actions, joining and leaving; forums.go: a forum's topics; groups_extras.go: the requests to join; engine/groups.go, fake/groups.go, fake/forums.go: the frames and the scripted groups 4,276 3,823 96.5 % stmts
history Tcl mam.tcl: an XEP-0313 archive per contact, paged from Telegram, searched (XEP-0431) 283 259 100.0 % procs
Go account/history.go: a chat's history, a page at a time 295 439 100.0 % stmts
media Tcl media.tcl, albums.tcl: files, albums and captions both ways; upload.tcl: the upload service; held.tcl: files over the limit 1,967 583 98.5 % procs
Go account/media.go, attachments.go, files.go: media down and up; internal/fetch: HTTP; held.go: held files 2,390 2,818 98.7 % stmts
organize Tcl blocking.tcl: the blocked lists (XEP-0191 at the gateway; Telegram's kept in step with the user's own under the XEP-0356 IQ permission); the folders as groups are in roster.tcl 377 382 100.0 % procs
Go account/organize.go, engine/organize.go, fake/organize.go: folders, the blocked list; chatstate.go of each: pinned, muted, archived chats 723 779 99.7 % stmts
profile Tcl vcard.tcl: a contact's card (vcard-temp, vCard4); bots.tcl: its full user and commands; account.tcl: the user's own profile; online.tcl, prefs.tcl: online status, the user's settings; tz.tcl: time zone and last seen 1,864 353 96.3 % procs
Go account/online.go, engine/online.go, fake/online.go: the online status 148 251 100.0 % stmts
roster Tcl roster.tcl: the contacts and one-to-one chats in the user's roster (XEP-0356 pushes; without them a list at node contacts, each added on first use), paced, the subscriptions they ask for and their record, Telegram's folders as groups 1,116 574 98.6 % procs
scheduled Tcl schedule.tcl: silent and scheduled messages 442 207 100.0 % procs
Go account/schedule.go, engine/schedule.go, store/schedule.go, fake/schedule.go: the same in the engine 777 880 97.3 % stmts
secret chats Tcl e2e.tcl: secret chats relayed to the owning device, no key held 866 1,086 98.3 % procs
Go internal/e2e: the courier and its durable queue; account/e2e.go, engine/e2e.go, store/e2e.go, fake/e2e.go, fake/peer.go 2,692 2,918 99.1 % stmts
security Tcl security.tcl: the account's sessions, two-step password and privacy 347 106 100.0 % procs
Go account/security.go, engine/security.go, fake/security.go: the same in the engine 705 694 100.0 % stmts
stickers Tcl sticker.tcl: stickers both ways (XEP-0449), the animated ones as Telegram's still preview; packs.tcl: Telegram's sticker sets as the gateway's own XEP-0449 packs 1,270 0 94.6 % procs
storage Go internal/seal: encryption at rest; internal/store: the sealed per-user store; engine/retain.go: retention and quota 1,095 2,315 99.1 % stmts
typing Tcl typing.tcl: chat states (XEP-0085) both ways 180 110 100.0 % procs
Go account/typing.go, engine/typing.go, fake/typing.go: Telegram's typing 137 207 100.0 % stmts
voice and round notes Tcl in media.tcl; tests/e2e/notes.tcl tests it 0 43 --
Go internal/notes: WebM to Ogg Opus, waveforms, round video checks; account/notes.go, fake/notes.go 840 757 99.8 % stmts
everything else make, Dockerfile, sh, Python, Tcl the Makefile, Dockerfile, e2e scripts and tools/ 1,768 2,018 --
total (without everything else) Tcl 18,711 · Go 34,449 · C 10 53,170 50,385 Tcl 98.0 % procs · Go 98.0 % stmts

code: lines without blanks and comments; libtacky is not counted, and the everything else row is not in the total. tests: test lines per component (COMPONENTS in tools/stats.py). coverage: Go statements run by the engine's tests; Tcl procedures called under the e2e in both privilege modes, from the make coverage-all run on 2026-11-12 at commit 8c7528c5.

Build and test

Everything builds and runs in a container (podman, else docker).

make build         # dist/paperplaned and dist/tackygram
make test          # the engine's go vet and race tests
make e2e           # end to end against ejabberd, both privilege modes, sharded
make coverage-all  # both test runs under coverage, into _build/cov and this README
make stats         # this README's tables (make stats-check: fail when stale)
make image         # the runtime image with both executables
make clean

make e2e runs eight rigs on ports from 20000 (E2E_PORT_BASE), logs in _build/e2e; tests/e2e/gate.sh has its knobs. The reads of a user's bare JID and of pubsub.<server> are tested without the privilege, or with E2E_PACKS=1 against a server that loads mod_component_iq.

Try the engine without a Telegram account:

paperplaned keygen > /tmp/key && chmod 0400 /tmp/key
echo '{"id":1,"m":"list"}' | dist/paperplaned -fake -data /tmp/tg -key /tmp/key