This traefik plugin allows you to define limits for incoming telegram messages based on the messages' IDs. Define exceptions for certain IDs with higher limits and to block certain IDs at all.
The following code snippet is a sample configuration for the dynamic file based provider, but this plugin works with all other configuration providers as well.
# config.ymlapi:dashboard: trueinsecure: true # do not use `insecure: true` in productionexperimental:plugins:traefik-telegram-ratelimiter:moduleName: github.com/bitzlato/traefik-telegram-ratelimiterversion: "v0.1.0"entryPoints:https:address: ":443"forwardedHeaders:insecure: trueproviders:file:filename: rules.yml# rules.ymlhttp:routers:my-router:entryPoints:- httpsmiddlewares:- tg-ratelimit- strip-webhookservice: tg-botrule: Path(`/webhook/tg-bot`)services:tg-bot:loadBalancer:servers:- url: http://tg-bot:8000middlewares:tg-ratelimit:plugin:traefik-telegram-ratelimiter:hitTableSize: 50000limit: 6000whitelistLimit: -1expire: 86400 # 24 hourswhitelist: "/srv/config/tg-bot/whitelist.ids"whitelistURL: "https://server.com/whitelist.ids"blacklist: "/srv/config/tg-bot/blacklist.ids"blacklistURL: "https://server.com/blacklist.ids"listPolling: 60console: trueconsoleAddress: ":8888"strip-webhook:stipPrefix:prefixes:- "/webhook/tg-bot"
This plugin supports the following configuration parameters:
50000
86400
(24 hours)expire
period. -1
means the limit is not applied. 0
-- no hits allowed at all. Default value: -1
(do not apply hit limit)whitelist
file. Has the same special cases as for the limit
parameter. Default value: -1
(do not apply hit limit)whitelistLimit
to. The file should contain each numeric ID on a separate line. Default value: nil
blacklist
file. Default: nil
nil
nil
0
(no periodic updates)/hits
-- returns hit table./hits/<tg id>
-- shows accumulated hits for the specified telegram id/hits/<tg id>
-- reset hits for the specified telegram id/list/(wl|bl)/<tg id>
-- check whether the telegram id is present in the list. Example: curl http://srv.com:8888/list/bl/123
/list/(wl|bl)/<tg id>
-- add the telegram id to the specified list/list/(wl|bl)/<tg id>
-- remove the telegram id from the specified list/limit
-- returns hit limit for regular ids/limit
-- set hit limit for regular ids. Example: curl http://srv.com:8888/limit -X PUT -d 20
/wllimit
-- returns hit limit for whitelisted ids/wllimit
-- set hit limit for whitelisted ids. Example: curl http://srv.com:8888/wllimit -X PUT -d -1