Registry / communication / telegraf-mixpanel

telegraf-mixpanel

JSON →
library1.0.0jsnpmunverified

Mixpanel analytics middleware for the Telegraf Telegram bot framework. Current version 1.0.0. Provides a simple way to track events, set people properties, and manage charges directly from Telegraf context via `ctx.mixpanel`. Requires Telegraf v2 or v3. Lightweight wrapper around the Mixpanel Node.js library, designed for bot-specific analytics workflows like sales funnels. No breaking changes yet; limited to single Mixpanel instance per bot.

npm install telegraf-mixpanel
INSTALL
IMPORT
SIG · TELEGRAF-MIXPANEL
T
telegraf-mixpanel
communicationjavascriptv1.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ const TelegrafMixpanel = require('telegraf-mixpanel')
✗ import TelegrafMixpanel from 'telegraf-mixpanel'
CommonJS only. No default export; use require.
middleware
✓ const { middleware } = require('telegraf-mixpanel')
Named export for the middleware function.
type TelegrafMixpanel
✓ const TelegrafMixpanel = require('telegraf-mixpanel')
No TypeScript types provided.

Initializes Telegraf bot, attaches Mixpanel middleware, and tracks a 'start' event and people property on /start.

const Telegraf = require('telegraf'); const TelegrafMixpanel = require('telegraf-mixpanel'); const bot = new Telegraf(process.env.BOT_TOKEN ?? ''); const mixpanel = new TelegrafMixpanel(process.env.MIXPANEL_TOKEN ?? ''); bot.use(mixpanel.middleware()); bot.command('/start', (ctx) => { ctx.mixpanel.track('start', { source: 'telegram' }); ctx.mixpanel.people.set({ $name: ctx.from.first_name ?? '' }); return ctx.reply('Welcome!'); }); bot.launch();
Debug
Known issues
gotcha`ctx.mixpanel` is not available outside of middleware (e.g., in error handlers). The mixpanel object is attached only on handled updates.
fix
Ensure mixpanel usage is inside middleware chain where ctx has been processed.
affects: >=1.0.0
gotchaMixpanel Node library must be installed separately? Actually bundling: telegraf-mixpanel does not bundle mixpanel; it uses `require('mixpanel')` internally. If mixpanel is not installed, it will throw at runtime.
fix
Install mixpanel: `npm install mixpanel`.
affects: >=1.0.0
deprecatedTelegraf v2 and v3 are deprecated; newer Telegraf v4+ may not be compatible. The peer dep range `^2.0.0 || ^3.0.0` does not include v4.
fix
For Telegraf v4+, do not use this package; consider updating to a maintained fork.
affects: >=1.0.0
gotchaDefault export is a constructor, not mixpanel client itself. You must call `new TelegrafMixpanel(token)`.
fix
Correct usage: `const TelegrafMixpanel = require('telegraf-mixpanel'); const m = new TelegrafMixpanel(token);`
affects: >=1.0.0
gotcha`ctx.mixpanel` methods (track, people, etc.) are synchronous wrappers; errors are not handled. If Mixpanel token is invalid, calls may fail silently or throw.
fix
Ensure Mixpanel token is valid and handle errors with try/catch.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'mixpanel'
telegraf-mixpanel depends on mixpanel but does not list it as a dependency.
fix
Run `npm install mixpanel`.
TelegrafMixpanel is not a constructor
CommonJS require returns an object with a default property? Or wrong import style.
fix
Use `const TelegrafMixpanel = require('telegraf-mixpanel');` (not destructured).
TypeError: Cannot read property 'track' of undefined
`ctx.mixpanel` is undefined because middleware was not applied.
fix
Call `bot.use(mixpanel.middleware())` before using the bot.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
telegrafrequiredPeer dependency – provides bot context and middleware system
Agent activity
46 hits · last 30 days
node
40
OpenAI (training)
1
Resources
telegraf-mixpanel — npm install telegraf-mixpanel · libregistry