telegram_bot_api_sup (telegram_bot_api v2.9.0)
View Sourcetelegram_bot_api top level supervisor.
Summary
Functions
Start Http pool telegram bot
Start receive incoming updates using long polling
Start webhook
Types
-type child_id() :: term().
Functions
-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:ABNFSERRTYUERYTYUurVGhgFrtyReWuthTWworkers- Count of workers, The worker is a moduletelegram_bot_api_serverhttp_module- Module for implementing HTTP requests, by defaulttelegram_bot_api_httphttp_endpoint- Url telegram api, by default https://api.telegram.orghttp_option- HttpOption httpc:request, by default[{timeout,10000}, {ssl, [{verify, verify_none}]}]http_timeout- Http timeout, by default10000option_request- OptionRequest for httpc:request
Examples:
{ok, Pid} = telegram_bot_api_sup:start_pool(#{
name=>pool_name_bot1,
token=><<"1000000000:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQ">>
workers=>1
}).
-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
}).
-spec start_webhook(Op :: #{id => child_id(), secret_token := telegram_bot_api:secret_token(), bots => telegram_bot_api_webhook_server:bots(), transport_opts := telegram_bot_api_webhook_server:transport_opts(), protocol_opts => telegram_bot_api_webhook_server:protocol_opts()}) -> supervisor:startchild_ret() | supervisor:startchild_err().
Start webhook
Parameters:
secret_token- A secret token to be sent in a headerX-Telegram-Bot-Api-Secret-Tokenin every webhook request, 1-256 characters.bots- Maps bottransport_opts- Maps contains the IP address and port for REST API webhook, use for set url webhooktelegram_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
}
}).
-spec stop_pool(Pool :: telegram_bot_api:pool_name()) -> ok | {error, term()}.