class Telegram::Bot::Api
Public Class Methods
new(token = nil)
click to toggle source
# File lib/telegram/bot/api.rb, line 4 def initialize(token = nil) @token = token || Bot.configuration.token end
Public Instance Methods
addStickerToSet(user_id, name, png_sticker, emojis, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 218 def addStickerToSet(user_id, name, png_sticker, emojis, options = {}) request('addStickerToSet', { user_id: user_id, name: name, png_sticker: png_sticker, emojis: emojis }.merge(options)) end
answerCallbackQuery(callback_query_id, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 180 def answerCallbackQuery(callback_query_id, options = {}) request('answerCallbackQuery', {callback_query_id: callback_query_id}.merge(options)) end
connection()
click to toggle source
# File lib/telegram/bot/api.rb, line 251 def connection @conn ||= Faraday.new(url: API_URL) do |faraday| faraday.response :json, content_type: /\bjson$/ faraday.request :multipart faraday.request :url_encoded faraday.adapter Faraday.default_adapter end end
createNewStickerSet(user_id, name, title, png_sticker, emojis, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 212 def createNewStickerSet(user_id, name, title, png_sticker, emojis, options = {}) request('createNewStickerSet', { user_id: user_id, name: name, title: title, png_sticker: png_sticker, emojis: emojis }.merge(options)) end
deleteChatPhoto(chat_id)
click to toggle source
# File lib/telegram/bot/api.rb, line 132 def deleteChatPhoto(chat_id) request('deleteChatPhoto', {chat_id: chat_id}) end
deleteChatStickerSet(chat_id)
click to toggle source
# File lib/telegram/bot/api.rb, line 176 def deleteChatStickerSet(chat_id) request('deleteChatStickerSet', {chat_id: chat_id}) end
deleteMessage(chat_id, message_id)
click to toggle source
# File lib/telegram/bot/api.rb, line 196 def deleteMessage(chat_id, message_id) request('deleteMessage', {chat_id: chat_id, message_id: message_id}) end
deleteStickerFromSet(sticker)
click to toggle source
# File lib/telegram/bot/api.rb, line 228 def deleteStickerFromSet(sticker) request('deleteStickerFromSet', {sticker: sticker}) end
deleteWebhook()
click to toggle source
# File lib/telegram/bot/api.rb, line 20 def deleteWebhook request('deleteWebhook') end
editMessageCaption(options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 188 def editMessageCaption(options = {}) request('editMessageCaption', options, Types::Message) end
editMessageLiveLocation(latitude, longitude, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 80 def editMessageLiveLocation(latitude, longitude, options = {}) request('editMessageLiveLocation', {latitude: latitude, longitude: longitude}.merge(options), Types::Message) end
editMessageReplyMarkup(options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 192 def editMessageReplyMarkup(options = {}) request('editMessageReplyMarkup', options, Types::Message) end
editMessageText(text, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 184 def editMessageText(text, options = {}) request('editMessageText', {text: text}.merge(options), Types::Message) end
exportChatInviteLink(chat_id)
click to toggle source
# File lib/telegram/bot/api.rb, line 124 def exportChatInviteLink(chat_id) request('exportChatInviteLink', {chat_id: chat_id}) end
forwardMessage(chat_id, from_chat_id, message_id, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 40 def forwardMessage(chat_id, from_chat_id, message_id, options = {}) request('forwardMessage', { chat_id: chat_id, from_chat_id: from_chat_id, message_id: message_id }.merge(options), Types::Message) end
getChat(user_id)
click to toggle source
# File lib/telegram/bot/api.rb, line 156 def getChat(user_id) request('getChat', {chat_id: user_id}, Types::Chat) end
getChatAdministrators(chat_id)
click to toggle source
# File lib/telegram/bot/api.rb, line 160 def getChatAdministrators(chat_id) request('getChatAdministrators', {chat_id: chat_id}, Types::ChatMember, true) end
getChatMember(chat_id, user_id)
click to toggle source
# File lib/telegram/bot/api.rb, line 168 def getChatMember(chat_id, user_id) request('getChatMember', {chat_id: chat_id, user_id: user_id}, Types::ChatMember) end
getChatMembersCount(chat_id)
click to toggle source
# File lib/telegram/bot/api.rb, line 164 def getChatMembersCount(chat_id) request('getChatMembersCount', {chat_id: chat_id}) end
getFile(file_id)
click to toggle source
# File lib/telegram/bot/api.rb, line 32 def getFile(file_id) request('getFile', {file_id: file_id}, Types::File) end
getMe()
click to toggle source
# File lib/telegram/bot/api.rb, line 12 def getMe request('getMe', {}, Types::User) end
getStickerSet(name)
click to toggle source
# File lib/telegram/bot/api.rb, line 204 def getStickerSet(name) request('getStickerSet', {name: name}, Types::StickerSet) end
getUpdates(options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 28 def getUpdates(options = {}) request('getUpdates', options, Types::Update, true) end
getUserProfilePhotos(user_id, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 104 def getUserProfilePhotos(user_id, options = {}) request('getUserProfilePhotos', {user_id: user_id}.merge(options), Types::UserProfilePhotos) end
getWebhookInfo()
click to toggle source
# File lib/telegram/bot/api.rb, line 24 def getWebhookInfo request('getWebhookInfo', {}, Types::WebhookInfo) end
kickChatMember(chat_id, user_id, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 108 def kickChatMember(chat_id, user_id, options = {}) request('kickChatMember', {chat_id: chat_id, user_id: user_id}.merge(options)) end
leaveChat(chat_id)
click to toggle source
# File lib/telegram/bot/api.rb, line 152 def leaveChat(chat_id) request('leaveChat', {chat_id: chat_id}) end
pinChatMessage(chat_id, message_id, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 144 def pinChatMessage(chat_id, message_id, options = {}) request('pinChatMessage', {chat_id: chat_id, message_id: message_id}.merge(options)) end
promoteChatMember(chat_id, user_id, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 116 def promoteChatMember(chat_id, user_id, options = {}) request('promoteChatMember', {chat_id: chat_id, user_id: user_id}.merge(options)) end
request(method, query = {}, type_obj = nil, as_array = false)
click to toggle source
# File lib/telegram/bot/api.rb, line 232 def request(method, query = {}, type_obj = nil, as_array = false) query[:reply_markup] = query[:reply_markup].to_json if query.has_key?(:reply_markup) response = connection.post("/bot#{@token}/#{method}", query) body = response.body if Bot.configuration.raise_exceptions && (response.status != 200 || body['ok'] != true) raise Telegram::Bot::ResponseError.new(body['description']) end if type_obj.nil? body['result'] elsif as_array body['result'].map {|r| type_obj.new(r) } else type_obj.new(body['result']) end end
restrictChatMember(chat_id, user_id, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 120 def restrictChatMember(chat_id, user_id, options = {}) request('restrictChatMember', {chat_id: chat_id, user_id: user_id}.merge(options)) end
sendAudio(chat_id, audio, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 50 def sendAudio(chat_id, audio, options = {}) request('sendAudio', {chat_id: chat_id, audio: audio}.merge(options), Types::Message) end
sendChatAction(chat_id, action, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 100 def sendChatAction(chat_id, action, options = {}) request('sendChatAction', {chat_id: chat_id, action: action}.merge(options)) end
sendContact(chat_id, phone_number, first_name, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 94 def sendContact(chat_id, phone_number, first_name, options = {}) request('sendContact', { chat_id: chat_id, phone_number: phone_number, first_name: first_name }.merge(options), Types::Message) end
sendDocument(chat_id, document, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 54 def sendDocument(chat_id, document, options = {}) request('sendDocument', {chat_id: chat_id, document: document}.merge(options), Types::Message) end
sendLocation(chat_id, latitude, longitude, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 74 def sendLocation(chat_id, latitude, longitude, options = {}) request('sendLocation', { chat_id: chat_id, latitude: latitude, longitude: longitude }.merge(options), Types::Message) end
sendMediaGroup(chat_id, video_note, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 66 def sendMediaGroup(chat_id, video_note, options = {}) request('sendMediaGroup', {chat_id: chat_id, video_note: video_note}.merge(options), Types::Message) end
sendMessage(chat_id, text, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 36 def sendMessage(chat_id, text, options = {}) request('sendMessage', {chat_id: chat_id, text: text}.merge(options), Types::Message) end
sendPhoto(chat_id, photo, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 46 def sendPhoto(chat_id, photo, options = {}) request('sendPhoto', {chat_id: chat_id, photo: photo}.merge(options), Types::Message) end
sendSticker(chat_id, sticker, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 200 def sendSticker(chat_id, sticker, options = {}) request('sendSticker', {chat_id: chat_id, sticker: sticker}.merge(options), Types::Message) end
sendVenue(chat_id, latitude, longitude, title, address, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 88 def sendVenue(chat_id, latitude, longitude, title, address, options = {}) request('sendVenue', { chat_id: chat_id, latitude: latitude, longitude: longitude, title: title, address: address }.merge(options), Types::Message) end
sendVideo(chat_id, video, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 58 def sendVideo(chat_id, video, options = {}) request('sendVideo', {chat_id: chat_id, video: video}.merge(options), Types::Message) end
sendVideoNote(chat_id, media, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 70 def sendVideoNote(chat_id, media, options = {}) request('sendVideoNote', {chat_id: chat_id, media: media}.merge(options), Types::Message, true) end
sendVoice(chat_id, voice, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 62 def sendVoice(chat_id, voice, options = {}) request('sendVoice', {chat_id: chat_id, voice: voice}.merge(options), Types::Message) end
setChatDescription(chat_id, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 140 def setChatDescription(chat_id, options = {}) request('setChatDescription', {chat_id: chat_id}.merge(options)) end
setChatPhoto(chat_id, photo)
click to toggle source
# File lib/telegram/bot/api.rb, line 128 def setChatPhoto(chat_id, photo) request('setChatPhoto', {chat_id: chat_id, photo: photo}) end
setChatStickerSet(chat_id, sticker_set_name)
click to toggle source
# File lib/telegram/bot/api.rb, line 172 def setChatStickerSet(chat_id, sticker_set_name) request('setChatStickerSet', {chat_id: chat_id, sticker_set_name: sticker_set_name}) end
setChatTitle(chat_id, title)
click to toggle source
# File lib/telegram/bot/api.rb, line 136 def setChatTitle(chat_id, title) request('setChatTitle', {chat_id: chat_id, title: title}) end
setStickerPositionInSet(sticker, position)
click to toggle source
# File lib/telegram/bot/api.rb, line 224 def setStickerPositionInSet(sticker, position) request('setStickerPositionInSet', {sticker: sticker, position: position}) end
setWebhook(url, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 16 def setWebhook(url, options = {}) request('setWebhook', {url: url}.merge(options)) end
stopMessageLiveLocation(options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 84 def stopMessageLiveLocation(options = {}) request('stopMessageLiveLocation', options, Types::Message) end
token()
click to toggle source
# File lib/telegram/bot/api.rb, line 8 def token @token end
unbanChatMember(chat_id, user_id, options = {})
click to toggle source
# File lib/telegram/bot/api.rb, line 112 def unbanChatMember(chat_id, user_id, options = {}) request('unbanChatMember', {chat_id: chat_id, user_id: user_id}.merge(options)) end
unpinChatMessage(chat_id)
click to toggle source
# File lib/telegram/bot/api.rb, line 148 def unpinChatMessage(chat_id) request('unpinChatMessage', {chat_id: chat_id}) end
uploadStickerFile(user_id, png_sticker)
click to toggle source
# File lib/telegram/bot/api.rb, line 208 def uploadStickerFile(user_id, png_sticker) request('uploadStickerFile', {user_id: user_id, png_sticker: png_sticker}, Types::File) end