Skip to content

Middleware for grammY. Use this to ensure only authorized Telegram IDs (admins or pro users) can use your bot.

License

Notifications You must be signed in to change notification settings

losparviero/grammyAccess

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grammYAccess

Access control middleware plugin for the 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
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.)
    }
})
  1. To only let admins access the bot
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, then open a PR.

License

MIT ©️ Zubin

About

Middleware for grammY. Use this to ensure only authorized Telegram IDs (admins or pro users) can use your bot.

Topics

Resources

License

Stars

Watchers

Forks