{"id":19873686,"url":"https://github.com/mediv0/telegram-rate-limiter","last_synced_at":"2025-06-29T10:35:27.828Z","repository":{"id":57683011,"uuid":"475849130","full_name":"mediv0/telegram-rate-limiter","owner":"mediv0","description":"dead simple rate limiter for telegram bots with typescript support.","archived":false,"fork":false,"pushed_at":"2023-12-16T20:29:49.000Z","size":81,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-10-29T07:21:25.627Z","etag":null,"topics":["rate-limiter","telegram","telegram-bot","telegrambot"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mediv0.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-30T11:33:12.000Z","updated_at":"2024-09-16T11:23:28.000Z","dependencies_parsed_at":"2022-09-15T18:10:42.159Z","dependency_job_id":null,"html_url":"https://github.com/mediv0/telegram-rate-limiter","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mediv0%2Ftelegram-rate-limiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mediv0%2Ftelegram-rate-limiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mediv0%2Ftelegram-rate-limiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mediv0%2Ftelegram-rate-limiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mediv0","download_url":"https://codeload.github.com/mediv0/telegram-rate-limiter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224305960,"owners_count":17289542,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rate-limiter","telegram","telegram-bot","telegrambot"],"created_at":"2024-11-12T16:19:30.328Z","updated_at":"2024-11-12T16:19:31.697Z","avatar_url":"https://github.com/mediv0.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Telegram Rate Limiter\n\ndead simple rate limiter for telegram bots with typescript support.\n\ncan be used to limit the number of messages sent by a user, using a token bucket algorithm. works fine with both telegraf and Telegram-Bot-API packages.\n\nSupported Drivers:\n\n-   Memory ( development only )\n-   Redis ( Production )\n\nadding other drivers is not supported yet. ( will be soon )\n\n## Install\n\n```\nyarn add @mediv0/rate-limit\n```\nor\n```\nnpm install @mediv0/rate-limit\n```\n\n## usage example\n\n```js\nimport { Limiter } from \"@mediv0/rate-limit\";\n\n// init\nconst limiter = new Limiter(\"memory\", {\n    interval: 10,\n    max: 5,\n    driverOptions: {},\n});\n\n// Telegram-Bot-API example\nbot.on(\"message\", async (msg) =\u003e {\n    try {\n        const userId = msg.chat.id;\n        await limiter.limit(userId);\n        bot.sendMessage(chatId, \"Hello World!\");\n    } catch (e) {\n        // catch rate limit errors\n    }\n});\n```\n\n## Options\n\n`Limiter\u003cK extends keyof driver\u003e`\n\n#### class Limiter (driver: `K`, options: `ILimiterOptions\u003cdriver[K]\u003e`)\n\n**driver** -\u003e `memory` | `redis`\n\n**ILimiterOptions** -\u003e\n\n```\n{\n    max: number;   // maximum number of messages allowed in the interval\n    interval: number; // interval in minutes e.g -\u003e 2\n    driverOptions: T; // driver specific options\n}\n```\n\nfor example, in snipet below, a user can send maximum 100 messages in interval of 5 minutes. if the user sends more than 100 messages, the limiter will throw an error.\n\n```js\nconst limiter = new Limiter(\"memory\", {\n    interval: 5,\n    max: 100,\n    driverOptions: {},\n});\n```\n\n### Redis Driver\n\ndriver used in this packages is from [npm redis](https://www.npmjs.com/package/redis)\n\nyou can pass options used in redis package to rate limiter.\n\n**[list of redis options](https://github.com/redis/node-redis/blob/HEAD/docs/client-configuration.md)**\n\n```js\nlimiter = new Limiter(\"redis\", {\n    interval: 10,\n    max: 5,\n    driverOptions: {\n        url: \"redis://localhost:6379\",\n        name: \"test\",\n        password: \"test\",\n        legacyMode: false,\n        // other options\n    },\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmediv0%2Ftelegram-rate-limiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmediv0%2Ftelegram-rate-limiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmediv0%2Ftelegram-rate-limiter/lists"}