🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

grammyaccess

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grammyaccess

Access control middleware plugin for the grammY framework!

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

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

  • 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.)
    }
})
  • 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

  • Implement time based access
  • 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

Keywords

grammy

FAQs

Package last updated on 25 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts