module Tourmaline::Client::CoreMethods

Direct including types

Defined in:

tourmaline/client/core_methods.cr

Instance Method Summary

Instance Method Detail

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_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 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 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) #

[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 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 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_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 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, icon_custom_emoji_id) #

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_message_caption(chat, caption, message = nil, inline_message = nil, parse_mode = Tourmaline::Client.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 = Tourmaline::Client.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_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_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_updates(offset = @next_offset, 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 is_admin?(chat_id) #

Convenience method to check if this bot is an admin in the current chat. See Client#get_chat_administrators for more info.

Note: This method should be used sparingly. It's much better to cache admins.


[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 next_offset : Int64 #

[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(delete_webhook = false, no_middleware_check = false) #

Start polling for updates. This method uses a combination of #get_updates and #handle_update to send continuously check Telegram's servers for updates.


[View source]
def polling : Bool #

[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 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 restrict_chat_member(chat, user, permissions, 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, 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) #

[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 = Tourmaline::Client.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) #

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 = Tourmaline::Client.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_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 = 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) #

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 = 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) #

Use this method to send photos. 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_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, 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) #

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 = Tourmaline::Client.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 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_permissions(chat, permissions) #

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_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_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 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_polling #

Stops the bot from polling.


[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 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]