Skip to content

Client

class Tourmaline::Client
inherits Reference #

The Client class is the base class for all Tourmaline based bots. Extend this class to create your own bots, or create an instance of Client and add event handlers to it.

Included modules#

Tourmaline::Client::CoreMethods Tourmaline::Client::GameMethods Tourmaline::Client::PassportMethods Tourmaline::Client::PaymentMethods Tourmaline::Client::PollMethods Tourmaline::Client::StickerMethods Tourmaline::Client::WebhookMethods Tourmaline::EventHandler::Annotator Tourmaline::Logger

Constants#

DEFAULT_API_URL = "https://api.telegram.org/" #

Log = ::Log.for("tourmaline.client") #

Class methods#

.new(api_key : String, endpoint = DEFAULT_API_URL, *, persistence : Persistence = NilPersistence.new, allowed_updates = [] of String, set_commands = false, default_parse_mode : ParseMode = ParseMode::Markdown, pool_capacity = 200, initial_pool_size = 20, pool_timeout = 0.1, proxy = nil, proxy_uri = nil, proxy_host = nil, proxy_port = nil, proxy_user = nil, proxy_pass = nil) #

Create a new instance of Tourmaline::Client.

Positional Arguments##
api_key
required; the bot token you were provided with by @BotFather
endpoint
the Telegram bot API endpoint to use; defaults to https://api.telegram.org
Named Arguments##
persistence
the persistence strategy to use
set_commands
if true, set_my_commands will be run on start and any commands marked with register will be registered with BotFather.
pool_capacity
the maximum number of concurrent HTTP connections to use
initial_pool_size
the number of HTTP::Client instances to create on init
pool_timeout
How long to wait for a new client to be available if the pool is full before throwing a TimeoutError
proxy
an instance of HTTP::Proxy::Client to use; if set, overrides the following proxy_ args
proxy_uri
a URI to use when connecting to the proxy; can be a URI instance or a String
proxy_host
if no proxy_uri is provided, this will be the host for the URI
proxy_port
if no proxy_uri is provided, this will be the port for the URI
proxy_user
a username to use for a proxy that requires authentication
proxy_pass
a password to use for a proxy that requires authentication

Methods#

#add_event_handler(handler : EventHandler) #

Add an EventHandler instance to the handler stack

#allowed_updates : Array(String) #

#allowed_updates=(allowed_updates : Array(String)) #

#bot #

Gets the name of the Client at the time the Client was started. Refreshing can be done by setting @bot to get_me.

#default_parse_mode : ParseMode #

Default parse mode to use for commands when it isn't included explicitly

#default_parse_mode=(default_parse_mode : ParseMode) #

Default parse mode to use for commands when it isn't included explicitly

#handle_update(update : Update) #

Calls all handlers in the stack with the given update and this client instance.

#remove_event_handler(handler : EventHandler) #

Remove an existing event handler from the stack

#send_menu(chat, menu : RoutedMenu, **kwargs) #