teleruby 1.5.1 → 1.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +9 -0
- data/README.md +398 -0
- data/lib/api/all.rb +12 -0
- data/lib/api/delete_apis.rb +55 -0
- data/lib/api/get_apis.rb +162 -0
- data/lib/api/nstandard.rb +26 -0
- data/lib/api/other_apis.rb +225 -0
- data/lib/api/send_apis.rb +191 -0
- data/lib/api/set_apis.rb +130 -0
- data/lib/core_api.rb +41 -0
- data/lib/objects/all.rb +42 -0
- data/lib/objects/animation.rb +38 -0
- data/lib/objects/audio.rb +37 -0
- data/lib/objects/bot_command.rb +24 -0
- data/lib/objects/callback_query.rb +64 -0
- data/lib/objects/chat.rb +158 -0
- data/lib/objects/chat_member.rb +142 -0
- data/lib/objects/chat_permissions.rb +59 -0
- data/lib/objects/chat_photo.rb +37 -0
- data/lib/objects/chosen_inline_result.rb +43 -0
- data/lib/objects/contact.rb +37 -0
- data/lib/objects/dice.rb +21 -0
- data/lib/objects/document.rb +27 -0
- data/lib/objects/file.rb +32 -0
- data/lib/objects/game.rb +65 -0
- data/lib/objects/inline_query.rb +42 -0
- data/lib/objects/inlinekeyboardbutton.rb +59 -0
- data/lib/objects/inlinekeyboardmarkup.rb +30 -0
- data/lib/objects/location.rb +21 -0
- data/lib/objects/mask_position.rb +35 -0
- data/lib/objects/message.rb +378 -0
- data/lib/objects/message_entity.rb +93 -0
- data/lib/objects/order_info.rb +34 -0
- data/lib/objects/photo_size.rb +14 -0
- data/lib/objects/poll.rb +97 -0
- data/lib/objects/poll_answer.rb +29 -0
- data/lib/objects/poll_option.rb +22 -0
- data/lib/objects/pre_checkout_query.rb +48 -0
- data/lib/objects/same/common.rb +37 -0
- data/lib/objects/same/common_2.rb +38 -0
- data/lib/objects/shipping_address.rb +39 -0
- data/lib/objects/shipping_query.rb +32 -0
- data/lib/objects/sticker.rb +55 -0
- data/lib/objects/update.rb +174 -0
- data/lib/objects/user.rb +66 -0
- data/lib/objects/user_profile_photos.rb +35 -0
- data/lib/objects/venue.rb +40 -0
- data/lib/objects/video.rb +37 -0
- data/lib/objects/video_note.rb +48 -0
- data/lib/objects/voice.rb +20 -0
- data/lib/teleruby.rb +4 -40
- data/lib/teleruby/all_apis.rb +22 -0
- data/lib/teleruby/api/delete_apis.rb +58 -0
- data/lib/teleruby/api/get_apis.rb +172 -0
- data/lib/teleruby/api/nstandard.rb +27 -0
- data/lib/teleruby/api/other_apis.rb +241 -0
- data/lib/teleruby/api/send_apis.rb +206 -0
- data/lib/teleruby/api/set_apis.rb +137 -0
- data/lib/teleruby/core_api.rb +52 -0
- data/lib/teleruby/objects/all.rb +42 -0
- data/lib/teleruby/objects/animation.rb +40 -0
- data/lib/teleruby/objects/audio.rb +39 -0
- data/lib/teleruby/objects/bot_command.rb +24 -0
- data/lib/teleruby/objects/callback_query.rb +66 -0
- data/lib/teleruby/objects/chat.rb +164 -0
- data/lib/teleruby/objects/chat_member.rb +142 -0
- data/lib/teleruby/objects/chat_permissions.rb +59 -0
- data/lib/teleruby/objects/chat_photo.rb +37 -0
- data/lib/teleruby/objects/chosen_inline_result.rb +45 -0
- data/lib/teleruby/objects/contact.rb +37 -0
- data/lib/teleruby/objects/dice.rb +21 -0
- data/lib/teleruby/objects/document.rb +29 -0
- data/lib/teleruby/objects/file.rb +32 -0
- data/lib/teleruby/objects/game.rb +65 -0
- data/lib/teleruby/objects/inline_query.rb +44 -0
- data/lib/teleruby/objects/inlinekeyboardbutton.rb +59 -0
- data/lib/teleruby/objects/inlinekeyboardmarkup.rb +31 -0
- data/lib/teleruby/objects/location.rb +21 -0
- data/lib/teleruby/objects/mask_position.rb +35 -0
- data/lib/teleruby/objects/message.rb +400 -0
- data/lib/teleruby/objects/message_entity.rb +95 -0
- data/lib/teleruby/objects/order_info.rb +36 -0
- data/lib/teleruby/objects/photo_size.rb +14 -0
- data/lib/teleruby/objects/poll.rb +97 -0
- data/lib/teleruby/objects/poll_answer.rb +29 -0
- data/lib/teleruby/objects/poll_option.rb +22 -0
- data/lib/teleruby/objects/pre_checkout_query.rb +50 -0
- data/lib/teleruby/objects/same/common.rb +31 -0
- data/lib/teleruby/objects/same/common_2.rb +32 -0
- data/lib/teleruby/objects/shipping_address.rb +39 -0
- data/lib/teleruby/objects/shipping_query.rb +32 -0
- data/lib/teleruby/objects/sticker.rb +59 -0
- data/lib/teleruby/objects/update.rb +207 -0
- data/lib/teleruby/objects/user.rb +66 -0
- data/lib/teleruby/objects/user_profile_photos.rb +36 -0
- data/lib/teleruby/objects/venue.rb +40 -0
- data/lib/teleruby/objects/video.rb +39 -0
- data/lib/teleruby/objects/video_note.rb +50 -0
- data/lib/teleruby/objects/voice.rb +20 -0
- data/lib/teleruby/version.rb +3 -0
- data/msg.png +0 -0
- data/rdoc.png +0 -0
- data/teleruby.gemspec +9 -7
- metadata +109 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8323bf733744d8b1f032534ad087c398b4d54d466e3990a263905698d42517ba
|
4
|
+
data.tar.gz: 89109597ff80a96beef742e102ad36f45e49f028aa0e59f12ce4a5da2f0b0e65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d94858861777a0c9d69b757421dcd8ac045e5e1a4d279e0ea0f31f0a1fa5cab55b1a7d61459e4d1be462e280643d0cde1d3db8b2213a58bfc306e285a15f5cbc
|
7
|
+
data.tar.gz: 7839a39dde8b1e3915553b48c5e90cc8f682f24e64c7ae4b3909145e80c92d4b28d4c3d48d4fc835fc8a43649db156c0877a870585168b3ebbf54821f2ff8033
|
data/LICENSE.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
Copyright (C) 2020 Solomon Boloshe
|
2
|
+
|
3
|
+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
4
|
+
|
5
|
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
6
|
+
|
7
|
+
You should have received a copy of the GNU General Public License along with this program. If not, [see](https://www.gnu.org/licenses/)
|
8
|
+
|
9
|
+
|
data/README.md
ADDED
@@ -0,0 +1,398 @@
|
|
1
|
+
# Teleruby
|
2
|
+
|
3
|
+
Is a lightweigth Ruby wrapper for Telegram bot.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'teleruby'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ sudo gem install teleruby
|
20
|
+
|
21
|
+
Obtain a bot token from [@botfather](https://t.me/botfather)
|
22
|
+
|
23
|
+
To test your bot's authentication token, use the *get_me* method.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
#!/usr/bin/ruby
|
27
|
+
# frozen_string_literal: true
|
28
|
+
|
29
|
+
require 'teleruby'
|
30
|
+
|
31
|
+
@token = %q{place-your-bot's-token-here}
|
32
|
+
@bot = Telegram::Client.new(token: @token)
|
33
|
+
|
34
|
+
me = @bot.get_me
|
35
|
+
|
36
|
+
puts 'first name:' + me.first_name
|
37
|
+
puts 'user name:' + me.username
|
38
|
+
puts 'id:' + me.id.to_s
|
39
|
+
```
|
40
|
+
|
41
|
+
# Usage
|
42
|
+
|
43
|
+
There are two ways to get update from Telegram Server.
|
44
|
+
|
45
|
+
* polling
|
46
|
+
* webhook
|
47
|
+
|
48
|
+
For now this library supports only polling method.
|
49
|
+
|
50
|
+
## Getting Update s
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
#!/usr/bin/ruby
|
54
|
+
# frozen_string_literal: true
|
55
|
+
|
56
|
+
require 'teleruby'
|
57
|
+
|
58
|
+
@token = %q{place-your-bot's-token-here}
|
59
|
+
@bot = Telegram::Client.new(token: @token)
|
60
|
+
|
61
|
+
updates = @bot.get_updates
|
62
|
+
puts updates.inspect
|
63
|
+
```
|
64
|
+
|
65
|
+
*NB:* The default number of updates to be retrieved is *10*, but you can add yours like.
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
@bot = Telegram::Client.new(token: @token)
|
69
|
+
|
70
|
+
updates = @bot.get_updates(limit: 80)
|
71
|
+
```
|
72
|
+
|
73
|
+
Here 10 shows, 80 updates to be retrieved. Max limit is 100. You can also limit type of updates!.
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
up_dates = ['message', 'channel_post']
|
77
|
+
|
78
|
+
@bot = Telegram::Client.new(token: @token)
|
79
|
+
updates = @bot.get_updates(limit: 80, type: up_dates)
|
80
|
+
```
|
81
|
+
|
82
|
+
In the above case bot will retrive 80 updates and only looks message and channel post notifications.
|
83
|
+
|
84
|
+
If you wanna create specific purpose bot, limiting type of request would be better!.
|
85
|
+
|
86
|
+
## Echo server
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
#!/usr/bin/ruby
|
90
|
+
# frozen_string_literal: true
|
91
|
+
|
92
|
+
require 'teleruby'
|
93
|
+
|
94
|
+
@token = %q{place-your-bot's-token-here}
|
95
|
+
@bot = Telegram::Client.new(token: @token)
|
96
|
+
|
97
|
+
@bot.run! do
|
98
|
+
updates = @bot.get_updates
|
99
|
+
updates.each do |update|
|
100
|
+
if update.msg?
|
101
|
+
message = update.message
|
102
|
+
if message.text_msg?
|
103
|
+
chat = message.chat
|
104
|
+
@bot.send_message(chat.id, message.text)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# echoes text message and replys to send message but
|
111
|
+
# you can make it to echo all send messages!
|
112
|
+
```
|
113
|
+
|
114
|
+
Telegram doesn't send left chat participant notification if your group members exceed 50.
|
115
|
+
|
116
|
+
*NB:* To use actions like pin_message, unpin_chat_message, promote_chat_member .... , your bot must have appropriate admin right in supergroup.
|
117
|
+
|
118
|
+
*Note:* Only get methods and send methods return object, the rest methods return hash object.
|
119
|
+
|
120
|
+
##### NB:
|
121
|
+
Sometimes optional methods return irrelevant, it may be nil or false, so you have to check it.
|
122
|
+
|
123
|
+
If Telegram response is irrelevant but expected to return Telegram object, then teleruby returns false and if it is expected to return other info rather than Telegram object, it returns nil.
|
124
|
+
|
125
|
+
![Sample](msg.png)
|
126
|
+
|
127
|
+
###### Example:
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
updates = @bot.get_updates
|
131
|
+
updates.eah do |update|
|
132
|
+
if update.msg?
|
133
|
+
# code goes here
|
134
|
+
end
|
135
|
+
end
|
136
|
+
```
|
137
|
+
|
138
|
+
In the above case, message is optional, when? if ```bot(client)``` gets channel post notification and blah blah.
|
139
|
+
|
140
|
+
### Custom Keyboard
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
question = 'which one is your favorite programming language?'
|
144
|
+
|
145
|
+
answer1 = 'Ruby'
|
146
|
+
answer2 = 'Python'
|
147
|
+
answer3 = 'Java'
|
148
|
+
answer4 = 'C'
|
149
|
+
|
150
|
+
hash1 = { text: answer1, callback_data: 'ruby' }
|
151
|
+
hash2 = { text: answer2, callback_data: 'python' }
|
152
|
+
hash3 = { text: answer3, callback_data: 'java' }
|
153
|
+
hash4 = { text: answer4, callback_data: 'c' }
|
154
|
+
|
155
|
+
button1 = [hash1]
|
156
|
+
button2 = [hash2]
|
157
|
+
button3 = [hash3]
|
158
|
+
button4 = [hash4]
|
159
|
+
|
160
|
+
ary_of_buttons = [button1, button2, button3, button4]
|
161
|
+
|
162
|
+
buttons = { inline_keyboard: ary_of_buttons }.to_json
|
163
|
+
|
164
|
+
msg = -> { { reply_markup: all_buttons } }
|
165
|
+
chat_id = 432234232 # provide target chat id
|
166
|
+
@bot.send_message(chat_id, question, msg.call)
|
167
|
+
```
|
168
|
+
|
169
|
+
### Inline Keyboard
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
question = 'which one is your favorite programming language?'
|
173
|
+
|
174
|
+
answer1 = 'Ruby'
|
175
|
+
answer2 = 'Python'
|
176
|
+
answer3 = 'Java'
|
177
|
+
answer4 = 'C'
|
178
|
+
|
179
|
+
hash1 = { text: answer1, callback_data: 'ruby' }
|
180
|
+
hash2 = { text: answer2, callback_data: 'python' }
|
181
|
+
hash3 = { text: answer3, callback_data: 'java' }
|
182
|
+
hash4 = { text: answer4, callback_data: 'c' }
|
183
|
+
|
184
|
+
button1 = [hash1]
|
185
|
+
button2 = [hash2]
|
186
|
+
button3 = [hash3]
|
187
|
+
button4 = [hash4]
|
188
|
+
|
189
|
+
ary_of_buttons = [button1, button2, button3, button4]
|
190
|
+
|
191
|
+
buttons = { keyboard: ary_of_buttons }.to_json
|
192
|
+
|
193
|
+
msg = -> { { reply_markup: all_buttons, resize_keyboard: true, one_time_keyboard: true } }
|
194
|
+
chat_id = 432234232 # provide target chat id
|
195
|
+
@bot.send_message(chat_id, question, msg.call)
|
196
|
+
```
|
197
|
+
|
198
|
+
You can also make it like this...
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
msg = { reply_markup: all_buttons, resize_keyboard: true, one_time_keyboard: true }
|
202
|
+
@bot.send_message(chat_id, question, msg)
|
203
|
+
```
|
204
|
+
|
205
|
+
May be confused with ```one_time_keyboard```?, well it makes keyboard to disappear after user clicks one button from the given choices.
|
206
|
+
To know about ```resize_keyboard```, remove it and send message, then see what you have got!
|
207
|
+
|
208
|
+
Check ```callback_query```, to see which button is clicked from the given one.
|
209
|
+
|
210
|
+
### Requesting Contact
|
211
|
+
|
212
|
+
```ruby
|
213
|
+
msg = 'please share your contact'
|
214
|
+
hash = { text: 'share', request_contact: true }
|
215
|
+
|
216
|
+
button = [hash]
|
217
|
+
buttons = [button]
|
218
|
+
|
219
|
+
msg = { keyboard: buttons }.to_json
|
220
|
+
last = { reply_markup: msg, resize_keyboard: true, one_time_keyboard: true }
|
221
|
+
@bot.send_message(chat_id, msg, last)
|
222
|
+
```
|
223
|
+
|
224
|
+
You can also request *location*, and *request_poll*.
|
225
|
+
|
226
|
+
#### Send methods
|
227
|
+
|
228
|
+
* ```send_animation(chat_id, file_id, params)```
|
229
|
+
* ```send_audio(chat_id, file_id, params)```
|
230
|
+
* ```send_chat_action(chat_id, action)```
|
231
|
+
* ```send_contact(chat_id, phone_number, first_name, params)```
|
232
|
+
* ```send_document(chat_id, file_id, params)```
|
233
|
+
* ```send_dice(chat_id, params)```
|
234
|
+
* ```send_location+(chat_id, latitude, longitude, params)```
|
235
|
+
* ```send_media_group(chat_id, file_id, params)```
|
236
|
+
* ```send_message(chat_id+, text, params)```
|
237
|
+
* ```send_poll(chat_id, question, options, params)```
|
238
|
+
* ```send_voice(chat_id, file_id, params)```
|
239
|
+
* ```send_video(chat_id, file_id, params)```
|
240
|
+
* ```send_video_note(chat_id, file_id, params)```
|
241
|
+
* ```send_sticker(chat_id, file_id, params)```
|
242
|
+
* ```send_venue(chat_id, latitude, longitude, title, address, params)```
|
243
|
+
|
244
|
+
#### Delete methods
|
245
|
+
|
246
|
+
* ```delete_message(chat_id, message_id)```
|
247
|
+
* ```delete_chat_photo(chat_id)```
|
248
|
+
* ```delete_chat_sticker_set(chat_id)```
|
249
|
+
* ```delete_sticker_from_set(sticker```)
|
250
|
+
|
251
|
+
#### Set methods
|
252
|
+
|
253
|
+
* ```set_cutom_title(chat_id, user_id, title)```
|
254
|
+
* ```set_chat_permissions(chat_id, permissions)```
|
255
|
+
* ```set_chat_photo(chat_id, file)```
|
256
|
+
* ```set_chat_title(chat_id, title)```
|
257
|
+
* ```set_chat_sticker_set+(chat_id, set_name)```
|
258
|
+
* ```set_my_command(command)```
|
259
|
+
* ```set_sticker_position_in_the_set(sticker, position)```
|
260
|
+
* ```set_sticker_set_thumb(name, user_id, params)```
|
261
|
+
* ```set_chat_description(chat_id, description)```
|
262
|
+
|
263
|
+
#### Get Methods
|
264
|
+
|
265
|
+
* ```get_updates``
|
266
|
+
* ```get_me```
|
267
|
+
* ```get_file(file_id)```
|
268
|
+
* ```get_profile_photos(user_id, params)```
|
269
|
+
* ```get_chat_admins(chat_id)```
|
270
|
+
* ```get_members_count(chat_id)```
|
271
|
+
* ```get_chat_member(chat_id, user_id)```
|
272
|
+
* ```get_sticker_set_name(name)```
|
273
|
+
* ```get_chat(chat_id)```
|
274
|
+
* ```get_my_commands```
|
275
|
+
|
276
|
+
#### Other methods
|
277
|
+
|
278
|
+
* ```forward_message(from_chat_id, to_chat_id, message_id, params)```
|
279
|
+
* ```kick_chat_member(chat_id, user_id, params)```
|
280
|
+
* ```unban_chat_member(chat_id, user_id)```
|
281
|
+
* ```restrict_chat_member(chat_id, user_id, permissions, params)```
|
282
|
+
* ```promote_chat_member(chat_id, user_id, params)``
|
283
|
+
* ```export_chat_link(chat_id)```
|
284
|
+
* ```pin_chat_message(chat_id, message_id, params)```
|
285
|
+
* ```unpin_chat_message(chat_id)```
|
286
|
+
* ```leave_chat(chat_id)```
|
287
|
+
* ```stop_poll(chat_id, message_id, params)```
|
288
|
+
* ```upload_sticker_file(user_id, png_sticker)```
|
289
|
+
* ```create_new_stricker_set(user_id, name, title, params)```
|
290
|
+
* ```add_sticker_to_set(user_id, name, emojis, params)```
|
291
|
+
|
292
|
+
If you wanna know available methods:
|
293
|
+
|
294
|
+
```ruby
|
295
|
+
irb(main):002:0> require 'teleruby'
|
296
|
+
=> true
|
297
|
+
irb(main):004:0> bot = Telegram::Client.new(token: 'dafasfasfasfasf')
|
298
|
+
=> #<Telegram::Client:0x0000560aee01caa8 @token="dafasfasfasfasf", @last_update=0>
|
299
|
+
irb(main):005:0> bot.methods - self.methods
|
300
|
+
```
|
301
|
+
|
302
|
+
Lists all available methods.
|
303
|
+
|
304
|
+
#### Available Objects
|
305
|
+
|
306
|
+
Poll
|
307
|
+
|
308
|
+
Location
|
309
|
+
|
310
|
+
Venue
|
311
|
+
|
312
|
+
Chat
|
313
|
+
|
314
|
+
BotCommand
|
315
|
+
|
316
|
+
ChatPermissions
|
317
|
+
|
318
|
+
ChatPhoto
|
319
|
+
|
320
|
+
CallbackQuery
|
321
|
+
|
322
|
+
TFile
|
323
|
+
|
324
|
+
PollAnswer
|
325
|
+
|
326
|
+
PollOption
|
327
|
+
|
328
|
+
Dice
|
329
|
+
|
330
|
+
Contact
|
331
|
+
|
332
|
+
Voice
|
333
|
+
|
334
|
+
Video
|
335
|
+
|
336
|
+
Audio
|
337
|
+
|
338
|
+
PhotoSize
|
339
|
+
|
340
|
+
Document
|
341
|
+
|
342
|
+
VideoNote
|
343
|
+
|
344
|
+
User
|
345
|
+
|
346
|
+
MessageEntity
|
347
|
+
|
348
|
+
ChatMember
|
349
|
+
|
350
|
+
ChoseInlineResult
|
351
|
+
|
352
|
+
Sticker
|
353
|
+
|
354
|
+
Game
|
355
|
+
|
356
|
+
InlineQuery
|
357
|
+
|
358
|
+
ShippingQuery
|
359
|
+
|
360
|
+
MaskPosition
|
361
|
+
|
362
|
+
ShippingAddress
|
363
|
+
|
364
|
+
PreCheckoutQuery
|
365
|
+
|
366
|
+
OrderInfo
|
367
|
+
|
368
|
+
Message
|
369
|
+
|
370
|
+
Animation
|
371
|
+
|
372
|
+
InlineKeyboardButton
|
373
|
+
|
374
|
+
InlineKeyboardMarkup
|
375
|
+
|
376
|
+
UserProfilePhotos
|
377
|
+
|
378
|
+
Update
|
379
|
+
|
380
|
+
Please download the source file and do ```rdoc``` from the root of dir, then go to doc/, then open README_rdoc.html with your fav browser.
|
381
|
+
|
382
|
+
![rdoc](rdoc.png)
|
383
|
+
|
384
|
+
#### Discussion Group On Telegram
|
385
|
+
[teleruby support](https://t.me/teleruby_support)
|
386
|
+
|
387
|
+
## Contributing
|
388
|
+
|
389
|
+
1. Fork it
|
390
|
+
2. Create your feature branch (git checkout -b my-new-feature)
|
391
|
+
3. Commit your changes (git commit -am 'Add some feature')
|
392
|
+
4. Push to the branch (git push origin my-new-feature)
|
393
|
+
5. Create new Pull Request
|
394
|
+
|
395
|
+
## License
|
396
|
+
|
397
|
+
The gem is available as open source under the terms of the [GPLv3+](https://gnu.org/licenses/gpl.html).
|
398
|
+
|
data/lib/api/all.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../core_api'
|
5
|
+
|
6
|
+
module Telegram
|
7
|
+
module DeleteApis
|
8
|
+
include CoreApi
|
9
|
+
# Use this method to delete a chat photo.
|
10
|
+
def delete_chat_photo(chat_id)
|
11
|
+
unless chat_id.to_i.negative?
|
12
|
+
raise BadRequestError, %{can't delete private chat photo}
|
13
|
+
end
|
14
|
+
|
15
|
+
hash = { chat_id: chat_id }
|
16
|
+
response = http_post('deleteChatPhoto', hash)
|
17
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
18
|
+
raise PermissionError, response.description
|
19
|
+
end
|
20
|
+
|
21
|
+
response.result
|
22
|
+
end
|
23
|
+
|
24
|
+
# Use this method to delete a group sticker set from a supergroup.
|
25
|
+
def delete_chat_sticker_set(chat_id)
|
26
|
+
unless chat_id.to_i.negative?
|
27
|
+
raise BadRequestError, %{can' delete sticker set of private chat}
|
28
|
+
end
|
29
|
+
|
30
|
+
hash = { chat_id: chat_id }
|
31
|
+
response = http_post('deleteChatStickerSet', hash)
|
32
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
33
|
+
raise PermissionError, response.description
|
34
|
+
end
|
35
|
+
|
36
|
+
response.result
|
37
|
+
end
|
38
|
+
|
39
|
+
# Use this method to delete a message, including service messages.
|
40
|
+
def delete_message(chat_id, message_id)
|
41
|
+
hash = { chat_id: chat_id, message_id: message_id }
|
42
|
+
response = http_post('deleteMessage', hash)
|
43
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
44
|
+
raise TelegramError, response.description
|
45
|
+
end
|
46
|
+
|
47
|
+
response.result
|
48
|
+
end
|
49
|
+
|
50
|
+
# Use this method to delete a sticker from a set created by the bot.
|
51
|
+
def delete_sticker_from_set(sticker)
|
52
|
+
raise NotImplementedError, 'currently not supported'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|