Module: Telegram::OtherApis

Includes:
CoreApi
Included in:
AllApis, Client
Defined in:
lib/api/other_apis.rb

Instance Method Summary collapse

Methods included from CoreApi

#http_get, #http_post

Instance Method Details

#add_sticker_to_set(user_id, name, emojis, params = {}) ⇒ Object

Use this method to add a new sticker to a set created by the bot.



122
123
124
125
126
127
128
129
# File 'lib/api/other_apis.rb', line 122

def add_sticker_to_set(user_id, name, emojis, params = {})
  hash = { user_id: user_id, name: name, emojis: emojis }.merge!(params)
  response = http_post('addStickerToSet', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    throw StandardError, response.description
  end
  response.result
end

#answer_callback_query(callback_query_id, params = {}) ⇒ Object

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.



139
140
141
142
143
144
145
146
# File 'lib/api/other_apis.rb', line 139

def answer_callback_query(callback_query_id, params = {})
  hash = { callback_query_id: callback_query_id }.merge!(params)
  response = http_post('answerCallbackQuery', hash)
  unless response.ok
    raise FatalError, response.description
  end
  response.result
end

#answer_inline_query(inline_query_id, result, params = {}) ⇒ Object

Use this method to send answers to an inline query. On success, True is returned. No more than 50 results per query are allowed.



216
217
218
219
220
221
222
223
# File 'lib/api/other_apis.rb', line 216

def answer_inline_query(inline_query_id, result, params = {})
  hash = { inline_query_id: inline_query_id, result: result }.merge!(params)
  response = http_post('answerInlineQuery', hash)
  unless response.ok
   fail FatalError, response.description
  end
  response.result
end

#create_new_stricker_set(user_id, name, title, params = {}) ⇒ Object

Use this method to create a new sticker set owned by a user. The bot will be able to edit the sticker set thus created. You must use exactly one of the fields png_sticker or tgs_sticker.



112
113
114
115
116
117
118
119
# File 'lib/api/other_apis.rb', line 112

def create_new_stricker_set(user_id, name, title, params = {})
  hash = { user_id: user_id, name: name, title: title }.merge!(params)
  response = http_post('createNewStickerSet', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail Error, response.description
  end
  response.result
end

#delete_webhookObject



148
149
150
# File 'lib/api/other_apis.rb', line 148

def delete_webhook
  fail NotImplementedError, 'not support for now'
end

#edit_message_caption(params = {}) ⇒ Object

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.



170
171
172
173
174
175
176
177
178
179
# File 'lib/api/other_apis.rb', line 170

def edit_message_caption(params = {})
  response = http_post('editMessageCaption', params)
  unless response.ok
    fail FatalError, response.description
  end
  if response.result == true
    return true
  end
  Message.new(response.result)
end

#edit_message_live_locationObject



131
132
133
# File 'lib/api/other_apis.rb', line 131

def edit_message_live_location
  fail NotImplementedError, 'not implemented'
end

#edit_message_media(media, params = {}) ⇒ Object

Use this method to edit animation, audio, document, photo, or video messages. If a message is a part of a message album, then it can be edited only to a photo or a video. Otherwise, message type can be changed arbitrarily. When inline message is edited, new file can’t be uploaded. Use previously uploaded file via its file_id or specify a URL. On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.



188
189
190
191
192
193
194
195
196
197
198
# File 'lib/api/other_apis.rb', line 188

def edit_message_media(media, params = {})
  hash = { media: media }.merge!(params)
  response = http_post('editMessageMedia', hash)
  unless response.ok
    fail FatalError, response.description
  end
  if response.result == true
    return true
  end
  Message.new(response.result)
end

#edit_message_reply_markup(params = {}) ⇒ Object

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.



203
204
205
206
207
208
209
210
211
212
# File 'lib/api/other_apis.rb', line 203

def edit_message_reply_markup(params = {})
  response = http_post('editMessageReplyMarkup', params)
  unless response.ok
    fail FatalError, response.description
  end
  if response.result == true
    return true
  end
  Message.new(response.result)
end

#edit_message_text(text, params = {}) ⇒ Object

Use this method to edit text and game messages. On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.



155
156
157
158
159
160
161
162
163
164
165
# File 'lib/api/other_apis.rb', line 155

def edit_message_text(text, params = {})
  hash = { text: text }.merge!(params)
  response = http_post('editMessageText', hash)
  unless response.ok
    fail FatalError, response.description
  end
  if response.result == true
    return true
  end
  Message.new(response.result)
end

Use this method to generate a new invite link for a chat.



67
68
69
70
71
72
73
74
# File 'lib/api/other_apis.rb', line 67

def export_chat_link(chat_id)
  hash = { chat_id: chat_id }
  response = http_post('exportChatInviteLink', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail TelegramError, response.description
  end
  response.result
end

#forward_message(from_chat_id, to_chat_id, message_id, params = {}) ⇒ Object

Use this method to forward messages of any kind.



10
11
12
13
14
15
16
17
18
19
# File 'lib/api/other_apis.rb', line 10

def forward_message(from_chat_id, to_chat_id, message_id, params = {})
  hash = { chat_id: to_chat_id, from_chat_id: from_chat_id }
  hash2 = { message_id: message_id }.merge!(params)
  hash.merge!(hash2)
  data = http_post('forwardMessage', hash)
  unless data.ok # rubocop:disable Style/IfUnlessModifier
    fail TelegramError, data.description
  end
  data.result
end

#kick_chat_member(chat_id, user_id, params = {}) ⇒ Object

Use this method to kick a user from a group, a supergroup or a channel.



23
24
25
26
27
28
29
30
# File 'lib/api/other_apis.rb', line 23

def kick_chat_member(chat_id, user_id, params = {})
  hash = { chat_id: chat_id, user_id: user_id }.merge!(params)
  data = http_post('kickChatMember', hash)
  unless data.ok # rubocop:disable Style/IfUnlessModifier
    fail TelegramError, data.description
  end
  data.result
end

#pin_chat_message(chat_id, message_id, params = {}) ⇒ Object

Use this method to pin a message in a group, a supergroup, or a channel.



78
79
80
81
82
83
84
85
# File 'lib/api/other_apis.rb', line 78

def pin_chat_message(chat_id, message_id, params = {})
  hash = { chat_id: chat_id, message_id: message_id }.merge!(params)
  response = http_post('pinChatMessage', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail SecurityError, response.description
  end
  response.result
end

#promote_chat_member(chat_id, user_id, params = {}) ⇒ Object

Use this method to promote or demote a user in a supergroup or a channel.



57
58
59
60
61
62
63
64
# File 'lib/api/other_apis.rb', line 57

def promote_chat_member(chat_id, user_id, params = {})
  hash = { chat_id: chat_id, user_id: user_id }.merge!(params)
  data = http_post('promoteChatMember', hash)
  unless data.ok # rubocop:disable Style/IfUnlessModifier
    fail TelegramError, data.description
  end
  data.result
end

#restrict_chat_member(chat_id, user_id, permissions, params = {}) ⇒ Object

Use this method to restrict a user in a supergroup.



44
45
46
47
48
49
50
51
52
53
# File 'lib/api/other_apis.rb', line 44

def restrict_chat_member(chat_id, user_id, permissions, params = {})
  hash = { chat_id: chat_id, user_id: user_id }
  hash2 = { permissions: permissions }
  hash.merge!(hash2)
  data = http_post('restrictChatMember', hash)
  unless data.ok # rubocop:disable Style/IfUnlessModifier
    fail TelegramError, data.description
  end
  data.result
end

#stop_poll(chat_id, message_id, params = {}) ⇒ Object

Use this method to stop a poll which was sent by the bot.



88
89
90
91
92
93
94
95
# File 'lib/api/other_apis.rb', line 88

def stop_poll(chat_id, message_id, params = {})
  hash = { chat_id: chat_id, message_id: message_id }.merge!(params)
  response = http_post('stopPoll', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail Error, response.description
  end
  response.result
end

#unban_chat_member(chat_id, user_id) ⇒ Object

Use this method to unban a previously kicked user in a supergroup or channel.



34
35
36
37
38
39
40
41
# File 'lib/api/other_apis.rb', line 34

def unban_chat_member(chat_id, user_id)
  hash = { chat_id: chat_id, user_id: user_id }
  data = http_post('unbanChatMember', hash)
  unless data.ok # rubocop:disable Style/IfUnlessModifier
    fail TelegramError, data.description
  end
  data.result
end

#upload_sticker_file(user_id, png_sticker) ⇒ Object

Use this method to upload a .PNG file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times).



100
101
102
103
104
105
106
107
# File 'lib/api/other_apis.rb', line 100

def upload_sticker_file(user_id, png_sticker)
  hash = { user_id: user_id, png_sticker: png_sticker }
  response = http_post('uploadStickerFile', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail Error, response.description
  end
  response.result
end