Git Product home page Git Product logo

tg-captcha-bot's Introduction

Go Report Card Version GitHub tag (latest by date) GitHub closed issues GitHub contributors GitHub All Releases Docker Pulls

Telegram Captcha Bot

Telegram bot that validates new users that enter supergroup. Validation works like a simple captcha. Bot written in Go (Golang).

This bot has been tested on several supergroups (2000+ people) for a long time and has shown its effectiveness against spammers.

Cloud hosted instance of the bot

@cloud_tg_captcha_bot

How it works

  1. Add the bot to your supergroup
  2. Promote the bot for administrator privileges
  3. A new user enters your supergroup
  4. Bot restricts the user's ability to send messages
  5. Bot shows a welcome message and a captcha button to the user
  6. If the user doesn't press the button within 30 seconds then the user is banned by the bot

If you want to run your own instance of the bot

Commands

/healthz - check that the bot is working correctly

Сustomization

You can change several bot's settings (welcome message, ban duration, socks5 proxy server) through the configuration file config.toml

Alternatives / Forks

tg-captcha-bot's People

Contributors

aprosvetova avatar berkus avatar darwinnn avatar denisgolius avatar dependabot[bot] avatar mxssl avatar tobiasmuehl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tg-captcha-bot's Issues

hey there

Can you PLEASE dont write this in the bot API and I can possibly donate to you.

A lot of groups want this PM-Only and that's not allowed through the BOT API.

Only Telegram/Telethon API

Enchacement: .env, config, multiple buttons (ban, dummy, approve)

I want to offer to add multiple buttons to prevent spam (buttons may be shuffle). I can do a PR, but it's better if u looking for my forked repository, cause i'm not a familiar with go yet (one day of research)

photo_2020-01-27_18-55-21

First one will ban a user at once, the second one is dummy, and the third one is to approve user.

Also to use .env to store bot token and use config.toml.example to get updates with out any problems.

A contact to appeal

When a user failed to click the button, there should be a possibility to contact someone for an appeal.

wrong

Soory, wrong request.

Help: How to import golang.org/x/net/proxy to use it with tcp socks5?

Hello, need some help. I'm not familar with go, sorry for my question.

I've try to add "golang.org/x/net/proxy"

package main

import (
        "log"
        "os"
        "os/signal"
        "regexp"
        "strconv"
        "sync"
        "syscall"
        "time"

        "github.com/pkg/errors"
        "github.com/spf13/viper"
        tb "gopkg.in/tucnak/telebot.v2"
        "golang.org/x/net/proxy"
)

To use it with SOCKS5

