Skip to content

Commit

Permalink
docs: add middleware examples/add grammy docs links
Browse files Browse the repository at this point in the history
  • Loading branch information
blasdfaa committed Nov 11, 2024
1 parent 0a7ff06 commit e303d55
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Supports Fastify versions `5.x`

## Install

```
```bash
# npm
npm install fastify-grammy

Expand All @@ -36,19 +36,42 @@ fastify.register(fastifyGrammy, {
fastify.listen({ port: 3000 })
```

Before using `fastify-grammy`, make sure to check the [Grammy](https://grammy.dev/guide/getting-started) documentation for more information about how to create and configure a Telegram bot.

## Middlewares

You can use middlewares with `fastify-grammy` by passing them in the options object when registering the plugin.

```ts
import { session } from 'grammy'

fastify.register(fastifyGrammy, {
token: 'your-tg-bot-token',
middlewares: [session()]
})
```

## Using with TypeScript

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:

```ts
import type { FastifyGrammyBot } from 'fastify-grammy'

// for single instance
declare module 'fastify' {
interface FastifyInstance {
grammy: FastifyGrammyBot
}
}
```

And here's an example for multiple instances:

```ts
import type { FastifyGrammyBot } from 'fastify-grammy'

// for multiple instances
declare module 'fastify' {
interface FastifyInstance {
grammy: {
Expand All @@ -61,6 +84,8 @@ declare module 'fastify' {

## Acknowledgements

This library is based on the [Grammy](https://grammy.dev) library.

## License

Licensed under [MIT](./LICENSE).<br/>
Licensed under [MIT](./LICENSE).

0 comments on commit e303d55

Please sign in to comment.