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:

tourmaline/client.cr

Constant Summary

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

Constructors

Instance Method Summary

Constructor Detail

def self.new(bot_token : String, endpoint : String = DEFAULT_API_URL, 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.

Named Arguments

#bot_token : the bot token you should've received from @BotFather

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

#default_parse_mode : the default parse mode to use for messages; default is ParseMode::None (no formatting)

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


[View source]

Instance Method Detail

def add_sticker_to_set(user_id, name, sticker) #

Use this method to add a new sticker to a set created by the bot. Returns true on success.


[View source]
def answer_callback_query(callback_query_id, text = nil, show_alert = nil, url = nil, cache_time = nil) #

Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On success, true is returned.

!!! note Alternatively, the user can be redirected to the specified Game URL (url). For this option to work, you must first create a game for your bot via @Botfather and accept the terms. Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.


[View source]
def answer_inline_query(inline_query_id, results, cache_time = nil, is_personal = nil, next_offset = nil, switch_pm_text = nil, switch_pm_parameter = nil) #

Use this method to send answers to an inline query. On success, True is returned. No more than 50 results per query are allowed.


[View source]
def answer_pre_checkout_query(pre_checkout_query_id, ok, error_message = nil) #

Once the user has confirmed their payment and shipping details, the Client API sends the final confirmation in the form of a Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries. On success, true is returned.

Note: The Client API must receive an answer within 10 seconds after the pre-checkout query was sent.


[View source]
def answer_shipping_query(shipping_query_id, ok, shipping_options = nil, error_message = nil) #

If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Client API will send a Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, true is returned.


[View source]
def answer_web_app_query(query_id : String, result : InlineQueryResult) #

Use this method to set the result of an interaction with a Web App and send a corresponding message on behalf of the user to the chat from which the query originated. On success, a SentWebAppMessage object is returned.


[View source]
def approve_chat_join_request(chat, user) #

Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. Returns True on success.


[View source]
def ban_chat_member(chat, user, until_date = nil, revoke_messages = nil) #

Use this method to kick a user from a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns true on success.

Note: In regular groups (non-supergroups), this method will only work if the All Members Are Admins setting is off in the target group. Otherwise members may only be removed by the group's creator or by the member that added them.


[View source]
def ban_chat_sender_chat(chat, sender_chat) #

Use this method to ban a channel chat in a supergroup or a channel. The owner of the chat will not be able to send messages and join live streams on behalf of the chat, unless it is unbanned first. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.


[View source]
def bot : User #

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


[View source]
def bot? : User | Nil #

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


[View source]
def bot_token : String #

[View source]
def close #

Use this method to close the bot instance before moving it from one local server to another. You need to delete the webhook before calling this method to ensure that the bot isn't launched again after server restart. The method will return error 429 in the first 10 minutes after the bot is launched.

Returns true on success. Requires no parameters.


[View source]
def close_forum_topic(chat, message_thread_id) #

Use this method to close an open topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.


[View source]
def close_general_forum_topic(chat) #

Use this method to close an open 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.


[View source]
def copy_message(chat, from_chat, message, message_thread_id = nil, caption = nil, parse_mode : ParseMode = 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) #

[View source]
def create_chat_invite_link(chat, name = nil, expire_date = nil, member_limit = nil, creates_join_request = false) #

Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. The link can be revoked using the method revokeChatInviteLink. Returns the new invite link as ChatInviteLink object.


[View source]
def create_forum_topic(chat, name, icon_color = nil, icon_custom_emoji_id = nil) #

Use this method to create a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns information about the created topic as a ForumTopic object.


[View source]
def 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) #

Use this method to create a link for an invoice. Returns the created invoice link as String on success.


[View source]
def create_new_sticker_set(user_id, name, title, stickers : Array(InputSticker), sticker_format : Sticker::Format, sticker_type : Sticker::Type | Nil = nil, needs_repainting = false) #

Use this method to create new sticker set owned by a user. The bot will be able to edit the created sticker set. You must use exactly one of the fields png_sticker or tgs_sticker. Returns true on success.


