Skip to content

module Tourmaline::Client::CoreMethods #

Included modules

Tourmaline::Logger

Direct including types

Tourmaline::Client

Constants#

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

Methods#

#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

#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

#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

#copy_message(chat, from_chat, message, caption = nil, parse_mode = @default_parse_mode, caption_entities = [] of MessageEntity, disable_notification = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil) #

View source

#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

#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

#delete_my_commands(scope : BotCommandScope? = nil, language_code : String? = 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

#download_file(file_id, path = nil) #

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

View source

#edit_message_caption(chat, caption, message = nil, inline_message = nil, parse_mode = @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

#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

#edit_message_media(chat, media, message = nil, inline_message = nil, reply_markup = nil) #

View source

#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

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

#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

#forward_message(chat, from_chat, message, disable_notification = false) #

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

View source

#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

#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

#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

#get_chat_members_count(chat) #

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

View source

#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

#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

#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

#get_my_commands(scope : BotCommandScope? = nil, language_code : String? = 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

#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

#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

#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

#kick_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

#leave_chat(chat) #

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

View source

#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

#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

#next_offset : Int64 #

View source

#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

#poll(delete_webhook = 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

#polling : Bool #

View source

#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_voice_chats = nil, can_restrict_members = nil, can_pin_messages = nil, can_promote_members = 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

#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

#send_animation(chat, animation, duration = nil, width = nil, height = nil, thumb = nil, caption = nil, caption_entities = [] of MessageEntity, parse_mode = @default_parse_mode, disable_notification = false, reply_to_message = nil, allow_sending_without_reply = false, reply_markup = nil) #

View source

#send_audio(chat, audio, caption = nil, caption_entities = [] of MessageEntity, duration = nil, preformer = nil, title = nil, parse_mode = @default_parse_mode, disable_notification = 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

#send_basketball(chat, disable_notification = 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

#send_bowling(chat, disable_notification = 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

#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

#send_contact(chat, phone_number, first_name, last_name = nil, disable_notification = 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

#send_dart(chat, disable_notification = 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

#send_dice(chat, disable_notification = 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

#send_document(chat, document, caption = nil, caption_entities = [] of MessageEntity, parse_mode = @default_parse_mode, disable_notification = 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

#send_football(chat, disable_notification = 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

#send_location(chat, latitude, longitude, horizontal_accuracy = nil, live_period = nil, proximity_alert_radius = nil, heading = nil, disable_notification = 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

#send_media_group(chat, media : Array(InputMediaPhoto | InputMediaVideo | InputMediaAudio | InputMediaDocument), disable_notification = 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

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

View source

#send_photo(chat, photo, caption = nil, parse_mode = @default_parse_mode, caption_entities = [] of MessageEntity, disable_notification = 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

#send_slot_machine(chat, disable_notification = 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

#send_soccerball(chat, disable_notification = 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

#send_venue(chat, latitude, longitude, title, address, foursquare_id = nil, foursquare_type = nil, google_place_id = nil, google_place_type = nil, disable_notification = 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

#send_video(chat, video, duration = nil, width = nil, height = nil, caption = nil, caption_entities = [] of MessageEntity, parse_mode = @default_parse_mode, disable_notification = 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

#send_video_note(chat, video_note, duration = nil, width = nil, height = nil, caption = nil, caption_entities = [] of MessageEntity, parse_mode = @default_parse_mode, disable_notification = 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

#send_voice(chat, voice, caption = nil, caption_entities = [] of MessageEntity, duration = nil, preformer = nil, title = nil, disable_notification = 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

#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

#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

#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

#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

#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

#set_my_commands(commands : Array(BotCommand | NamedTuple()), scope : BotCommandScope? = nil, language_code : String? = nil) #

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

View source

#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

#stop_polling #

Stops the bot from polling.

View source

#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

#unpin_all_chat_messages(chat) #

View source

#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