npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@puregram/scenes

v2.0.1

Published

Simple implementation of middleware-based scene management for puregram

Readme

@puregram/scenes

simple implementation of middleware-based scene management for puregram package

introduction

@puregram/scenes helps you to organize step-by-step handler by providing you needed classes and methods

example

const { Telegram } = require('puregram')

// @puregram/scenes requires @puregram/session
const { SessionManager } = require('@puregram/session')
const { SceneManager, StepScene } = require('@puregram/scenes')

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

const sessionManager = new SessionManager()
const sceneManager = new SceneManager()

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

telegram.updates.on('message', sceneManager.middleware)
telegram.updates.on('message', sceneManager.middlewareIntercept) // default scene entry handler

telegram.updates.on('message', (context) => {
  if (/^\/signup$/i.test(context.text)) {
    return context.scene.enter('signup')
  }
})

sceneManager.addScenes([
  new StepScene('signup', [
    (context) => {
      if (context.scene.step.firstTime || !context.hasText()) {
        return context.send('what\'s your name?')
      }

      context.scene.state.firstName = context.text

      return context.scene.step.next()
    },

    (context) => {
      if (context.scene.step.firstTime || !context.hasText()) {
        return context.send('how old are you?')
      }

      context.scene.state.age = Number.parseInt(context.text, 10)

      return context.scene.step.next()
    },

    async (context) => {
      const { firstName, age } = context.scene.state

      await context.send(`you are ${firstName} ${age} years old!`)

      // automatic exit since this is the last scene
      return context.scene.step.next()
    }
  ])
])

telegram.updates.startPolling()

installation

$ yarn add @puregram/scenes
$ npm i -S @puregram/scenes

typescript usage

you can tell @puregram/scenes about actual context type by providing it in the StepScene<T>:

import { CallbackQueryContext } from 'puregram'

new StepScene<CallbackQueryContext>('foo', [])

also, you can change context type on the fly simply by providing new type to the context variable:

import { CallbackQueryContext, MessageContext } from 'puregram'

new StepScene('bar', [
  (context: CallbackQueryContext) => {},
  (context: MessageContext) => {}
])

list of methods & getters

context.scene

step

returns: SceneInterface | undefined

returns current scene step

enter(slug, options?)

returns: Promise<void>

enters to another scene by slug

context.scene.enter('signup')

leave(options?)

returns: Promise<void>

leaves from current scene

context.scene.leave()

reenter()

returns: Promise<void>

reenters into current scene

context.scene.reenter()

reset()

returns: void

resets current scene (deletes it)

context.scene.step

firstTime

returns: boolean

returns true if this entry is the first entry in this scene

if (context.scene.step.firstTime) { /* ... */ }

stepId

returns: number

returns current step ID

current

returns: StepSceneHandler | undefined

returns current step handler

reenter()

returns: Promise<void>

reenters into current step handler

if (value.invalid) {
  return context.scene.step.reenter()
}

go(stepId, options?)

returns: Promise<void>

goes to a specific step by stepId

context.scene.step.go(0)

next(options?)

returns: Promise<void>

goes to the next step

context.scene.step.next()

previous(options?)

returns: Promise<void>

goes to the previous step

context.scene.step.previous()