[View source]
def decline_chat_join_request(chat, user) #

Use this method to decline a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. Returns True on success.


[View source]
def default_parse_mode : ParseMode #

[View source]
def default_parse_mode=(default_parse_mode : ParseMode) #

[View source]
def delete_chat_photo(chat) #

Use this method to delete a chat photo. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns true on success.

Note: In regular groups (non-supergroups), this method will only work if the All Members Are Admins setting is off in the target group.


[View source]
def delete_chat_sticker_set(chat_id) #

Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Use the field can_set_sticker_set optionally returned in #get_chat requests to check if the bot can use this method. Returns true on success.


[View source]
def delete_forum_topic(chat, message_thread_id) #

Use this method to delete a forum topic along with all its messages in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_delete_messages administrator rights. Returns True on success.


[View source]
def delete_message(chat, message) #

Use this method to delete a Message, including service messages, with the following limitations:

  • A message can only be deleted if it was sent less than 48 hours ago.
  • Bots can delete outgoing messages in private chats, groups, and supergroups.
  • Bots can delete incoming messages in private chats.
  • Bots granted can_post_messages permissions can delete outgoing messages in channels.
  • If the bot is an administrator of a group, it can delete any message there.
  • If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there. Returns true on success.

[View source]
def delete_my_commands(scope : BotCommandScope | Nil = nil, language_code : String | Nil = nil) #

Use this method to delete the list of the bot's commands for the given scope and user language. After deletion, higher level commands will be shown to affected users. Returns True on success.


[View source]
def delete_sticker_from_set(sticker) #

Use this method to delete a sticker from a set created by the bot. Returns true on success.


[View source]
def delete_sticker_set(name) #

Use this method to delete a sticker set that was created by the bot. Returns True on success.


[View source]
def delete_webhook(drop_pending_updates = false) #

Use this method to remove webhook integration if you decide to switch back to getUpdates.


[View source]
def dispatcher #

[View source]
def download_file(file_id, path = nil) #

Given a file_id, download the file and return its path on the file system.


[View source]
def edit_chat_invite_link(chat, invite_link, name = nil, expire_date = nil, member_limit = nil, creates_join_request = false) #

Use this method to edit a non-primary invite link created by the bot. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the edited invite link as a ChatInviteLink object.


[View source]
def edit_forum_topic(chat, message_thread_id, name = nil, icon_custom_emoji_id = nil) #

Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.


[View source]
def edit_general_forum_topic(chat, name) #

Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success.


[View source]
def edit_message_caption(chat, caption, message = nil, inline_message = nil, parse_mode : ParseMode = default_parse_mode, caption_entities = [] of MessageEntity, reply_markup = nil) #

Use this method to edit captions of messages. On success, if edited message is sent by the bot, the edited Message is returned, otherwise true is returned.


[View source]
def 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) #

Use this method to edit live location messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to #stopMessageLiveLocation.

On success, if the edited message wasn't by the bot, the edited Message is returned, otherwise true is returned.


[View source]
def edit_message_media(chat, media, message = nil, inline_message = nil, reply_markup = nil) #

[View source]
def edit_message_reply_markup(chat, message = nil, inline_message = nil, reply_markup = nil) #

Use this method to edit only the reply markup of messages. On success, if edited message is sent by the bot, the edited Message is returned, otherwise true is returned.


[View source]
def edit_message_text(text, chat = nil, message = nil, inline_message = nil, parse_mode : ParseMode = default_parse_mode, entities = [] of MessageEntity, disable_link_preview = false, reply_markup = nil) #

Use this method to edit text and game messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise true is returned.


[View source]
def export_chat_invite_link(chat) #

Use this method to generate a new invite link for a chat; any previously generated link is revoked. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns the new invite link as String on success.


[View source]
def forward_message(chat, from_chat, message, message_thread_id = nil, disable_notification = false, protect_content = false) #

Use this method to forward messages of any kind. On success, the sent Message is returned.


[View source]
def get_chat(chat) #

Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). Returns a Chat object on success.

