class Ayanami::Bot

Bot is an interface for a Telegram Bot rubocop:disable Metrics/ClassLength

Public Class Methods

new(token) click to toggle source
# File lib/ayanami/bot.rb, line 9
def initialize(token)
  @token = token
end

Public Instance Methods

answer_callback_query(callback_query_id: nil, **args) click to toggle source

Sends answers to callback queries sent from inline keyboards.

# File lib/ayanami/bot.rb, line 158
def answer_callback_query(callback_query_id: nil, **args)
  request('answerCallbackQuery', __grab_parameters(__method__, binding))
end
answer_inline_query(inline_query_id: nil, results: nil, **args) click to toggle source

Answers to an inline query. On success, True is returned.

# File lib/ayanami/bot.rb, line 181
def answer_inline_query(inline_query_id: nil, results: nil, **args)
  request('answerInlineQuery', __grab_parameters(__method__, binding))
end
edit_message_caption(**args) click to toggle source

Changes captions of messages sent by the bot or via the bot (for inline bots).

# File lib/ayanami/bot.rb, line 170
def edit_message_caption(**args)
  request('editMessageCaption', args)
end
edit_message_reply_markup(**args) click to toggle source

Changes the markup of messages sent by the bot or via the bot (for inline bots).

# File lib/ayanami/bot.rb, line 176
def edit_message_reply_markup(**args)
  request('editMessageReplyMarkup', args)
end
edit_message_text(text: nil, **args) click to toggle source

Changes text and game messages sent by the bot or via the bot (for inline bots).

# File lib/ayanami/bot.rb, line 164
def edit_message_text(text: nil, **args)
  request('editMessageText', __grab_parameters(__method__, binding))
end
forward_message(chat_id: nil, from_chat_id: nil, message_id: nil, **args) click to toggle source

Forwards a message. On success, the sent Message is returned.

# File lib/ayanami/bot.rb, line 46
def forward_message(chat_id: nil, from_chat_id: nil, message_id: nil,
                    **args)
  request('forwardMessage', __grab_parameters(__method__, binding))
end
get_chat(chat_id: nil) click to toggle source

Returns information about the chat.

# File lib/ayanami/bot.rb, line 138
def get_chat(chat_id: nil)
  request('getChat', __grab_parameters(__method__, binding))
end
get_chat_administrators(chat_id: nil) click to toggle source

Returns a list of administratos in a chat.

# File lib/ayanami/bot.rb, line 143
def get_chat_administrators(chat_id: nil)
  request('getChatAdministrators', __grab_parameters(__method__, binding))
end
get_chat_member(chat_id: nil, user_id: nil) click to toggle source

Returns an information about a member of a chat.

# File lib/ayanami/bot.rb, line 153
def get_chat_member(chat_id: nil, user_id: nil)
  request('getChatMember', __grab_parameters(__method__, binding))
end
get_chat_members_count(chat_id: nil) click to toggle source

Returns the number of members in a chat.

# File lib/ayanami/bot.rb, line 148
def get_chat_members_count(chat_id: nil)
  request('getChatMembersCount', __grab_parameters(__method__, binding))
end
get_file(file_id: nil) click to toggle source

Returns a basic info about a file and prepare it for downloading. Bots can download files up to 20 MB in size.

# File lib/ayanami/bot.rb, line 118
def get_file(file_id: nil)
  request('getFile', __grab_parameters(__method__, binding))
end
get_me() click to toggle source

Returns basic information about the bot rubocop:disable Style/AccessorMethodName

# File lib/ayanami/bot.rb, line 31
def get_me
  request('getMe')
end
get_updates(**args) click to toggle source

Receives incoming updates.

# File lib/ayanami/bot.rb, line 36
def get_updates(**args)
  request('getUpdates', args)
end
get_user_profile_photos(user_id: nil, **args) click to toggle source

Returns a list of profile pictures for a user.

# File lib/ayanami/bot.rb, line 112
def get_user_profile_photos(user_id: nil, **args)
  request('getUserProfilePhotos', __grab_parameters(__method__, binding))
end
kick_chat_member(chat_id: nil, user_id: nil) click to toggle source

Kicks a chat member from a group/supergroup.

# File lib/ayanami/bot.rb, line 123
def kick_chat_member(chat_id: nil, user_id: nil)
  request('kickChatMember', __grab_parameters(__method__, binding))
end
leave_chat(chat_id: nil) click to toggle source

Leaves the group, supergroup, or channel.

# File lib/ayanami/bot.rb, line 128
def leave_chat(chat_id: nil)
  request('leaveChat', __grab_parameters(__method__, binding))
end
request(method, **args) click to toggle source
# File lib/ayanami/bot.rb, line 20
def request(method, **args)
  verify_arguments(args)
  res = RestClient.post("https://api.telegram.org/bot#{@token}/#{method}",
                        args)
  return JSON.parse(res)