func main() {
        token, e := getToken(tgtoken)
        if e != nil {
                log.Fatalln(e)
        }
        log.Printf("Telegram Bot Token [%v] successfully obtained from env variable $TGTOKEN\n", token)

        dialer, err := proxy.SOCKS5("tcp", "host:port", &proxy.Auth{User: "anon", Password:"anon"}, proxy.Direct)
	if err != nil {
		t.Fatal("Error creating dialer, aborting.")
	}

	// setup a http client
	httpTransport := &http.Transport{}
	httpClient := &http.Client{Transport: httpTransport}
	httpTransport.Dial = dialer.Dial

        var err error
        bot, err = tb.NewBot(tb.Settings{
                Token:  token,
                Poller: &tb.LongPoller{Timeout: 10 * time.Second},
                Client: httpClient
        })

And getting this error during docker-compose build. Cant google for it solution

root@honda:/var/www/tg-captcha-bot# docker-compose build
Building tg-captcha-bot
Step 1/12 : FROM golang:1.13.4-alpine3.10 as builder
 ---> 3024b4e742b0
Step 2/12 : ENV GO111MODULE=on
 ---> Using cache
 ---> e032ddee3b2b
Step 3/12 : WORKDIR /go/src/github.com/mxssl/tg-captcha-bot
 ---> Using cache
 ---> c2d3321ebe20
Step 4/12 : COPY . .
 ---> Using cache
 ---> 674d3ed6621e
Step 5/12 : RUN apk add --no-cache   ca-certificates   curl   git
 ---> Running in 7600296a5c01
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz
(1/6) Installing nghttp2-libs (1.39.2-r0)
(2/6) Installing libcurl (7.66.0-r0)
(3/6) Installing curl (7.66.0-r0)
(4/6) Installing expat (2.2.8-r0)
(5/6) Installing pcre2 (10.33-r0)
(6/6) Installing git (2.22.2-r0)
Executing busybox-1.30.1-r2.trigger
OK: 21 MiB in 21 packages
Removing intermediate container 7600296a5c01
 ---> 2ad7a165cbc9
Step 6/12 : RUN CGO_ENABLED=0   GOOS=`go env GOHOSTOS`   GOARCH=`go env GOHOSTARCH`   go build -v -mod=vendor -o bot
 ---> Running in b3b9270cd7bc
build github.com/mxssl/tg-captcha-bot: cannot load golang.org/x/net/proxy: open /go/src/github.com/mxssl/tg-captcha-bot/vendor/golang.org/x/net/proxy: no such file or directory
ERROR: Service 'tg-captcha-bot' failed to build: The command '/bin/sh -c CGO_ENABLED=0   GOOS=`go env GOHOSTOS`   GOARCH=`go env GOHOSTARCH`   go build -v -mod=vendor -o bot' returned a non-zero code: 1

No updates on chat join

The problem is that the bot does not receive any updates when user joins my supergroup (> 20k users). I used another smaller group for testing and everything was fine there.

In BotApi doc it says that for getUpdates method "chat_member" should be specified in allowed_updates field in order to receive this update type.

Am I doing something wrong or this is expected behaviour for supergroup of this size?

Enhancement: remove failed validation notification after timeout

Our chat group has recently been hit by a spam bot wave (30+ and counting at the moment), and while this bot works perfectly fine against them, unfortunately it doesn't clean up after itself, resulting in a humongous wall of "User didn't pass the validation and was banned." messages. It'd be great if @cloud_tg_captcha_bot or on-prem instance could clean up after itself, with 30 minutes timeout by default, or even configurable, if it's easy to implement.

Service crashes with /getUpdates:EOF

Hi,

Just got this from the logs:

Feb 19 13:21:18 tg-captcha-bot[15469]: 2021/02/19 13:21:18 Post https://api.telegram.org/<redacted>:<redacted>/getUpdates: EOF
Feb 19 13:21:18 tg-captcha-bot[15469]: telebot
Feb 19 13:21:18 tg-captcha-bot[15469]: gopkg.in/tucnak/telebot%2ev2.wrapError
Feb 19 13:21:18 tg-captcha-bot[15469]:         /home/helio/go/pkg/mod/gopkg.in/tucnak/[email protected]/util.go:46
Feb 19 13:21:18 tg-captcha-bot[15469]: gopkg.in/tucnak/telebot%2ev2.(*Bot).Raw
Feb 19 13:21:18 tg-captcha-bot[15469]:         /home/helio/go/pkg/mod/gopkg.in/tucnak/[email protected]/api.go:32
Feb 19 13:21:18 tg-captcha-bot[15469]: gopkg.in/tucnak/telebot%2ev2.(*Bot).getUpdates
Feb 19 13:21:18 tg-captcha-bot[15469]:         /home/helio/go/pkg/mod/gopkg.in/tucnak/[email protected]/api.go:219
Feb 19 13:21:18 tg-captcha-bot[15469]: gopkg.in/tucnak/telebot%2ev2.(*LongPoller).Poll
Feb 19 13:21:18 tg-captcha-bot[15469]:         /home/helio/go/pkg/mod/gopkg.in/tucnak/[email protected]/poller.go:100
Feb 19 13:21:18 tg-captcha-bot[15469]: runtime.goexit
Feb 19 13:21:18 tg-captcha-bot[15469]:         /usr/lib/go-1.13/src/runtime/asm_amd64.s:1357
Feb 19 13:21:18 tg-captcha-bot[15469]: gopkg.in/tucnak/telebot%2ev2.(*Bot).debug
Feb 19 13:21:18 tg-captcha-bot[15469]:         /home/helio/go/pkg/mod/gopkg.in/tucnak/[email protected]/util.go:14
Feb 19 13:21:18 tg-captcha-bot[15469]: gopkg.in/tucnak/telebot%2ev2.(*LongPoller).Poll
Feb 19 13:21:18 tg-captcha-bot[15469]:         /home/helio/go/pkg/mod/gopkg.in/tucnak/[email protected]/poller.go:102
Feb 19 13:21:18 tg-captcha-bot[15469]: runtime.goexit
Feb 19 13:21:18 tg-captcha-bot[15469]:         /usr/lib/go-1.13/src/runtime/asm_amd64.s:1357
Feb 19 13:21:18 tg-captcha-bot[15469]: 2021/02/19 13:21:18 telebot: could not fetch new updates
Feb 19 13:21:18 tg-captcha-bot[15469]: gopkg.in/tucnak/telebot%2ev2.init
Feb 19 13:21:18 tg-captcha-bot[15469]:         /home/helio/go/pkg/mod/gopkg.in/tucnak/[email protected]/telebot.go:36
Feb 19 13:21:18 tg-captcha-bot[15469]: runtime.doInit
Feb 19 13:21:18 tg-captcha-bot[15469]:         /usr/lib/go-1.13/src/runtime/proc.go:5222
Feb 19 13:21:18 tg-captcha-bot[15469]: runtime.doInit
Feb 19 13:21:18 tg-captcha-bot[15469]:         /usr/lib/go-1.13/src/runtime/proc.go:5217
Feb 19 13:21:18 tg-captcha-bot[15469]: runtime.main
Feb 19 13:21:18 tg-captcha-bot[15469]:         /usr/lib/go-1.13/src/runtime/proc.go:190
Feb 19 13:21:18 tg-captcha-bot[15469]: runtime.goexit
Feb 19 13:21:18 tg-captcha-bot[15469]:         /usr/lib/go-1.13/src/runtime/asm_amd64.s:1357
Feb 19 13:21:18 tg-captcha-bot[15469]: gopkg.in/tucnak/telebot%2ev2.(*Bot).debug
Feb 19 13:21:18 tg-captcha-bot[15469]:         /home/helio/go/pkg/mod/gopkg.in/tucnak/[email protected]/util.go:14
Feb 19 13:21:18 tg-captcha-bot[15469]: gopkg.in/tucnak/telebot%2ev2.(*LongPoller).Poll
Feb 19 13:21:18 tg-captcha-bot[15469]:         /home/helio/go/pkg/mod/gopkg.in/tucnak/[email protected]/poller.go:103
Feb 19 13:21:18 tg-captcha-bot[15469]: runtime.goexit
Feb 19 13:21:18 tg-captcha-bot[15469]:         /usr/lib/go-1.13/src/runtime/asm_amd64.s:1357
Feb 19 14:18:00 tg-captcha-bot[15469]: 2021/02/19 14:18:00 Shutdown signal received, exiting...

Since it didn't really died at 13:21:18, I had to manually restart the service at 14:18:00. It is running on systemd.

Update Docker Build & Publish and add ARM image

Example
Result

name: Build & Push Docker Images

on:
  workflow_dispatch:
    inputs:
      version:
        description: "Version"
        required: true

jobs:
  build_and_push:
    name: "Build & Push"
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./
    timeout-minutes: 60
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Log in to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKER_HUB_USERNAME }}
          password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

      - name: Build and push image
        uses: docker/build-push-action@v4
        with:
          context: .
          file: ./Dockerfile
          platforms: linux/arm64, linux/amd64
          push: true
          tags: ${{ secrets.DOCKER_HUB_USERNAME }}/tg-captcha-bot:latest, ${{ secrets.DOCKER_HUB_USERNAME }}/tg-captcha-bot:${{ github.event.inputs.version }}

Feature Request: Multi-Message captcha

Hello! I would like to be able to add this to multiple chats and set a welcome message custom to each chat to show off the website for each chat or events specific to that chat without having to create 30 different bots for all of our chats

Отключить "Добро пожаловать!"

Когда много человек заходит в чат, несколько экранов чата зафлужено этим сообщением, можно ли убрать это сообщение совсем?

Increase response duration

I think 30 seconds is a bit low for the default duration. Would it be possible to increase it to 1 minute?

(I know I can host the bot myself, but this way I don't have to set it up and waste energy on running a server just for this)

уязвимость с разбаном

когда кого то банят в чате в режим только чтение (например пользователю ограничены стикеры, написание сообщений, но он может читать группу), ему достаточно перевойти в чат, чтобы бот его разбанил в полный доступ через свой механизм, надо вам что-то поправить, чтобы если пользователь уже забанен в группе, чтобы бот его не трогал.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.