!!! tip When using TDLight this method isn't restructed to chats/users your bot is familiar with.

!!! warning When using TDLight this method will first check for a locally cached chat, then use MTProto if that fails. When using MTProto this method is heavily rate limited, so be careful.


[View source]
def get_chat_administrators(chat) #

Use this method to get a list of administrators in a chat. On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned.


[View source]
def get_chat_member(chat, user) #

Use this method to get information about a member of a chat. Returns a ChatMember object on success.


[View source]
def get_chat_members_count(chat) #

Use this method to get the number of members in a chat. Returns Int32 on success.


[View source]
def get_custom_emoji_stickers(custom_emoji_ids : Array(String)) #

Use this method to get information about custom emoji stickers by their identifiers. Returns an Array of Sticker objects.


[View source]
def get_file(file_id) #

Use this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. On success, a TFile object is returned. The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>, where <file_path> is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling #get_file again.

To simplify retrieving a link for a file, use the #get_file_link method.


[View source]
def get_file_link(file_id) #

Takes a file id and returns a link to download the file. The link will be valid for at least one hour.


[View source]
def get_forum_topic_icon_stickers #

Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user. Requires no parameters. Returns an Array of Sticker objects.


[View source]
def get_game_high_scores(user_id, chat_id = nil, message_id = nil, inline_message_id = nil) #

Use this method to get data for high score tables. Will return the score of the specified user and several of his neighbors in a game. On success, returns an Array of GameHighScore objects.

This method will currently return scores for the target user, plus two of his closest neighbors on each side. Will also return the top three users if the user and his neighbors are not among them. Please note that this behavior is subject to change.


[View source]
def get_me #

A simple method for testing your bot's auth token. Requires no parameters. Returns basic information about the bot in form of a User object.


[View source]
def get_my_commands(scope : BotCommandScope | Nil = nil, language_code : String | Nil = nil) #

Use this method to get the current list of the bot's commands. Requires no parameters. Returns Array of BotCommand on success.


[View source]
def get_my_default_adminstrator_rights(for_channels : Bool = false) #

Use this method to get the current default administrator rights of the bot. Returns ChatAdministratorRights on success.


[View source]
def get_my_description(language_code : String | Nil = nil) #

Use this method to get the current bot description for the given user language. Returns BotDescription on success.


[View source]
def get_my_short_description(language_code : String | Nil = nil) #

Use this method to get the current bot short description for the given user language. Returns BotShortDescription on success.


[View source]
def get_sticker_set(name : String) #

Use this method to get a sticker set. On success, a StickerSet object is returned.


[View source]
def get_updates(offset = 0, limit = 100, timeout = 0, allowed_updates = [] of String) #

Use this method to receive incoming updates using long polling (wiki). An Array of Update objects is returned.


[View source]
def get_user_profile_photos(user, offset = nil, limit = nil) #

Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.


[View source]
def get_webhook_info #

Use this method to get current webhook status. Requires no parameters. On success, returns a WebhookInfo object. If the bot is using #getUpdates, will return an object with the url field empty.


[View source]
def hide_general_forum_topic(chat) #

Use this method to hide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. The topic will be automatically closed if it was open. Returns True on success.


[View source]
def kick_chat_member(*args, **kwargs) #

[View source]
def leave_chat(chat) #

Use this method for your bot to leave a group, supergroup, or channel. Returns true on success.


[View source]
def log_out #

Use this method to log out from the cloud Bot API server before launching the bot locally. You must log out the bot before running it locally, otherwise there is no guarantee that the bot will receive updates. After a successful call, you can immediately log in on a local server, but will not be able to log in back to the cloud Bot API server for 10 minutes.

Returns true on success. Requires no parameters.


[View source]
def mute_chat_member(chat, user, until_date = nil) #

Use this method to easily mute a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin right. Works by calling #restrict_chat_member with all permissions set to false. Returns true on success.


[View source]
def on(action : UpdateAction, &block : Context -> ) #

[View source]
def on(*actions : Symbol | UpdateAction, &block : Context -> ) #

