An open API service indexing awesome lists of open source software.

https://github.com/s0ftik3/telegraf-userblock

Handling if user blocked the bot middleware for Telegraf.
https://github.com/s0ftik3/telegraf-userblock

bots telegraf telegram

Last synced: 5 months ago
JSON representation

Handling if user blocked the bot middleware for Telegraf.

Awesome Lists containing this project

README

          

# Telegraf User Block

[Telegraf (Telegram bot framework)](https://github.com/telegraf/telegraf) middleware that helps you to handle users who blocked your bot.

## Installation

```js
$ npm i telegraf-userblock
```

## Example

```js
const Telegraf = require('telegraf');
const userBlock = require('telegraf-userblock');

const bot = new Telegraf(process.env.TOKEN);

bot.use(
userBlock({
onUserBlock: (ctx, next, userId) => {
console.log('This user %s has blocked the bot.', userId);
return next();
},
})
);

bot.launch();
```

## API

### Options

- `onUserBlock`: action after some user blocked your bot.

```js
{
onUserBlock: (ctx, next, userId) => {
// ctx — current context
// next — go ahead after work of middleware's done
// userId — id of the user who blocked the bot, alternatively you could use ctx.update.my_chat_member.from.id
},
};
```