@grammyjs/router
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

Router middleware for grammY

Check out the official documentation for this plugin.

Quickstart

A router lets you specify a number of middlewares, each of them identified by a string key. You can then pass a routing function that decides based on the context which middleware to choose by returning one of the keys.

const router = new Router(ctx => {
  // determine route to pick here
  return 'key'
})

router.route('key',       ctx => { ... })
router.route('other-key', ctx => { ... })
router.otherwise(ctx => { ... }) // called if no route matches
bot.use(router)

If you use a custom context type for your bot, you need to pass it when constructing the Router instance, too.

const router = new Router<MyContext>(ctx => { ... })

Package Sidebar

Install

npm i @grammyjs/router

Weekly Downloads

187

Version

2.0.0

License

MIT

Unpacked Size

9.77 kB

Total Files

9

Last publish

Collaborators

  • knorpelsenf