[View source]
def pin_chat_message(chat, message, disable_notification = false) #

Use this method to pin a message in a group, a supergroup, or a channel. The bot must be an administrator in the chat for this to work and must have the can_pin_messages admin right in the supergroup or can_edit_messages admin right in the channel. Returns true on success.


[View source]
def poll #

[View source]
def 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) #

Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Pass False for all boolean parameters to demote a user. Returns true on success.


[View source]
def register(*handlers : EventHandler) #

[View source]
def reopen_forum_topic(chat, message_thread_id) #

Use this method to reopen a closed topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.


[View source]
def reopen_general_forum_topic(chat) #

Use this method to reopen a closed 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. The topic will be automatically unhidden if it was hidden. Returns True on success.


[View source]
def request(type : U.class, method, params = {} of String => String) forall U #

Sends a request to the Telegram Client API. Returns the response, parsed as a U.


[View source]
def request_raw(method : String, params = {} of String => String) #

Sends a request to the Telegram Client API. Returns the raw response.


[View source]
def restrict_chat_member(chat, user, permissions, use_independent_chat_permissions = false, until_date = nil) #

Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass True for all permissions to lift restrictions from a user. Returns true on success.


[View source]
def revoke_chat_invite_link(chat, invite_link) #

Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is automatically generated. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the revoked invite link as ChatInviteLink object.


[View source]
def send_animation(chat, animation, message_thread_id = nil, duration = nil, width = nil, height = nil, thumbnail = nil, caption = nil, caption_entities = [] of MessageEntity, has_spoiler = false, parse_mode : ParseMode = default_parse_mode, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil) #

[View source]
def send_audio(chat, audio, message_thread_id = nil, caption = nil, caption_entities = [] of MessageEntity, duration = nil, preformer = nil, title = nil, parse_mode : ParseMode = default_parse_mode, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil) #

Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .mp3 format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.

For sending voice messages, use the #sendVoice method instead.

TODO Add filesize checking and validation.


[View source]
def 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) #

Use this method to send a basketball (🏀 emoji), which will have a random value from 1 to 6. On success, the sent Message is returned.


[View source]
def 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) #

Use this method to send a bowling (🎳 emoji), which will have a random value from 1 to 6. On success, the sent Message is returned.


[View source]
def send_chat_action(chat, action : ChatAction, message_thread = nil) #

Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Returns true on success.

Example: The ImageBot needs some time to process a request and upload the image. Instead of sending a text message along the lines of “Retrieving image, please wait…”, the bot may use #sendChatAction with action = upload_photo. The user will see a “sending photo” status for the bot.

We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.


[View source]
def 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) #

Use this method to send phone contacts. On success, the sent Message is returned.


[View source]
def 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) #

Use this method to send a dart (🎯 emoji), which will have a random value from 1 to 6. On success, the sent Message is returned.


[View source]
def 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) #

Use this method to send a dice (🎲 emoji), which will have a random value from 1 to 6. On success, the sent Message is returned.


[View source]
def send_document(chat, document, message_thread_id = nil, caption = nil, caption_entities = [] of MessageEntity, parse_mode : ParseMode = default_parse_mode, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil) #

Use this method to send general files. On success, the sent Message is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.

TODO Add filesize checking and validation.


[View source]
def 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) #

Use this method to send a football (⚽️ emoji), which will have a random value from 1 to 5. On success, the sent Message is returned.


[View source]
def send_game(chat, game_short_name, message_thread_id = nil, disable_notification = false, reply_to_message_id = nil, reply_markup = nil) #

Use this method to send a game. On success, the sent Message is returned.


[View source]
def 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 = false, reply_to_message = nil, reply_markup = nil) #

Use this method to send invoices. On success, the sent Message is returned.


[View source]
def 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) #

Use this method to send point on the map. On success, the sent Message is returned.


[View source]
def 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) #

Use this method to send a group of photos or videos as an album. On success, an array of the sent Messages is returned.


[View source]
def send_message(chat, text, message_thread_id = nil, parse_mode : ParseMode = 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) #

