{"id":46587,"library":"telegraf-session-sqlite","title":"telegraf-session-sqlite","description":"SQLite session middleware for the Telegraf Telegram bot framework, version 1.0.6. Maintains session data persistently using SQLite3 database. Requires an existing sqlite3 instance and a table with a specific schema. Suitable for production bots that need state persistence across restarts with minimal dependencies. Compared to in-memory stores, this provides durability, but lacks built-in expiry or cleanup mechanisms.","status":"active","version":"1.0.6","language":"javascript","source_language":"en","source_url":"https://github.com/podvarkov/telegraf-session-sqlite","tags":["javascript","telegram-bot","telegram","telegraf-framework","middleware","session","sqlite3"],"install":[{"cmd":"npm install telegraf-session-sqlite","lang":"bash","label":"npm"},{"cmd":"yarn add telegraf-session-sqlite","lang":"bash","label":"yarn"},{"cmd":"pnpm add telegraf-session-sqlite","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required to create and interact with the SQLite database instance passed via options.","package":"sqlite3","optional":false},{"reason":"Provides the base Telegram bot framework that the middleware integrates with.","package":"telegraf","optional":false}],"imports":[{"note":"This package uses CommonJS module format; default export is the session function. Named exports are not supported.","wrong":"import { session } from 'telegraf-session-sqlite';","symbol":"session","correct":"const session = require('telegraf-session-sqlite');"},{"note":"Telegraf is default exported, not a named export.","wrong":"const { Telegraf } = require('telegraf');","symbol":"Telegraf","correct":"const Telegraf = require('telegraf');"},{"note":"The verbose() method enables long stack traces for debugging; without it errors may be less descriptive.","wrong":"const sqlite3 = require('sqlite3');","symbol":"sqlite3","correct":"const sqlite3 = require('sqlite3').verbose();"}],"quickstart":{"code":"const sqlite3 = require('sqlite3').verbose();\nconst { session } = require('telegraf-session-sqlite');\nconst Telegraf = require('telegraf');\nconst bot = new Telegraf(process.env.BOT_TOKEN);\nconst db = new sqlite3.Database(':memory:');\ndb.run(`CREATE TABLE telegraf_session (id VARCHAR(255) PRIMARY KEY, session VARCHAR(255))`);\nbot.use(session({ db, table_name: 'telegraf_session' }));\nbot.on('text', (ctx) => {\n  ctx.session.counter = (ctx.session.counter || 0) + 1;\n  ctx.reply(`Session counter: ${ctx.session.counter}`);\n});\nbot.launch();","lang":"javascript","description":"Creates a Telegram bot with SQLite session middleware storing counter in memory session."},"warnings":[{"fix":"Ensure session objects are JSON-serializable. Avoid storing functions, Symbols, or circular structures.","message":"Session data is serialized to JSON before storage; objects with circular references or non-serializable values will cause errors.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Create the table manually using the provided SQL schema: CREATE TABLE telegraf_session (id VARCHAR(255) PRIMARY KEY, session VARCHAR(255));","message":"Database table must exist before using middleware; no automatic table creation is performed.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Alter the table to use TEXT instead of VARCHAR(255) to store longer session strings.","message":"Session data is stored as a VARCHAR(255) column; large session objects may be truncated.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Implement periodic cleanup of old sessions or use an alternative session store with TTL support.","message":"No session expiration or cleanup is implemented; database will grow unboundedly with stale records.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Wrap bot usage in try-catch or attach error handlers to the database instance.","message":"The package uses synchronous SQLite operations? Actually it uses async but database errors may not be properly handled.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'1.0.6':15 'across':43 'bot':12,38,69 'built':60 'built-in':59 'cleanup':64 'compar':48 'data':18 'databas':22 'depend':47 'durabl':56 'exist':25 'expiri':62 'framework':13,73 'in-memori':50 'instanc':27 'javascript':66 'lack':58 'maintain':16 'mechan':65 'memori':52 'middlewar':7,74 'minim':46 'need':40 'persist':19,42 'product':37 'provid':55 'requir':23 'restart':44 'schema':34 'session':3,6,17,75 'specif':33 'sqlite':4,5 'sqlite3':21,26,76 'state':41 'store':53 'suitabl':35 'tabl':30 'telegraf':2,10,72 'telegraf-framework':71 'telegraf-session-sqlit':1 'telegram':11,68,70 'telegram-bot':67 'use':20 'version':14","created_at":"2026-06-07T13:00:38.929597+00:00","updated_at":"2026-06-07T13:00:38.929597+00:00","problems":[{"fix":"Run 'npm install telegraf-session-sqlite' and ensure the require path is correct.","cause":"Package not installed or incorrect import path.","error":"Cannot find module 'telegraf-session-sqlite'"},{"fix":"Execute the CREATE TABLE statement from the README before calling session() middleware.","cause":"Table not created in the database before using middleware.","error":"SQLITE_ERROR: no such table: telegraf_session"},{"fix":"Use 'const session = require('telegraf-session-sqlite');' (commonjs) and verify the package is version 1.x.","cause":"Incorrect import or version mismatch.","error":"TypeError: session is not a function"},{"fix":"Ensure bot.use(session(options)) is called before any handlers that access ctx.session.","cause":"Session object not initialized; middleware not applied or ctx.session is undefined.","error":"Cannot read property 'counter' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/podvarkov/telegraf-session-sqlite","github":"https://github.com/podvarkov/telegraf-session-sqlite","docs":null,"changelog":null,"pypi":null,"npm":"telegraf-session-sqlite","openapi_spec":null,"status_page":null,"smithery":null,"categories":["messaging"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}