Class: Telegram::Bot::Api
- Inherits:
-
Object
- Object
- Telegram::Bot::Api
- Defined in:
- lib/telegram/bot/api.rb
Instance Method Summary collapse
- #addStickerToSet(user_id, name, png_sticker, emojis, options = {}) ⇒ Object
- #answerCallbackQuery(callback_query_id, options = {}) ⇒ Object
- #connection ⇒ Object
- #createNewStickerSet(user_id, name, title, png_sticker, emojis, options = {}) ⇒ Object
- #deleteChatPhoto(chat_id) ⇒ Object
- #deleteChatStickerSet(chat_id) ⇒ Object
- #deleteMessage(chat_id, message_id) ⇒ Object
- #deleteStickerFromSet(sticker) ⇒ Object
- #deleteWebhook ⇒ Object
- #editMessageCaption(options = {}) ⇒ Object
- #editMessageLiveLocation(latitude, longitude, options = {}) ⇒ Object
- #editMessageReplyMarkup(options = {}) ⇒ Object
- #editMessageText(text, options = {}) ⇒ Object
- #exportChatInviteLink(chat_id) ⇒ Object
- #forwardMessage(chat_id, from_chat_id, message_id, options = {}) ⇒ Object
- #getChat(user_id) ⇒ Object
- #getChatAdministrators(chat_id) ⇒ Object
- #getChatMember(chat_id, user_id) ⇒ Object
- #getChatMembersCount(chat_id) ⇒ Object
- #getFile(file_id) ⇒ Object
- #getMe ⇒ Object
- #getStickerSet(name) ⇒ Object
- #getUpdates(options = {}) ⇒ Object
- #getUserProfilePhotos(user_id, options = {}) ⇒ Object
- #getWebhookInfo ⇒ Object
-
#initialize(token = nil) ⇒ Api
constructor
A new instance of Api.
- #kickChatMember(chat_id, user_id, options = {}) ⇒ Object
- #leaveChat(chat_id) ⇒ Object
- #pinChatMessage(chat_id, message_id, options = {}) ⇒ Object
- #promoteChatMember(chat_id, user_id, options = {}) ⇒ Object
- #request(method, query = {}, type_obj = nil, as_array = false) ⇒ Object
- #restrictChatMember(chat_id, user_id, options = {}) ⇒ Object
- #sendAudio(chat_id, audio, options = {}) ⇒ Object
- #sendChatAction(chat_id, action, options = {}) ⇒ Object
- #sendContact(chat_id, phone_number, first_name, options = {}) ⇒ Object
- #sendDocument(chat_id, document, options = {}) ⇒ Object
- #sendLocation(chat_id, latitude, longitude, options = {}) ⇒ Object
- #sendMediaGroup(chat_id, video_note, options = {}) ⇒ Object
- #sendMessage(chat_id, text, options = {}) ⇒ Object
- #sendPhoto(chat_id, photo, options = {}) ⇒ Object
- #sendSticker(chat_id, sticker, options = {}) ⇒ Object
- #sendVenue(chat_id, latitude, longitude, title, address, options = {}) ⇒ Object
- #sendVideo(chat_id, video, options = {}) ⇒ Object
- #sendVideoNote(chat_id, media, options = {}) ⇒ Object
- #sendVoice(chat_id, voice, options = {}) ⇒ Object
- #setChatDescription(chat_id, options = {}) ⇒ Object
- #setChatPhoto(chat_id, photo) ⇒ Object
- #setChatStickerSet(chat_id, sticker_set_name) ⇒ Object
- #setChatTitle(chat_id, title) ⇒ Object
- #setStickerPositionInSet(sticker, position) ⇒ Object
- #setWebhook(url, options = {}) ⇒ Object
- #stopMessageLiveLocation(options = {}) ⇒ Object
- #token ⇒ Object
- #unbanChatMember(chat_id, user_id, options = {}) ⇒ Object
- #unpinChatMessage(chat_id) ⇒ Object
- #uploadStickerFile(user_id, png_sticker) ⇒ Object
Constructor Details
#initialize(token = nil) ⇒ Api
Returns a new instance of Api.
4 5 6 |
# File 'lib/telegram/bot/api.rb', line 4 def initialize(token = nil) @token = token || Bot.configuration.token end |
Instance Method Details
#addStickerToSet(user_id, name, png_sticker, emojis, options = {}) ⇒ Object
218 219 220 221 222 |
# File 'lib/telegram/bot/api.rb', line 218 def addStickerToSet(user_id, name, png_sticker, emojis, = {}) request('addStickerToSet', { user_id: user_id, name: name, png_sticker: png_sticker, emojis: emojis }.merge()) end |
#answerCallbackQuery(callback_query_id, options = {}) ⇒ Object
180 181 182 |
# File 'lib/telegram/bot/api.rb', line 180 def answerCallbackQuery(callback_query_id, = {}) request('answerCallbackQuery', {callback_query_id: callback_query_id}.merge()) end |
#connection ⇒ Object
251 252 253 254 255 256 257 258 |
# 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 = {}) ⇒ Object
212 213 214 215 216 |
# File 'lib/telegram/bot/api.rb', line 212 def createNewStickerSet(user_id, name, title, png_sticker, emojis, = {}) request('createNewStickerSet', { user_id: user_id, name: name, title: title, png_sticker: png_sticker, emojis: emojis }.merge()) end |
#deleteChatPhoto(chat_id) ⇒ Object
132 133 134 |
# File 'lib/telegram/bot/api.rb', line 132 def deleteChatPhoto(chat_id) request('deleteChatPhoto', {chat_id: chat_id}) end |
#deleteChatStickerSet(chat_id) ⇒ Object
176 177 178 |
# File 'lib/telegram/bot/api.rb', line 176 def deleteChatStickerSet(chat_id) request('deleteChatStickerSet', {chat_id: chat_id}) end |
#deleteMessage(chat_id, message_id) ⇒ Object
196 197 198 |
# File 'lib/telegram/bot/api.rb', line 196 def deleteMessage(chat_id, ) request('deleteMessage', {chat_id: chat_id, message_id: }) end |
#deleteStickerFromSet(sticker) ⇒ Object
228 229 230 |
# File 'lib/telegram/bot/api.rb', line 228 def deleteStickerFromSet(sticker) request('deleteStickerFromSet', {sticker: sticker}) end |
#deleteWebhook ⇒ Object
20 21 22 |
# File 'lib/telegram/bot/api.rb', line 20 def deleteWebhook request('deleteWebhook') end |
#editMessageCaption(options = {}) ⇒ Object
188 189 190 |
# File 'lib/telegram/bot/api.rb', line 188 def editMessageCaption( = {}) request('editMessageCaption', , Types::Message) end |
#editMessageLiveLocation(latitude, longitude, options = {}) ⇒ Object
80 81 82 |
# File 'lib/telegram/bot/api.rb', line 80 def editMessageLiveLocation(latitude, longitude, = {}) request('editMessageLiveLocation', {latitude: latitude, longitude: longitude}.merge(), Types::Message) end |
#editMessageReplyMarkup(options = {}) ⇒ Object
192 193 194 |
# File 'lib/telegram/bot/api.rb', line 192 def editMessageReplyMarkup( = {}) request('editMessageReplyMarkup', , Types::Message) end |
#editMessageText(text, options = {}) ⇒ Object
184 185 186 |
# File 'lib/telegram/bot/api.rb', line 184 def editMessageText(text, = {}) request('editMessageText', {text: text}.merge(), Types::Message) end |
#exportChatInviteLink(chat_id) ⇒ Object
124 125 126 |
# 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 = {}) ⇒ Object
40 41 42 43 44 |
# File 'lib/telegram/bot/api.rb', line 40 def forwardMessage(chat_id, from_chat_id, , = {}) request('forwardMessage', { chat_id: chat_id, from_chat_id: from_chat_id, message_id: }.merge(), Types::Message) end |
#getChat(user_id) ⇒ Object
156 157 158 |
# File 'lib/telegram/bot/api.rb', line 156 def getChat(user_id) request('getChat', {chat_id: user_id}, Types::Chat) end |
#getChatAdministrators(chat_id) ⇒ Object
160 161 162 |
# 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) ⇒ Object
168 169 170 |
# 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) ⇒ Object
164 165 166 |
# File 'lib/telegram/bot/api.rb', line 164 def getChatMembersCount(chat_id) request('getChatMembersCount', {chat_id: chat_id}) end |
#getFile(file_id) ⇒ Object
32 33 34 |
# File 'lib/telegram/bot/api.rb', line 32 def getFile(file_id) request('getFile', {file_id: file_id}, Types::File) end |
#getMe ⇒ Object
12 13 14 |
# File 'lib/telegram/bot/api.rb', line 12 def getMe request('getMe', {}, Types::User) end |
#getStickerSet(name) ⇒ Object
204 205 206 |
# File 'lib/telegram/bot/api.rb', line 204 def getStickerSet(name) request('getStickerSet', {name: name}, Types::StickerSet) end |
#getUpdates(options = {}) ⇒ Object
28 29 30 |
# File 'lib/telegram/bot/api.rb', line 28 def getUpdates( = {}) request('getUpdates', , Types::Update, true) end |
#getUserProfilePhotos(user_id, options = {}) ⇒ Object
104 105 106 |
# File 'lib/telegram/bot/api.rb', line 104 def getUserProfilePhotos(user_id, = {}) request('getUserProfilePhotos', {user_id: user_id}.merge(), Types::UserProfilePhotos) end |
#getWebhookInfo ⇒ Object
24 25 26 |
# File 'lib/telegram/bot/api.rb', line 24 def getWebhookInfo request('getWebhookInfo', {}, Types::WebhookInfo) end |
#kickChatMember(chat_id, user_id, options = {}) ⇒ Object
108 109 110 |
# File 'lib/telegram/bot/api.rb', line 108 def kickChatMember(chat_id, user_id, = {}) request('kickChatMember', {chat_id: chat_id, user_id: user_id}.merge()) end |
#leaveChat(chat_id) ⇒ Object
152 153 154 |
# 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 = {}) ⇒ Object
144 145 146 |
# File 'lib/telegram/bot/api.rb', line 144 def pinChatMessage(chat_id, , = {}) request('pinChatMessage', {chat_id: chat_id, message_id: }.merge()) end |
#promoteChatMember(chat_id, user_id, options = {}) ⇒ Object
116 117 118 |
# File 'lib/telegram/bot/api.rb', line 116 def promoteChatMember(chat_id, user_id, = {}) request('promoteChatMember', {chat_id: chat_id, user_id: user_id}.merge()) end |
#request(method, query = {}, type_obj = nil, as_array = false) ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# 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 = {}) ⇒ Object
120 121 122 |
# File 'lib/telegram/bot/api.rb', line 120 def restrictChatMember(chat_id, user_id, = {}) request('restrictChatMember', {chat_id: chat_id, user_id: user_id}.merge()) end |
#sendAudio(chat_id, audio, options = {}) ⇒ Object
50 51 52 |
# File 'lib/telegram/bot/api.rb', line 50 def sendAudio(chat_id, audio, = {}) request('sendAudio', {chat_id: chat_id, audio: audio}.merge(), Types::Message) end |
#sendChatAction(chat_id, action, options = {}) ⇒ Object
100 101 102 |
# File 'lib/telegram/bot/api.rb', line 100 def sendChatAction(chat_id, action, = {}) request('sendChatAction', {chat_id: chat_id, action: action}.merge()) end |
#sendContact(chat_id, phone_number, first_name, options = {}) ⇒ Object
94 95 96 97 98 |
# File 'lib/telegram/bot/api.rb', line 94 def sendContact(chat_id, phone_number, first_name, = {}) request('sendContact', { chat_id: chat_id, phone_number: phone_number, first_name: first_name }.merge(), Types::Message) end |
#sendDocument(chat_id, document, options = {}) ⇒ Object
54 55 56 |
# File 'lib/telegram/bot/api.rb', line 54 def sendDocument(chat_id, document, = {}) request('sendDocument', {chat_id: chat_id, document: document}.merge(), Types::Message) end |
#sendLocation(chat_id, latitude, longitude, options = {}) ⇒ Object
74 75 76 77 78 |
# File 'lib/telegram/bot/api.rb', line 74 def sendLocation(chat_id, latitude, longitude, = {}) request('sendLocation', { chat_id: chat_id, latitude: latitude, longitude: longitude }.merge(), Types::Message) end |
#sendMediaGroup(chat_id, video_note, options = {}) ⇒ Object
66 67 68 |
# File 'lib/telegram/bot/api.rb', line 66 def sendMediaGroup(chat_id, video_note, = {}) request('sendMediaGroup', {chat_id: chat_id, video_note: video_note}.merge(), Types::Message) end |
#sendMessage(chat_id, text, options = {}) ⇒ Object
36 37 38 |
# File 'lib/telegram/bot/api.rb', line 36 def sendMessage(chat_id, text, = {}) request('sendMessage', {chat_id: chat_id, text: text}.merge(), Types::Message) end |
#sendPhoto(chat_id, photo, options = {}) ⇒ Object
46 47 48 |
# File 'lib/telegram/bot/api.rb', line 46 def sendPhoto(chat_id, photo, = {}) request('sendPhoto', {chat_id: chat_id, photo: photo}.merge(), Types::Message) end |
#sendSticker(chat_id, sticker, options = {}) ⇒ Object
200 201 202 |
# File 'lib/telegram/bot/api.rb', line 200 def sendSticker(chat_id, sticker, = {}) request('sendSticker', {chat_id: chat_id, sticker: sticker}.merge(), Types::Message) end |
#sendVenue(chat_id, latitude, longitude, title, address, options = {}) ⇒ Object
88 89 90 91 92 |
# File 'lib/telegram/bot/api.rb', line 88 def sendVenue(chat_id, latitude, longitude, title, address, = {}) request('sendVenue', { chat_id: chat_id, latitude: latitude, longitude: longitude, title: title, address: address }.merge(), Types::Message) end |
#sendVideo(chat_id, video, options = {}) ⇒ Object
58 59 60 |
# File 'lib/telegram/bot/api.rb', line 58 def sendVideo(chat_id, video, = {}) request('sendVideo', {chat_id: chat_id, video: video}.merge(), Types::Message) end |
#sendVideoNote(chat_id, media, options = {}) ⇒ Object
70 71 72 |
# File 'lib/telegram/bot/api.rb', line 70 def sendVideoNote(chat_id, media, = {}) request('sendVideoNote', {chat_id: chat_id, media: media}.merge(), Types::Message, true) end |
#sendVoice(chat_id, voice, options = {}) ⇒ Object
62 63 64 |
# File 'lib/telegram/bot/api.rb', line 62 def sendVoice(chat_id, voice, = {}) request('sendVoice', {chat_id: chat_id, voice: voice}.merge(), Types::Message) end |
#setChatDescription(chat_id, options = {}) ⇒ Object
140 141 142 |
# File 'lib/telegram/bot/api.rb', line 140 def setChatDescription(chat_id, = {}) request('setChatDescription', {chat_id: chat_id}.merge()) end |
#setChatPhoto(chat_id, photo) ⇒ Object
128 129 130 |
# 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) ⇒ Object
172 173 174 |
# 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) ⇒ Object
136 137 138 |
# 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) ⇒ Object
224 225 226 |
# File 'lib/telegram/bot/api.rb', line 224 def setStickerPositionInSet(sticker, position) request('setStickerPositionInSet', {sticker: sticker, position: position}) end |
#setWebhook(url, options = {}) ⇒ Object
16 17 18 |
# File 'lib/telegram/bot/api.rb', line 16 def setWebhook(url, = {}) request('setWebhook', {url: url}.merge()) end |
#stopMessageLiveLocation(options = {}) ⇒ Object
84 85 86 |
# File 'lib/telegram/bot/api.rb', line 84 def stopMessageLiveLocation( = {}) request('stopMessageLiveLocation', , Types::Message) end |
#token ⇒ Object
8 9 10 |
# File 'lib/telegram/bot/api.rb', line 8 def token @token end |
#unbanChatMember(chat_id, user_id, options = {}) ⇒ Object
112 113 114 |
# File 'lib/telegram/bot/api.rb', line 112 def unbanChatMember(chat_id, user_id, = {}) request('unbanChatMember', {chat_id: chat_id, user_id: user_id}.merge()) end |
#unpinChatMessage(chat_id) ⇒ Object
148 149 150 |
# File 'lib/telegram/bot/api.rb', line 148 def unpinChatMessage(chat_id) request('unpinChatMessage', {chat_id: chat_id}) end |