Use this method to send text messages. On success, the sent Message is returned.


[View source]
def send_photo(chat, photo, message_thread_id = nil, caption = nil, parse_mode : ParseMode = default_parse_mode, caption_entities = [] of MessageEntity, has_spoiler = false, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil) #

Use this method to send photos. On success, the sent Message is returned.


[View source]
def 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) #

Use this method to send a native poll. On success, the sent Message is returned.


[View source]
def 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) #

Use this method to send a slot_machine (🎰 emoji), which will have a random value from 1 to 64. On success, the sent Message is returned.


[View source]
def 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) #

Use this method to send a soccerball (⚽️ emoji), which will have a random value from 1 to 5. On success, the sent Message is returned.


[View source]
def send_sticker(chat, sticker, message_thread_id = nil, emoji = nil, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil) #

Use this method to send .webp stickers. On success, the sent Message is returned.

See: https://core.telegram.org/bots/api#stickers for more info.


[View source]
def 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) #

Use this method to send information about a venue. On success, the sent Message is returned.


[View source]
def send_video(chat, video, message_thread_id = nil, duration = nil, width = nil, height = nil, caption = nil, caption_entities = [] of MessageEntity, has_spoiler = false, parse_mode : ParseMode = default_parse_mode, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil) #

Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). On success, the sent Message is returned. Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.

TODO Add filesize checking and validation.


[View source]
def send_video_note(chat, video_note, message_thread_id = nil, duration = nil, width = nil, height = nil, caption = nil, caption_entities = [] of MessageEntity, parse_mode : ParseMode = default_parse_mode, disable_notification = false, protect_content = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil) #

As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long. Use this method to send video messages. On success, the sent Message is returned.


[View source]
def 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) #

Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.

TODO Add filesize checking and validation.


[View source]
def serve(path = "/", host = "127.0.0.1", port = 8081, ssl_certificate_path = nil, ssl_key_path = nil, no_middleware_check = false) #

[View source]
def set_chat_admininstrator_custom_title(chat, user, custom_title) #

Use this method to set a custom title for an administrator in a supergroup promoted by the bot. Returns True on success.


[View source]
def set_chat_description(chat, description) #

Use this method to change the description of a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns true on success.


[View source]
def set_chat_menu_button(chat, menu_button : MenuButton | Nil = nil) #

Use this method to change the bot's menu button in a private chat, or the default menu button. Returns True on success.


[View source]
def set_chat_permissions(chat, permissions, use_independent_chat_permissions = false) #

Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members admin rights. Returns True on success.


[View source]
def set_chat_photo(chat, photo) #

Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns true on success.

Note: In regular groups (non-supergroups), this method will only work if the All Members Are Admins setting is off in the target group.


[View source]
def set_chat_sticker_set(chat, sticker_set_name) #

Use this method to set a new group sticker set for a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Use the field can_set_sticker_set optionally returned in #get_chat requests to check if the bot can use this method. Returns true on success.


[View source]
def set_chat_title(chat, title) #

Use this method to change the title of a chat. Titles can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns true on success.

Note: In regular groups (non-supergroups), this method will only work if the All Members Are Admins setting is off in the target group.


[View source]
def set_custom_emoji_sticker_set_thumbnail(name, custom_emoji_id = nil) #

Use this method to set the thumbnail of a custom emoji sticker set. Returns True on success.


[View source]
def set_game_score(user_id, score, force = false, disable_edit_message = nil, chat_id = nil, message_id = nil, inline_message_id = nil) #

Use this method to set the score of the specified user in a game. On success, if the message was sent by the bot, returns the edited Message, otherwise returns true.

Raises an error, if the new score is not greater than the user's current score in the chat and force is false (default).


[View source]
def set_my_commands(commands : Array(BotCommand | NamedTuple(command: String, description: String)), scope : BotCommandScope | Nil = nil, language_code : String | Nil = nil) #

Use this method to change the list of the bot's commands. Returns true on success.


[View source]
def set_my_default_adminstrator_rights(rights : ChatAdministratorRights, for_channels : Bool = false) #

