{"record":{"id":"c69837a064e52850","repo":"DIYgod/RSSHub","slug":"telegram-session-is-not-configured","errorCode":null,"errorMessage":"TELEGRAM_SESSION is not configured","messagePattern":"TELEGRAM_SESSION is not configured","errorType":"exception","errorClass":"ConfigNotFoundError","httpStatus":503,"severity":"error","filePath":"lib/routes/telegram/tglib/client.ts","lineNumber":11,"sourceCode":"import { Api, TelegramClient } from 'teleproto';\nimport type { UserAuthParams } from 'teleproto/client/auth';\nimport { StringSession } from 'teleproto/sessions/index.js';\n\nimport { config } from '@/config';\nimport ConfigNotFoundError from '@/errors/types/config-not-found';\n\nlet client: TelegramClient | undefined;\nexport async function getClient(authParams?: UserAuthParams, session?: string) {\n    if (!config.telegram.session && session === undefined) {\n        throw new ConfigNotFoundError('TELEGRAM_SESSION is not configured');\n    }\n    if (client) {\n        return client;\n    }\n    const apiId = Number(config.telegram.apiId ?? 4);\n    const apiHash = config.telegram.apiHash ?? '014b35b6184100b085b0d0572f9b5103';\n\n    const stringSession = new StringSession(session ?? config.telegram.session);\n    client = new TelegramClient(stringSession, apiId, apiHash, {\n        connectionRetries: Infinity,\n        autoReconnect: true,\n        retryDelay: 3000,\n        maxConcurrentDownloads: Number(config.telegram.maxConcurrentDownloads ?? 10),\n        proxy:\n            config.telegram.proxy?.host && config.telegram.proxy.port && config.telegram.proxy.secret\n                ? {\n                      ip: config.telegram.proxy.host,\n                      port: Number(config.telegram.proxy.port),","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/telegram/tglib/client.ts#L1-L29","documentation":"getClient initializes the MTProto TelegramClient from a StringSession. It throws ConfigNotFoundError when neither the passed-in session argument nor config.telegram.session is set, because a StringSession cannot be constructed from nothing and no prior client exists to reuse.","triggerScenarios":"Any Telegram MTProto route (channel-media, etc.) calls getClient() on an instance where TELEGRAM_SESSION was never configured and the caller did not supply a session string.","commonSituations":"Self-hosted RSSHub without TELEGRAM_SESSION; the session string expired/was revoked; the env var was set in a different shell/systemd unit than the one running RSSHub.","solutions":["Generate a StringSession using the teleproto/telethon session generator and set TELEGRAM_SESSION in the RSSHub environment, then restart.","Ensure TELEGRAM_API_ID and TELEGRAM_API_HASH are also set so the client can authenticate the session.","If the session was invalidated (logged out, password change), regenerate it.","Verify the env var is visible to the process (print config.telegram.session presence, not value) to rule out a missing export."],"exampleFix":"// before\nif (!config.telegram.session && session === undefined) {\n    throw new ConfigNotFoundError('TELEGRAM_SESSION is not configured');\n}\n\n// after: also require api credentials and name the env vars\nif (!config.telegram.session && session === undefined) {\n    throw new ConfigNotFoundError('TELEGRAM_SESSION is not configured. Generate a StringSession and set TELEGRAM_SESSION (plus TELEGRAM_API_ID/TELEGRAM_API_HASH) in RSSHub config.');\n}","handlingStrategy":"validation","validationCode":"import { config } from '@/config';\nfunction mtprotoConfigured(): boolean {\n    return Boolean(config.telegram?.session);\n}\n// only register/enable MTProto routes when mtprotoConfigured() is true","typeGuard":"function hasTelegramSession(): boolean {\n    return Boolean(config.telegram && (config.telegram as { session?: string }).session);\n}","tryCatchPattern":"try {\n    return await getClient();\n} catch (e) {\n    if (e instanceof ConfigNotFoundError && /TELEGRAM_SESSION/.test(e.message)) {\n        // return a 503 with setup instructions instead of crashing\n        return unavailable('Set TELEGRAM_SESSION to enable Telegram media routes.');\n    }\n    throw e;\n}","preventionTips":["Generate a StringSession once and store it in TELEGRAM_SESSION.","Also set TELEGRAM_API_ID and TELEGRAM_API_HASH so the session authenticates.","Gate MTProto-dependent routes on config presence so they are not exposed unconfigured.","Regenerate the session if it is logged out or revoked."],"tags":["config","telegram","auth","environment"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}