rescue RestClient::ExceptionWithResponse => err
  err.response
end
send_audio(chat_id: nil, audio: nil, **args) click to toggle source

Sends audio. On success, the sent Message is returned.

# File lib/ayanami/bot.rb, line 57
def send_audio(chat_id: nil, audio: nil, **args)
  request('sendAudio', __grab_parameters(__method__, binding))
end
send_chat_action(chat_id: nil, action: nil) click to toggle source

Sends a status that tells something is happening. The status is set for 5 seconds or less. Returns True on success.

# File lib/ayanami/bot.rb, line 107
def send_chat_action(chat_id: nil, action: nil)
  request('sendChatAction', __grab_parameters(__method__, binding))
end
send_contact(chat_id: nil, phone_number: nil, first_name: nil, last_name: nil, **args) click to toggle source

Sends phone contacts. On success, the sent Message is returned.

# File lib/ayanami/bot.rb, line 100
def send_contact(chat_id: nil, phone_number: nil, first_name: nil,
                 last_name: nil, **args)
  request('sendContact', __grab_parameters(__method__, binding))
end
send_document(chat_id: nil, document: nil, **args) click to toggle source

Sends documents. On success, the sent Message is returned. Bots can currently send files of any type of up to 50 MB in size.

# File lib/ayanami/bot.rb, line 63
def send_document(chat_id: nil, document: nil, **args)
  request('sendDocument', __grab_parameters(__method__, binding))
end
send_game(chat_id: nil, game_short_name: nil, **args) click to toggle source

Sends a game. On success, the sent Message is returned.

# File lib/ayanami/bot.rb, line 186
def send_game(chat_id: nil, game_short_name: nil, **args)
  request('sendGame', __grab_parameters(__method__, binding))
end
send_location(chat_id: nil, latitude: nil, longitude: nil, **args) click to toggle source

Sends point on the map. On success, the sent Message is returned.

# File lib/ayanami/bot.rb, line 88
def send_location(chat_id: nil, latitude: nil, longitude: nil, **args)
  request('sendLocation', __grab_parameters(__method__, binding))
end
send_message(chat_id: nil, text: nil, **args) click to toggle source

Sends a Message. On success, the sent Message is returned.

# File lib/ayanami/bot.rb, line 41
def send_message(chat_id: nil, text: nil, **args)
  request('sendMessage', __grab_parameters(__method__, binding))
end
send_photo(chat_id: nil, photo: nil, **args) click to toggle source

Sends photos. On success, the sent Message is returned.

# File lib/ayanami/bot.rb, line 52
def send_photo(chat_id: nil, photo: nil, **args)
  request('sendPhoto', __grab_parameters(__method__, binding))
end
send_sticker(chat_id: nil, sticker: nil, **args) click to toggle source

Sends stickers. On success, the sent Message is returned.

# File lib/ayanami/bot.rb, line 68
def send_sticker(chat_id: nil, sticker: nil, **args)
  request('sendSticker', __grab_parameters(__method__, binding))
end
send_venue(chat_id: nil, latitude: nil, longitude: nil, title: nil, address: nil, **args) click to toggle source

Sends information about a venue. On success, the sent Message is returned. rubocop:disable Metrics/ParameterLists

# File lib/ayanami/bot.rb, line 94
def send_venue(chat_id: nil, latitude: nil, longitude: nil, title: nil,
               address: nil, **args)
  request('sendVenue', __grab_parameters(__method__, binding))
end
send_video(chat_id: nil, video: nil, **args) click to toggle source

Sends videos. 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.

# File lib/ayanami/bot.rb, line 75
def send_video(chat_id: nil, video: nil, **args)
  request('sendVideo', __grab_parameters(__method__, binding))
end
send_voice(chat_id: nil, voice: nil, **args) click to toggle source

Sends voice messages. The audio format 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.

# File lib/ayanami/bot.rb, line 83
def send_voice(chat_id: nil, voice: nil, **args)
  request('sendVoice', __grab_parameters(__method__, binding))
end
set_game_score(used_id: nil, score: nil, **args) click to toggle source

Sets 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. Returns an error, if the new score is not greater than the user’s current score in the chat.

# File lib/ayanami/bot.rb, line 194
def set_game_score(used_id: nil, score: nil, **args)
  request('setGameScore', __grab_parameters(__method__, binding))
end
unban_chat_member(chat_id: nil, user_id: nil) click to toggle source

Unbans previously kicked user in a supergroup.

# File lib/ayanami/bot.rb, line 133
def unban_chat_member(chat_id: nil, user_id: nil)
  request('unbanChatMember', __grab_parameters(__method__, binding))
end
verify_arguments(**args) click to toggle source
# File lib/ayanami/bot.rb, line 13
def verify_arguments(**args)
  args.each do |k, v|
    raise ArgumentError, "#{k} can't be nil. nil values aren't allowed"\
      if v.nil?
  end
end