Use this method to change the default administrator rights requested by the bot when it's added as an administrator to groups or channels. These rights will be suggested to users, but they are are free to modify the list before adding the bot. Returns True on success.


[View source]
def set_my_description(description : String, language_code : String | Nil = nil) #

Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty. Returns True on success.


[View source]
def set_my_short_description(description : String, language_code : String | Nil = nil) #

Use this method to change the bot's short description, which is shown on the bot's profile page and is sent together with the link when users share the bot. Returns True on success.


[View source]
def set_passport_data_errors(user_id : Int32, errors : Array(PassportElementError)) #

Informs a user that some of the Telegram Passport elements they provided contains errors. The user will not be able to re-submit their Passport to you until the errors are fixed (the contents of the field for which you returned the error must change).

Returns True on success.

Use this if the data submitted by the user doesn't satisfy the standards your service requires for any reason. For example, if a birthday date seems invalid, a submitted document is blurry, a scan shows evidence of tampering, etc. Supply some details in the error message to make sure the user knows how to correct the issues.


[View source]
def set_sticker_emoji_list(sticker, emoji_list) #

Use this method to change the list of emoji assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot. Returns True on success.


[View source]
def set_sticker_keywords(sticker, keywords) #

Use this method to change search keywords assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot. Returns True on success.


[View source]
def set_sticker_mask_position(sticker, position) #

Use this method to change the mask position of a mask sticker. The sticker must belong to a sticker set that was created by the bot. Returns True on success.


[View source]
def set_sticker_position_in_set(sticker, position) #

Use this method to move a sticker in a set created by the bot to a specific position. Returns true on success.


[View source]
def set_sticker_set_thumbnail(name, user, thumbnail = nil) #

Use this method to set the thumbnail of a sticker set. Animated thumbnails can be set for animated sticker sets only. Returns true on success.


[View source]
def set_sticker_set_title(name, title) #

Use this method to set the title of a created sticker set. Returns True on success.


[View source]
def set_webhook(url, ip_address = nil, certificate = nil, max_connections = nil, allowed_updates = nil, drop_pending_updates = false, secret_token = nil) #

Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. Returns true on success.

If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. https://www.example.com/<token>. Since nobody else knows your bot‘s token, you can be pretty sure it’s us.


[View source]
def stop_message_live_location(chat, message = nil, inline_message = nil, reply_markup = nil) #

Use this method to stop updating a live location message before live_period expires.

On success, if the message was sent by the bot, the sent Message is returned, otherwise true is returned.


[View source]
def stop_poll(chat, message, reply_markup = nil) #

Use this method to stop a poll which was sent by the bot. On success, the stopped Poll with the final results is returned.


[View source]
def unban_chat_member(chat, user, only_if_banned = false) #

Use this method to unban a previously kicked user in a supergroup or channel. The user will not return to the group or channel automatically, but will be able to join via link, etc. The bot must be an administrator for this to work. Returns true on success.


[View source]
def unban_chat_sender_chat(chat, sender_chat) #

Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns True on success.


[View source]
def unhide_general_forum_topic(chat) #

Use this method to unhide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.


[View source]
def unpin_all_chat_messages(chat) #

[View source]
def unpin_all_forum_topic_messages(chat, message_thread_id) #

Use this method to clear the list of pinned messages in a forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success.


[View source]
def unpin_chat_message(chat, message = nil) #

Use this method to unpin a message in a group, a supergroup, or a channel. The bot must be an administrator in the chat for this to work and must have the ‘can_pin_messages’ admin right in the supergroup or ‘can_edit_messages’ admin right in the channel. Returns true on success.


[View source]
def unset_webhook #

Use this to unset the webhook and stop receiving updates to your bot.


[View source]
def upload_sticker_file(user_id, png_sticker) #

Use this method to upload a .png file with a sticker for later use in #create_new_sticker_set and #add_sticker_to_set methods (can be used multiple times). Returns the uploaded TFile on success.


[View source]
def use(middleware : Middleware) #

[View source]