Redis-powered session middleware for Telegraf, the Telegram Bot API framework. Version 5.1.0 is the latest stable release, with regular updates following Telegraf releases. It stores session data in Redis for persistence across bot restarts and horizontal scaling. Key differentiators include support for custom TTL, custom session key resolvers, and manual session access without a context object (useful for OAuth flows). Requires Telegraf ^3.9.0 as a peer dependency.
npm install telegraf-session-redisNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Sets up a Telegraf bot with Redis session middleware, incrementing a counter on each text message.
Use new RedisSession({ store: {...}, ttl: ... }) instead of new RedisSession(host, port, ttl).Use new RedisSession({ store: { url: process.env.REDIS_URL } }) or provide host, port, password.Override getSessionKey to handle missing values: getSessionKey: (ctx) => { if (!ctx.from || !ctx.chat) return null; return `${ctx.from.id}:${ctx.chat.id}`; }To clear session data, set ctx.session = {} (empty object) instead of null.Ensure bot.use(session) is called before any handlers that use ctx.session.
Start Redis or set correct store.host/store.port in options.
Override getSessionKey to handle missing fields or ensure message has from and chat (e.g., not a callback query).