Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/losparviero/grammyaccess
Middleware for grammY. Use this to ensure only authorized Telegram IDs (admins or pro users) can use your bot.
https://github.com/losparviero/grammyaccess
grammy grammy-plugin grammyjs telegram telegram-bot telegram-node
Last synced: 2 days ago
JSON representation
Middleware for grammY. Use this to ensure only authorized Telegram IDs (admins or pro users) can use your bot.
- Host: GitHub
- URL: https://github.com/losparviero/grammyaccess
- Owner: losparviero
- License: mit
- Created: 2023-07-22T07:28:17.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-25T14:35:58.000Z (about 1 year ago)
- Last Synced: 2024-11-11T10:44:42.309Z (4 days ago)
- Topics: grammy, grammy-plugin, grammyjs, telegram, telegram-bot, telegram-node
- Language: JavaScript
- Homepage: https://www.npmjs.com/grammyaccess
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# grammYAccess
Access control middleware plugin for the [grammY](https://github.com/grammyjs/grammy) framework!
### Features
Middleware for grammY which lets you implement separate logic for admins or paid/pro users.
Use this to ensure only authorized Telegram IDs (admins) can use your bot or certain features.
### Usage
Copy the plugin code from ```access.js``` and use it in your grammY project.
Messages sent to your bot are checked against user IDs in admin or pro user list.
Implement separate logic for admins and pro users.
### Example
1. To only let paid users access the bot
```node
bot.on("message" => (ctx){
if (ctx.config.isPro) {
ctx.reply("Hello đ You are a Pro user.")
} else {
ctx.reply ("Please subscribe to a paid plan to use the bot.)
}
})
```2. To only let admins access the bot
```node
bot.on("message" => (ctx){
if (ctx.config.isAdmin) {
ctx.reply("Hello đ You are an admin.")
} else {
ctx.reply ("You are unauthorized to use the bot.")
}
})
```_Note: The admin or pro user list is stored in env_
### Future
1. Implement time based access
2. Replace env management of access list to db_Note: 'Admin' here only refers to the list of Telegram IDs included in the env. It has nothing to do with group admins or any other._
### Contribute
If you'd like to contribute to the project, please read grammY's [guide to plugins](https://grammy.dev/plugins/guide.html), then open a PR.
### License
MIT Šī¸ Zubin