Skip to content

iamwavecut/ngbot

Repository files navigation

🛡️ Telegram Chat Gatekeeper bot

Get rid of the unwanted spam joins out of the box

Demo

Join protection

  1. Join-time challenge is disabled as for now, due to being buggy, but will be back as option in the future.
  1. Triggered on the events, which introduces new chat members (invite, join, etc). Also works with join requests.
  2. Restrict newcomer to be read-only.
  3. Set up a challenge for the newcomer (join request), which is a simple task as shown on the image above, but yet, unsolvable for the vast majority of automated spam robots.
  4. If the newcomer succeeds in choosing the right answer - restrictions gets fully lifted, challenge ends.
  5. Otherwise - newcomer gets banned for 10 minutes (There is a "false-positive" chance, rememeber? Most robots aint coming back, anyway).
  6. If the newcomer struggles to answer in a set period of time (defaults to 3 minutes) - challenge automatically fails the same way, as in p.5.
  7. After the challenge bot cleans up all related messages, only leaving join notification for the newcomers, that made it. There are no traces of unsuccesful joins left, and that is awesome.

Spam protection

  1. Every chat member first message is being checked for spam using two approaches:
  • Known spammers DB lookup - checks if the message author is in the known spammers DB.
  • GPT-powered content analysis - asks GPT to analyze the message for harmful content.
  1. If the message is considered as spam - newcomer gets kick-banned.
  2. If the message is not considered as spam - user becomes a normal trusted chat member.

Installation

Quick Start with Docker Compose

  1. Create a bot via BotFather and enable group messages access.
  2. Clone the repository:
git clone https://github.com/iamwavecut/ngbot.git
cd ngbot
  1. Copy the example environment file and configure it:
cp .env.example .env
# Edit .env with your favorite editor and set required variables
  1. Start the bot:
docker compose up -d
  1. Add your bot to chat and give it Ban, Delete, and Invite permissions.
  2. Optional: Change bot language with /lang <code> (e.g., /lang ru).

Manual Installation

  1. Follow steps 1-3 from Quick Start.
  2. Build and run:
go mod download
go run .

Configuration

All configuration is done through environment variables. You can:

  • Set them in your environment
  • Use a .env file (recommended)
  • Pass them directly to docker compose or the binary

See .env.example for a quick reference of all available options.

Configuration Options

Required Variable name Description Default Options
✔️ NG_TOKEN Telegram BOT API token
✔️ NG_LLM_API_KEY OpenAI API key for content analysis
NG_LANG Default language to use in new chats en be, bg, cs, da, de, el, en, es, et, fi, fr, hu, id, it, ja, ko, lt, lv, nb, nl, pl, pt, ro, ru, sk, sl, sv, tr, uk, zh
NG_HANDLERS Enabled bot handlers admin,gatekeeper,reactor Comma-separated list of handlers
NG_LOG_LEVEL Logging verbosity 2 0=Panic, 1=Fatal, 2=Error, 3=Warn, 4=Info, 5=Debug, 6=Trace
NG_DOT_PATH Bot data storage path ~/.ngbot Any valid filesystem path
NG_LLM_API_MODEL OpenAI model to use gpt-4o-mini Any valid OpenAI model
NG_LLM_API_URL OpenAI API base URL https://api.openai.com/v1 Any valid OpenAI API compliant base URL
NG_LLM_API_TYPE API type openai openai, gemini
NG_FLAGGED_EMOJIS Emojis used for content flagging 👎,💩 Comma-separated list of emojis
NG_SPAM_LOG_CHANNEL_USERNAME Channel for spam logging Any valid channel username
NG_SPAM_VERBOSE Verbose in-chat notifications false true, false
NG_SPAM_VOTING_TIMEOUT Voting time limit 5m Any valid duration string
NG_SPAM_MIN_VOTERS Minimum required voters 2 Any positive integer
NG_SPAM_MAX_VOTERS Maximum voters cap 10 Any positive integer
NG_SPAM_MIN_VOTERS_PERCENTAGE Minimum voter percentage 5 Any positive float
NG_SPAM_SUSPECT_NOTIFICATION_TIMEOUT Suspect notification timeout 2m Any valid duration string

Troubleshooting

Don't hesitate to contact me

telegram linkedin

TODO

  • Individual chat's settings (behaviours, timeouts, custom welcome messages, etc).
  • Chat-specific spam filters.
  • Settings UI in private and/or web.

Feel free to add your requests in issues.

About

simple gatekeeper telegram bot

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published