telegram_bot_api_sup (telegram_bot_api v2.9.0)

View Source

telegram_bot_api top level supervisor.

Summary

Functions

Start Http pool telegram bot

Start receive incoming updates using long polling

Start webhook

Types

child_id()

-type child_id() :: term().

Functions

init/1

start_link()

start_pool/1

-spec start_pool(#{name := telegram_bot_api:pool_name(),
                   token := binary(),
                   workers := integer(),
                   http_module => telegram_bot_api_http:module_name(),
                   http_endpoint => telegram_bot_api_http:http_endpoint(),
                   http_option => telegram_bot_api_http:http_option(),
                   http_timeout => telegram_bot_api_http:http_timeout(),
                   option_request => telegram_bot_api_http:option_request(),
                   http_proxy => telegram_bot_api_http:http_proxy(),
                   http_profile => atom()}) ->
                    supervisor:startchild_ret() | supervisor:startchild_err() | {error, term()}.

Start Http pool telegram bot

Parameters:

  • name - Unique http pool name, separate pool for each bot!
  • token - Bot token obtained from @BotFather, example: 1234556678:ABNFSERRTYUERYTYUurVGhgFrtyReWuthTW
  • workers - Count of workers, The worker is a module telegram_bot_api_server
  • http_module - Module for implementing HTTP requests, by default telegram_bot_api_http
  • http_endpoint - Url telegram api, by default https://api.telegram.org
  • http_option - HttpOption httpc:request, by default [{timeout,10000}, {ssl, [{verify, verify_none}]}]
  • http_timeout - Http timeout, by default 10000
  • option_request - OptionRequest for httpc:request

Examples:

     {ok, Pid} = telegram_bot_api_sup:start_pool(#{
       name=>pool_name_bot1,
       token=><<"1000000000:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQ">>
       workers=>1
 }).

start_update(Op)

-spec start_update(Op ::
                       #{id => child_id(),
                         name := Pool :: telegram_bot_api:pool_name(),
                         update_time := UpdateTime :: integer(),
                         offset := Offset :: integer(),
                         event := Event :: telegram_bot_api_app:event(),
                         limit => Limit :: integer(),
                         allowed_updates => AllowedUpdates :: [telegram_bot_api:update_type(), ...]}) ->
                      supervisor:startchild_ret() | supervisor:startchild_err().

Start receive incoming updates using long polling

Parameters:

  • name - Unique http pool name, separate pool for each bot!

Examples:

     {ok, Pid} = telegram_bot_api_sup:start_update(#{
               name=>bot1,
               update_time=>1000,
               offset=>0,
               limit=>100,
               allowed_updates=>[message,callback_query,channel_post],
               event=>server_event
         }).

start_webhook(Op)

Start webhook

Parameters:

  • secret_token - A secret token to be sent in a header X-Telegram-Bot-Api-Secret-Token in every webhook request, 1-256 characters.
  • bots - Maps bot
  • transport_opts - Maps contains the IP address and port for REST API webhook, use for set url webhook telegram_bot_api:setWebhook/3

Examples:

telegram_bot_api_sup:start_webhook(#{
                    id=>server_webhook,
                    secret_token=><<"WebhookSecretToken">>,
                    bots=>#{
                        <<"bot1">>=>#{
                                    event=>{global,bot_event_server1},
                                    name=>bot1
                                }
                            %%.. other bot
                    },
                    transport_opts=>#{
                        ip=>{0,0,0,0},
                        port=>8443,
                        certfile=>Certfile,
                        keyfile=>Keyfile,
                        verify=> verify_none
                    }
                    }).

stop_pool(Pool)

-spec stop_pool(Pool :: telegram_bot_api:pool_name()) -> ok | {error, term()}.

stop_update(Id)

-spec stop_update(Id :: child_id()) -> ok | {error, term()}.

stop_webhook(Id)

-spec stop_webhook(Id :: child_id()) -> ok | {error, term()}.