Socket
Socket
Sign inDemoInstall

puregram-redis-storage

Package Overview
Dependencies
23
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    puregram-redis-storage

✈️ Redis storage for @puregram/session module


Version published
Weekly downloads
7
decreased by-30%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

puregram-redis-storage

NPM version NPM downloads

✈️ Redis storage for @puregram/session module

Powered by ioredis
Based on vk-io-redis-storage

Installation

yarn add puregram-redis-storage
npm i puregram-redis-storage

Example usage

const { Telegram } = require('puregram');
const { SessionManager } = require('@puregram/session');
const { RedisStorage } = require('puregram-redis-storage');

const telegram = Telegram.fromToken(process.env.TOKEN);

function startBot({ updates }) {
  const storage = new RedisStorage({
    // redis: ioRedisClient,
    redis: {
      host: '127.0.0.1',
      port: 6379
    },
    keyPrefix: 'puregram:session:'
    // ttl: 12 * 3600
  });

  const sessionManager = new SessionManager({
    storage,
    getStorageKey: (context) => `${context.chat.id}:${context.from?.id ?? 0}`
  });

  updates.on('message', sessionManager.middleware);

  updates.on('message', (context, next) => {
    if (context.text !== '/counter') {
      return next();
    }
    if (context.isOutbox) return;

    const { session } = context;

    session.counter = (session.counter || 0) + 1;

    context.send(`You turned to the bot (${session.counter}) times`);
  });

  updates.startPolling().catch(console.error);
}

// ...
startBot(telegram);

Keywords

FAQs

Last updated on 19 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc