Telegram Bot CAPTCHA

Telegram CAPTCHA Bot is an Erlang/OTP application for managing Telegram bots that protect chats from spam using CAPTCHA verification.

The application uses webhooks, supports multiple bots, and provides moderation tools such as muting and banning users.

ErlangHex Version


โœจ Features


๐Ÿ“ฅ Installation

The package can be installed by adding telegram_bot_captcha to your list of dependencies in rebar.config:

{deps, [telegram_bot_captcha]}.

โš™๏ธ Configuration

Configure the application in sys.config:

{telegram_bot_captcha,[
    {webhook,#{
         %% public IP address where webhook data will be received
        ip => <<"1.1.1.1">>,
        %% port of the public IP
        port => 80,
        %% webhook URL is formed from IP and port
        %% secret token for verification sent by Telegram in webhook headers
        %% see (https://core.telegram.org/bots/api#setwebhook)
        secret_token => <<"secret">>,
        %% transport settings
        transport_opts => #{
            %% which IP to bind the HTTP server to
            ip => {0,0,0,0},
            %% certificate, see (https://core.telegram.org/bots/self-signed)
            %% you can generate a self-signed certificate
            %% example: openssl req -newkey rsa:2048 -sha256 -nodes -keyout YOURPRIVATE.key -x509 -days 365 -out YOURPUBLIC.pem -subj "/C=US/ST=New York/L=Brooklyn/O=Example Brooklyn Company/CN=1.1.1.1"
            certfile => <<"/etc/telegram_bot_captcha/ssl/YOURPUBLIC.pem">>,
            keyfile => <<"/etc/telegram_bot_captcha/ssl/YOURPRIVATE.key">>,
            %% disable verification for self-signed certificates
            verify => verify_none,
            fail_if_no_peer_cert => false,
            log_level => none
            }
        }},
        {bots, [
        #{
            name => my_bot,
            event => my_bot_event,
            set_webhook => true,
            handlers => [
                {my_handler, #{}}
            ]
        }
    ]}
]}

๐Ÿš€ Starting the Application

application:start(telegram_bot_captcha).

On startup:

๐Ÿค– Bot Configuration

Each bot is defined as:

#{
    name := atom(), %Bot identifier
    event := term(), %Event process (gen_event)
    set_webhook := boolean(), %Whether to register webhook in Telegram
    handlers := [{Module, Options}] %List of event handlers
}

๐Ÿ“ก API

Add Bot

telegram_bot_captcha:add_bot(Bot).

Delete Bot

telegram_bot_captcha:delete_bot(BotName).

Delete All Bots

telegram_bot_captcha:delete_bots().

๐Ÿ”’ Moderation API

Mute User

telegram_bot_captcha:mute_chat_member(BotName, ChatId, UserId, Minutes).

Ban User

telegram_bot_captcha:ban_chat_member(BotName, ChatId, UserId, Minutes).

๐Ÿฆ„ Handler

telegram_bot_captcha_math_handler
telegram_bot_captcha_port_handler

๐Ÿงช Example

Example config/sys.config
Example captcha.php for telegram_bot_captcha_port_handler

๐Ÿ“Œ Other