class Tourmaline::Client
- Tourmaline::Client
- Reference
- Object
Overview
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::TDLightMethods
- Tourmaline::Client::WebhookMethods
- Tourmaline::EventHandler::Annotator
- Tourmaline::Logger
Defined in:
tourmaline/client.crtourmaline/client/core_methods.cr
tourmaline/client/game_methods.cr
tourmaline/client/passport_methods.cr
tourmaline/client/payment_methods.cr
tourmaline/client/poll_methods.cr
tourmaline/client/sticker_methods.cr
tourmaline/client/tdlight_methods.cr
tourmaline/client/webhook_methods.cr
tourmaline/extra/paginated_keyboard.cr
tourmaline/extra/routed_menu.cr
Constant Summary
-
DEFAULT_API_URL =
"https://api.telegram.org/"
-
DEFAULT_COMMAND_PREFIXES =
["/"]
Constructors
-
.new(*, bot_token : String | Nil = nil, user_token : String | Nil = nil, endpoint : String = DEFAULT_API_URL, persistence : Persistence = NilPersistence.new, set_commands : Bool = false, 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
.
Class Method Summary
-
.default_command_prefixes : Array(String)
Default prefixes to use for commands
-
.default_command_prefixes=(default_command_prefixes : Array(String))
Default prefixes to use for commands
-
.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
Instance Method Summary
-
#add_event_handler(handler : EventHandler)
Add an
EventHandler
instance to the handler stack -
#bot : User
Gets the name of the Client at the time the Client was started.
-
#bot? : User | Nil
Gets the name of the Client at the time the Client was started.
- #bot_token : String | Nil
- #bot_token=(bot_token : String | Nil)
- #event_handlers : Array(EventHandler)
-
#handle_update(update : Update)
Calls all handlers in the stack with the given update and this client instance.
- #middlewares : Array(Middleware)
- #persistence : Persistence
-
#remove_event_handler(handler : EventHandler)
Remove an existing event handler from the stack
- #send_menu(chat, menu : RoutedMenu, **kwargs)
- #send_paginated_keyboard(chat, keyboard : PaginatedKeyboard, **kwargs)
- #use(middleware : Middleware)
- #user_token : String | Nil
- #user_token=(user_token : String | Nil)
Instance methods inherited from module Tourmaline::Client::TDLightMethods
delete_messages(chat, start_id, end_id)
delete_messages,
get_memory_stats
get_memory_stats,
get_participants(chat)
get_participants,
login(phone_number)
login,
optimize_memory
optimize_memory,
ping
ping,
register_user(first_name, last_name = nil)
register_user,
send_code(code)
send_code
Instance methods inherited from module Tourmaline::Client::WebhookMethods
delete_webhook(drop_pending_updates = false)
delete_webhook,
get_webhook_info
get_webhook_info,
serve(host = "127.0.0.1", port = 8081, ssl_certificate_path = nil, ssl_key_path = nil, no_middleware_check = false, &block : HTTP::Server::Context -> )serve(path = "/", host = "127.0.0.1", port = 8081, ssl_certificate_path = nil, ssl_key_path = nil, no_middleware_check = false) serve, set_webhook(url, ip_address = nil, certificate = nil, max_connections = nil, allowed_updates = nil, drop_pending_updates = false, secret_token = nil) set_webhook, stop_serving stop_serving, unset_webhook unset_webhook
Instance methods inherited from module Tourmaline::Client::StickerMethods
add_sticker_to_set(user_id, name, emojis, png_sticker = nil, tgs_sticker = nil, webm_sticker = nil, mask_position = nil)
add_sticker_to_set,
create_new_sticker_set(user_id, name, title, emojis, png_sticker = nil, tgs_sticker = nil, webm_sticker = nil, sticker_type = nil, mask_position = nil)
create_new_sticker_set,
delete_chat_sticker_set(chat_id)
delete_chat_sticker_set,
delete_sticker_from_set(sticker)
delete_sticker_from_set,
get_custom_emoji_stickers(custom_emoji_ids : Array(String))
get_custom_emoji_stickers,
get_sticker_set(name : String)
get_sticker_set,
send_sticker(chat, sticker, message_thread_id = nil, disable_notification = nil, reply_to_message = nil, reply_markup = nil)
send_sticker,
set_chat_sticker_set(chat_id, sticker_set_name)
set_chat_sticker_set,
set_sticker_position_in_set(sticker, position)
set_sticker_position_in_set,
set_sticker_set_thumb(name, user, thumb = nil)
set_sticker_set_thumb,
upload_sticker_file(user_id, png_sticker)
upload_sticker_file
Instance methods inherited from module Tourmaline::Client::PollMethods
send_poll(chat, question : String, options : Array(String), anonymous : Bool = true, type : Poll::Type = Poll::Type::Regular, allows_multiple_answers : Bool = false, correct_option_id : Int32 | Nil = nil, close_date : Time | Nil = nil, open_period : Int32 | Nil = nil, closed : Bool = false, disable_notification : Bool = false, reply_to_message = nil, reply_markup = nil)
send_poll,
stop_poll(chat, message, reply_markup = nil)
stop_poll
Instance methods inherited from module Tourmaline::Client::PaymentMethods
answer_pre_checkout_query(pre_checkout_query_id, ok, error_message = nil)
answer_pre_checkout_query,
answer_shipping_query(shipping_query_id, ok, shipping_options = nil, error_message = nil)
answer_shipping_query,
create_invoice_link(title, description, payload, provider_token, currency, prices, max_tip_amount = nil, suggested_tip_amounts = nil, provider_data = nil, photo_url = nil, photo_size = nil, photo_width = nil, photo_height = nil, need_name = nil, need_phone_number = nil, need_email = nil, need_shipping_address = nil, send_phone_number_to_provider = nil, send_email_to_provider = nil, is_flexible = nil)
create_invoice_link,
labeled_prices(lp : Array(NamedTuple(label: String, amount: Int32)))
labeled_prices,
send_invoice(chat, title, description, payload, provider_token, currency, prices, message_thread_id = nil, max_tip_amount = nil, suggested_tip_amounts = nil, start_parameter = nil, provider_data = nil, photo_url = nil, photo_size = nil, photo_width = nil, photo_height = nil, need_name = nil, need_phone_number = nil, need_email = nil, need_shipping_address = nil, send_phone_number_to_provider = nil, send_email_to_provider = nil, is_flexible = nil, disable_notification = nil, reply_to_message = nil, reply_markup = nil)
send_invoice,
shipping_options(options : Array(NamedTuple(id: String, title: String, prices: Array(LabeledPrice))))
shipping_options
Instance methods inherited from module Tourmaline::Client::PassportMethods
set_passport_data_errors(user_id : Int32, errors : Array(PassportElementError))
set_passport_data_errors
Instance methods inherited from module Tourmaline::Client::GameMethods
get_game_high_scores(user_id, chat_id = nil, message_id = nil, inline_message_id = nil)
get_game_high_scores,
send_game(chat_id, game_short_name, message_thread_id = nil, disable_notification = nil, reply_to_message_id = nil, reply_markup = nil)
send_game,
set_game_score(user_id, score, force = false, disable_edit_message = nil, chat_id = nil, message_id = nil, inline_message_id = nil)
set_game_score
Instance methods inherited from module Tourmaline::Client::CoreMethods
answer_callback_query(callback_query_id, text = nil, show_alert = nil, url = nil, cache_time = nil)
answer_callback_query,
answer_inline_query(inline_query_id, results, cache_time = nil, is_personal = nil, next_offset = nil, switch_pm_text = nil, switch_pm_parameter = nil)
answer_inline_query,
answer_web_app_query(query_id : String, result : InlineQueryResult)
answer_web_app_query,
approve_chat_join_request(chat, user)
approve_chat_join_request,
ban_chat_member(chat, user, until_date = nil, revoke_messages = nil)
ban_chat_member,
ban_chat_sender_chat(chat, sender_chat)
ban_chat_sender_chat,
close
close,
close_forum_topic(chat, message_thread_id)
close_forum_topic,
copy_message(chat, from_chat, message, message_thread_id = nil, caption = nil, parse_mode = Tourmaline::Client.default_parse_mode, caption_entities = [] of MessageEntity, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil)
copy_message,
create_chat_invite_link(chat, name = nil, expire_date = nil, member_limit = nil, creates_join_request = false)
create_chat_invite_link,
create_forum_topic(chat, name, icon_color = nil, icon_custom_emoji_id = nil)
create_forum_topic,
decline_chat_join_request(chat, user)
decline_chat_join_request,
delete_chat_photo(chat)
delete_chat_photo,
delete_forum_topic(chat, message_thread_id)
delete_forum_topic,
delete_message(chat, message)
delete_message,
delete_my_commands(scope : BotCommandScope | Nil = nil, language_code : String | Nil = nil)
delete_my_commands,
download_file(file_id, path = nil)
download_file,
edit_chat_invite_link(chat, invite_link, name = nil, expire_date = nil, member_limit = nil, creates_join_request = false)
edit_chat_invite_link,
edit_forum_topic(chat, message_thread_id, name, icon_custom_emoji_id)
edit_forum_topic,
edit_message_caption(chat, caption, message = nil, inline_message = nil, parse_mode = Tourmaline::Client.default_parse_mode, caption_entities = [] of MessageEntity, reply_markup = nil)
edit_message_caption,
edit_message_live_location(chat, latitude, longitude, horizontal_accuracy = nil, live_period = nil, proximity_alert_radius = nil, heading = nil, message = nil, inline_message = nil, reply_markup = nil)
edit_message_live_location,
edit_message_media(chat, media, message = nil, inline_message = nil, reply_markup = nil)
edit_message_media,
edit_message_reply_markup(chat, message = nil, inline_message = nil, reply_markup = nil)
edit_message_reply_markup,
edit_message_text(text, chat = nil, message = nil, inline_message = nil, parse_mode = Tourmaline::Client.default_parse_mode, entities = [] of MessageEntity, disable_link_preview = false, reply_markup = nil)
edit_message_text,
export_chat_invite_link(chat)
export_chat_invite_link,
forward_message(chat, from_chat, message, message_thread_id = nil, disable_notification = false, protect_content = false)
forward_message,
get_chat(chat)
get_chat,
get_chat_administrators(chat)
get_chat_administrators,
get_chat_member(chat, user)
get_chat_member,
get_chat_members_count(chat)
get_chat_members_count,
get_file(file_id)
get_file,
get_file_link(file_id)
get_file_link,
get_forum_topic_icon_stickers
get_forum_topic_icon_stickers,
get_me
get_me,
get_my_commands(scope : BotCommandScope | Nil = nil, language_code : String | Nil = nil)
get_my_commands,
get_my_default_adminstrator_rights(for_channels : Bool = false)
get_my_default_adminstrator_rights,
get_updates(offset = @next_offset, limit = 100, timeout = 0, allowed_updates = [] of String)
get_updates,
get_user_profile_photos(user, offset = nil, limit = nil)
get_user_profile_photos,
is_admin?(chat_id)
is_admin?,
kick_chat_member(*args, **kwargs)
kick_chat_member,
leave_chat(chat)
leave_chat,
log_out
log_out,
mute_chat_member(chat, user, until_date = nil)
mute_chat_member,
next_offset : Int64
next_offset,
pin_chat_message(chat, message, disable_notification = false)
pin_chat_message,
poll(delete_webhook = false, no_middleware_check = false)
poll,
polling : Bool
polling,
promote_chat_member(chat, user, is_anonymous = false, until_date = nil, can_manage_chat = nil, can_change_info = nil, can_post_messages = nil, can_edit_messages = nil, can_delete_messages = nil, can_invite_users = nil, can_manage_video_chats = nil, can_restrict_members = nil, can_pin_messages = nil, can_promote_members = nil, can_manage_topics = nil)
promote_chat_member,
reopen_forum_topic(chat, message_thread_id)
reopen_forum_topic,
restrict_chat_member(chat, user, permissions, until_date = nil)
restrict_chat_member,
revoke_chat_invite_link(chat, invite_link)
revoke_chat_invite_link,
send_animation(chat, animation, message_thread_id = nil, duration = nil, width = nil, height = nil, thumb = nil, caption = nil, caption_entities = [] of MessageEntity, parse_mode = Tourmaline::Client.default_parse_mode, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil)
send_animation,
send_audio(chat, audio, message_thread_id = nil, caption = nil, caption_entities = [] of MessageEntity, duration = nil, preformer = nil, title = nil, parse_mode = Tourmaline::Client.default_parse_mode, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil)
send_audio,
send_basketball(chat, message_thread_id = nil, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil)
send_basketball,
send_bowling(chat, message_thread_id = nil, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil)
send_bowling,
send_chat_action(chat, action : ChatAction)
send_chat_action,
send_contact(chat, phone_number, first_name, message_thread_id = nil, last_name = nil, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil)
send_contact,
send_dart(chat, message_thread_id = nil, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil)
send_dart,
send_dice(chat, message_thread_id = nil, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil)
send_dice,
send_document(chat, document, message_thread_id = nil, caption = nil, caption_entities = [] of MessageEntity, parse_mode = Tourmaline::Client.default_parse_mode, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil)
send_document,
send_football(chat, message_thread_id = nil, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil)
send_football,
send_location(chat, latitude, longitude, message_thread_id = nil, horizontal_accuracy = nil, live_period = nil, proximity_alert_radius = nil, heading = nil, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil)
send_location,
send_media_group(chat, media : Array(InputMediaPhoto | InputMediaVideo | InputMediaAudio | InputMediaDocument), message_thread_id = nil, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false)
send_media_group,
send_message(chat, text, message_thread_id = nil, parse_mode = Tourmaline::Client.default_parse_mode, entities = [] of MessageEntity, link_preview = false, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil)
send_message,
send_photo(chat, photo, message_thread_id = nil, caption = nil, parse_mode = Tourmaline::Client.default_parse_mode, caption_entities = [] of MessageEntity, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil)
send_photo,
send_slot_machine(chat, message_thread_id = nil, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil)
send_slot_machine,
send_soccerball(chat, message_thread_id = nil, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil)
send_soccerball,
send_venue(chat, latitude, longitude, title, address, message_thread_id = nil, foursquare_id = nil, foursquare_type = nil, google_place_id = nil, google_place_type = nil, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil)
send_venue,
send_video(chat, video, message_thread_id = nil, duration = nil, width = nil, height = nil, caption = nil, caption_entities = [] of MessageEntity, parse_mode = Tourmaline::Client.default_parse_mode, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil)
send_video,
send_video_note(chat, video_note, message_thread_id = nil, duration = nil, width = nil, height = nil, caption = nil, caption_entities = [] of MessageEntity, parse_mode = Tourmaline::Client.default_parse_mode, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil)
send_video_note,
send_voice(chat, voice, message_thread_id = nil, caption = nil, caption_entities = [] of MessageEntity, duration = nil, preformer = nil, title = nil, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil)
send_voice,
set_chat_admininstrator_custom_title(chat, user, custom_title)
set_chat_admininstrator_custom_title,
set_chat_description(chat, description)
set_chat_description,
set_chat_permissions(chat, permissions)
set_chat_permissions,
set_chat_photo(chat, photo)
set_chat_photo,
set_chat_title(chat, title)
set_chat_title,
set_my_commands(commands : Array(BotCommand | NamedTuple(command: String, description: String)), scope : BotCommandScope | Nil = nil, language_code : String | Nil = nil)
set_my_commands,
set_my_default_adminstrator_rights(rights : ChatAdministratorRights, for_channels : Bool = false)
set_my_default_adminstrator_rights,
stop_message_live_location(chat, message = nil, inline_message = nil, reply_markup = nil)
stop_message_live_location,
stop_polling
stop_polling,
unban_chat_member(chat, user, only_if_banned = false)
unban_chat_member,
unban_chat_sender_chat(chat, sender_chat)
unban_chat_sender_chat,
unpin_all_chat_messages(chat)
unpin_all_chat_messages,
unpin_all_forum_topic_messages(chat, message_thread_id)
unpin_all_forum_topic_messages,
unpin_chat_message(chat, message = nil)
unpin_chat_message
Constructor Detail
Create a new instance of Tourmaline::Client
.
Named Arguments
#bot_token
: the bot token you should've received from @BotFather
#user_token
: the token returned by the #login
method
endpoint
: the API endpoint to use for requests; default is https://api.telegram.org
, but for
TDLight methods to work you may consider hosting your own instance or using one of
the official ones such as https://telegram.rest
#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
Class Method Detail
Default prefixes to use for commands
Default prefixes to use for commands
Default parse mode to use for commands when it isn't included explicitly
Default parse mode to use for commands when it isn't included explicitly
Instance Method Detail
Gets the name of the Client at the time the Client was
started. Refreshing can be done by setting
@bot
to get_me
.
Gets the name of the Client at the time the Client was
started. Refreshing can be done by setting
@bot
to get_me
.
Calls all handlers in the stack with the given update and this client instance.