telegram_bot_captcha (telegram_bot_captcha v0.3.0)

View Source

Telegram CAPTCHA Bot Application

This application manages Telegram bots that use webhooks to implement CAPTCHA and anti-spam verification when users join chats.

Features:

  • Webhook server initialization and management
  • Dynamic bot registration and removal
  • Event handling via gen_event
  • Per-bot HTTP connection pools
  • User moderation (mute / ban)

Architecture:

  • application behaviour — entry point
  • gen_server — state management
  • supervisor — child process management
  • webhook server — receives Telegram updates

Configuration example (sys.config):

  {telegram_bot_captcha, [
    {webhook, #{
        ip => ~"0.0.0.0",
        port => 8443,
        secret_token => ~"secret",
        transport_opts => #{certfile => "..."}
    }},
    {bots, [BotConfig]}
  ]}.
  

Summary

Types

bot/0

-type bot() ::
          #{event := term(),
            name := bot_name(),
            set_webhook := boolean(),
            handlers := [handler()],
            pool => term(),
            options => term()}.

bot_name/0

-type bot_name() :: atom().

chat_id/0

-type chat_id() :: integer() | binary().

handler/0

-type handler() :: {module(), term()}.

minute/0

-type minute() :: non_neg_integer().

state/0

-type state() :: #{webhook_id := webhook_id(), webhook_param := webhook_param(), bots := [bot()]}.

user_id/0

-type user_id() :: integer().

webhook_id/0

-type webhook_id() :: term().

webhook_param/0

-type webhook_param() ::
          #{ip := binary() | string(),
            port := integer(),
            secret_token := binary(),
            transport_opts := map(),
            id => term()}.

Functions

add_bot(Bot)

-spec add_bot(bot()) -> term().

ban_chat_member(BotName, ChatId, UserId, Minute)

-spec ban_chat_member(bot_name(), chat_id(), user_id(), minute()) -> boolean().

code_change(OldVsn, State, Extra)

delete_bot(BotName)

-spec delete_bot(bot_name()) -> term().

delete_bots()

-spec delete_bots() -> term().

handle_call(Request, From, State)

handle_cast(Msg, State)

handle_info(Info, State)

init(_)

-spec init([map()]) -> {ok, state()}.

mute_chat_member(BotName, ChatId, UserId, Minute)

-spec mute_chat_member(bot_name(), chat_id(), user_id(), minute()) -> boolean().

start(StartType, StartArgs)

-spec start(application:start_type(), term()) -> {ok, pid(), map()} | {error, term()}.

start_link(P)

-spec start_link(map()) -> {ok, pid()} | {error, term()}.

stop(State)

-spec stop(map()) -> ok.

terminate(Reason, State)