npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@actdim/app-telegram

v1.14.1

Published

Telegram OAuth bridge, account binding, direct Bot API notifier, and bot runtime for actdim apps

Readme

@actdim/app-telegram

Telegram OAuth bridge, account binding, direct Bot API notifier, and bot runtime for actdim applications.

Subpaths and Peer Dependencies

| Subpath | Description | Required Peers | |---|---|---| | . / ./contracts | DTOs, schemas, error codes, button models | @sinclair/typebox | | ./init-data | Telegram Mini App initData HMAC validator | None (node:crypto) | | ./db | Database table types and schema interface | kysely | | ./migrations | Migration directory and source | None (node:url) | | ./server | OAuth bridge, binding service, routes, notifier, modules | fastify, kysely, fast-jwt, get-jwks, @actdim/server-core, @actdim/core-contracts | | ./bot | Bot router, Telegram adapter, commands, client | grammy, fastify | | ./i18n/* | Error translation bundles (en, ru) | None |

Installation

pnpm add @actdim/app-telegram

Install the optional peer dependencies required by the subpaths your application consumes.

Environment Variables

Server Variables

| Variable | Subpath | Default | Description | |---|---|---|---| | TELEGRAM_OIDC_CLIENT_ID | ./server | "" | Telegram OAuth Client ID configured in Zitadel Generic OAuth IdP | | TELEGRAM_BOT_TOKEN | ./server, ./bot | "" | Telegram Bot token from @BotFather | | TELEGRAM_BOT_USERNAME | ./server, ./bot | "" | Bot username without @ for deep links (https://t.me/<bot>?start=bind_<ticket>) | | TELEGRAM_BOT_SERVICE_SUBJECTS | ./server | "" | Comma-separated list of Zitadel machine user sub values authorized for /telegram/bot/* | | WEBAPP_PUBLIC_URL | ./server, ./bot | "" | Public origin of the web application for connect links and buttons | | TELEGRAM_BINDING_TICKET_TTL_SEC | ./server | 300 | Expiration time for one-time binding tickets in seconds | | TELEGRAM_INIT_DATA_MAX_AGE_SEC | ./server | 86400 | Maximum age in seconds for valid Telegram Mini App initData | | ZITADEL_API_URL | ./server | Auth authority | Zitadel API URL for user IdP link lookup | | ZITADEL_MANAGEMENT_PAT | ./server | "" | Personal Access Token of Zitadel machine user with user read access | | TELEGRAM_IDP_ID | ./server | "" | Zitadel Identity Provider ID for the Telegram IdP | | TELEGRAM_API_ROOT | ./server, ./bot | https://api.telegram.org | Telegram Bot API base URL |

Bot Runtime Variables

| Variable | Default | Description | |---|---|---| | TELEGRAM_MODE | polling | Bot run mode (polling or webhook) | | TELEGRAM_WEBHOOK_URL | "" | Public webhook URL registered with Telegram in webhook mode | | TELEGRAM_WEBHOOK_PATH | /telegram/webhook | HTTP path where Fastify receives Telegram webhook updates | | TELEGRAM_WEBHOOK_SECRET | "" | Secret token verified on incoming webhook payloads | | TELEGRAM_WEBAPP_URL | "" | Optional Telegram Mini App URL for the primary button on /start | | TELEGRAM_LOCAL_FILES_PATH | "" (dev) / /var/lib/telegram-bot-api (prod) | Mount path for local bot API file storage | | <PREFIX>_API_URL | http://localhost:3000 (dev) / http://server:3000 (prod) | Backend server base URL | | <PREFIX>_AUTH_AUTHORITY | "" | Zitadel authority URL | | <PREFIX>_BOT_CLIENT_ID | "" | Machine user OAuth Client ID for /telegram/bot/* | | <PREFIX>_BOT_CLIENT_SECRET | "" | Machine user OAuth Client Secret |

Zitadel Generic OAuth IdP Setup

Telegram provides an official OIDC provider, but Zitadel cannot consume it as Generic OIDC directly: Zitadel's OIDC library rejects Telegram's entire JWKS because one key uses ES256K (secp256k1, unsupported by go-jose).

To work around this, configure Telegram as a Generic OAuth IdP in Zitadel pointing to the bridge routes exposed by @actdim/app-telegram/server:

  • Token Endpoint: https://<server-domain>/auth/telegram/token
  • User Endpoint: https://<server-domain>/auth/telegram/userinfo
  • ID Attribute: Set to id (numeric Telegram user ID) to allow automatic account binding from IdP links.

The bridge forwards authorization code exchanges to Telegram and swaps the returned id_token into the access_token, allowing the userinfo endpoint to verify claims against Telegram's JWKS while skipping unsupported key curves.

Server Composition Example

import {
    loadTelegramServerConfig,
    createTelegramModule,
    telegramAuthBridgeRoutes,
} from '@actdim/app-telegram/server';
import { createAuthModule } from '@actdim/server-core/auth';

const telegramConfig = loadTelegramServerConfig(process.env, {
    authority: 'https://zitadel.example.com',
});

// Register auth module with telegram auth bridge routes:
const authModule = createAuthModule({
    ...authOptions,
    afterRoutes: telegramAuthBridgeRoutes(telegramConfig.oauth),
});

// Register telegram binding module:
const telegramModule = createTelegramModule({
    getDb: () => db,
    config: telegramConfig.binding,
});

Bot Composition Example

import {
    loadBotConfig,
    createCommandRouter,
    createAccountCommands,
    createStartCommand,
    createClientCredentialsTokenProvider,
    createBotBindingApi,
    createBindingAccountService,
    createTelegramBotService,
} from '@actdim/app-telegram/bot';

const config = loadBotConfig(process.env, { envPrefix: 'APP' });

// Setup account binding client to backend server
const tokens = createClientCredentialsTokenProvider(config.serverAuth);
const bindingApi = createBotBindingApi({ baseUrl: config.serverApiUrl, tokens });
const accountService = createBindingAccountService({ api: bindingApi });

// Account commands and start command
const account = createAccountCommands({ appName: 'MyPortal' });
const start = createStartCommand({
    appName: 'MyPortal',
    account,
});

// Command router
const router = createCommandRouter({
    commands: [
        start,
        account.connectCommand,
        account.accountCommand,
        account.unbindCommand,
        account.bindCallbackCommand,
    ],
});

// Run bot with health server (polling in dev, webhook in prod)
const botService = createTelegramBotService(
    config,
    router,
    { account: accountService },
    { serviceName: 'myportal-bot', account }
);

await botService.start();

Architecture & Boundary Invariants

  • ./contracts and ./init-data have zero server or bot framework dependencies.
  • ./server never imports grammy or bot runtime internals.
  • ./bot never imports kysely, database tables, or server-core internals.
  • Notifier calls the Telegram Bot API directly via HTTPS using TELEGRAM_BOT_TOKEN, independent of the bot process.