class Tourmaline::Client

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

Defined in:

Constant Summary

DEFAULT_API_URL = "https://api.telegram.org/"
Log = ::Log.for("tourmaline.client")

Constructors

Instance Method Summary

Instance methods inherited from module Tourmaline::Client::WebhookMethods

delete_webhook delete_webhook, get_webhook_info get_webhook_info, serve(host = "127.0.0.1", port = 8081, ssl_certificate_path = nil, ssl_key_path = nil, &block : HTTP::Server::Context -> )
serve(path = "/", host = "127.0.0.1", port = 8081, ssl_certificate_path = nil, ssl_key_path = nil)
serve
, set_webhook(url, certificate = nil, max_connections = nil, allowed_updates = @allowed_updates) set_webhook, 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, mask_position = nil) add_sticker_to_set, create_new_sticker_set(user_id, name, title, emojis, png_sticker = nil, tgs_sticker = nil, contains_masks = 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_sticker_set(name : String) get_sticker_set, send_sticker(chat_id : Int32 | String, sticker : InputFile | String, disable_notification : Bool? = nil, reply_to_message_id : Int32? = 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, close_date : Time? = nil, open_period : Int32? = 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, labeled_prices(lp : Array(NamedTuple())) labeled_prices, send_invoice(chat, title, description, payload, provider_token, start_parameter, currency, prices, provider_data = nil, photo_url = nil, photo_size = nil, photo_width = nil, photo_height = nil, need_name = 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())) 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, 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, delete_chat_photo(chat) delete_chat_photo, delete_message(chat, message) delete_message, edit_message_caption(chat, caption, message = nil, inline_message = nil, parse_mode = ParseMode::Normal, reply_markup = nil) edit_message_caption, edit_message_live_location(chat, latitude, longitude, 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(chat, text, message = nil, inline_message = nil, parse_mode = ParseMode::Normal, 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, disable_notification = 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_me get_me, get_my_commands get_my_commands, 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(chat, user, until_date = nil) kick_chat_member, leave_chat(chat) leave_chat, next_offset : Int64 next_offset, pin_chat_message(chat, message, disable_notification = false) pin_chat_message, poll(delete_webhook = false) poll, polling : Bool polling, promote_chat_member(chat, user, until_date = nil, can_change_info = nil, can_post_messages = nil, can_edit_messages = nil, can_delete_messages = nil, can_invite_users = nil, can_restrict_members = nil, can_pin_messages = nil, can_promote_members = nil) promote_chat_member, restrict_chat_member(chat, user, permissions, until_date = nil) restrict_chat_member, send_animation(chat, animation, duration = nil, width = nil, height = nil, thumb = nil, caption = nil, parse_mode = ParseMode::Normal, disable_notification = false, reply_to_message = nil, reply_markup = nil) send_animation, send_audio(chat, audio, caption = nil, duration = nil, preformer = nil, title = nil, disable_notification = false, reply_to_message = nil, reply_markup = nil) send_audio, send_basket(chat, disable_notification = false, reply_to_message = nil, reply_markup = nil) send_basket, send_chat_action(chat, action : ChatAction) send_chat_action, send_contact(chat, phone_number, first_name, last_name = nil, disable_notification = false, reply_to_message = nil, reply_markup = nil) send_contact, send_dart(chat, disable_notification = false, reply_to_message = nil, reply_markup = nil) send_dart, send_dice(chat, disable_notification = false, reply_to_message = nil, reply_markup = nil) send_dice, send_document(chat, document, caption = nil, disable_notification = false, reply_to_message = nil, reply_markup = nil) send_document, send_location(chat, latitude, longitude, live_period = nil, disable_notification = false, reply_to_message = nil, reply_markup = nil) send_location, send_media_group(chat, media : Array(InputMediaPhoto | InputMediaVideo), disable_notification = false, reply_to_message = nil) send_media_group, send_message(chat, text, parse_mode = ParseMode::Normal, link_preview = false, disable_notification = false, reply_to_message = nil, reply_markup = nil) send_message, send_photo(chat, photo, caption = nil, parse_mode = ParseMode::Normal, disable_notification = false, reply_to_message = nil, reply_markup = nil) send_photo, send_venue(chat, latitude, longitude, title, address, foursquare_id = nil, disable_notification = false, reply_to_message = nil, reply_markup = nil) send_venue, send_video(chat, video, duration = nil, width = nil, height = nil, caption = nil, disable_notification = false, reply_to_message = nil, reply_markup = nil) send_video, send_video_note(chat, video_note, duration = nil, width = nil, height = nil, caption = nil, disable_notification = false, reply_to_message = nil, reply_markup = nil) send_video_note, send_voice(chat, voice, caption = nil, duration = nil, preformer = nil, title = nil, disable_notification = false, reply_to_message = nil, 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())) set_my_commands, 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) unban_chat_member, unpin_chat_message(chat) unpin_chat_message

Constructor Detail

def self.new(api_key : String, endpoint = DEFAULT_API_URL, *, persistence : Persistence = NilPersistence.new, allowed_updates = [] of String, 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.

Arguments

Positional

  • 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

  • persistence - the persistence strategy to use
  • 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

Instance Method Detail

def add_event_handler(handler : EventHandler) #

def allowed_updates : Array(String) #

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

def bot #

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


def handle_update(update : Update) #

def remove_event_handler(handler : EventHandler) #

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