This library is a work in progress and in active development.
Supports Fastify versions 5.x
# npm
npm install fastify-grammy
# pnpm
pnpm install fastify-grammy
Import fastify-grammy
and register.
import Fastify from 'fastify'
import { fastifyGrammy } from 'fastify-grammy'
const fastify = Fastify()
fastify.register(fastifyGrammy, {
token: 'your-tg-bot-token'
})
fastify.listen({ port: 3000 })
Before using fastify-grammy
, make sure to check the Grammy documentation for more information about how to create and configure a Telegram bot.
You can use middlewares with fastify-grammy
by passing them in the options object when registering the plugin.
import { session } from 'grammy'
fastify.register(fastifyGrammy, {
token: 'your-tg-bot-token',
middlewares: [session()]
})
To use fastify-grammy
with TypeScript, you need to extend the Fastify instance with the FastifyGrammyBot type.
Here's an example for a single instance:
import type { FastifyGrammyBot } from 'fastify-grammy'
declare module 'fastify' {
interface FastifyInstance {
grammy: FastifyGrammyBot
}
}
And here's an example for multiple instances:
import type { FastifyGrammyBot } from 'fastify-grammy'
declare module 'fastify' {
interface FastifyInstance {
grammy: {
one: FastifyGrammyBot
two: FastifyGrammyBot
}
}
}
This library is based on the Grammy library.
Licensed under MIT.