teleruby 1.5.1 → 1.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +9 -0
  3. data/README.md +398 -0
  4. data/lib/api/all.rb +12 -0
  5. data/lib/api/delete_apis.rb +55 -0
  6. data/lib/api/get_apis.rb +162 -0
  7. data/lib/api/nstandard.rb +26 -0
  8. data/lib/api/other_apis.rb +225 -0
  9. data/lib/api/send_apis.rb +191 -0
  10. data/lib/api/set_apis.rb +130 -0
  11. data/lib/core_api.rb +41 -0
  12. data/lib/objects/all.rb +42 -0
  13. data/lib/objects/animation.rb +38 -0
  14. data/lib/objects/audio.rb +37 -0
  15. data/lib/objects/bot_command.rb +24 -0
  16. data/lib/objects/callback_query.rb +64 -0
  17. data/lib/objects/chat.rb +158 -0
  18. data/lib/objects/chat_member.rb +142 -0
  19. data/lib/objects/chat_permissions.rb +59 -0
  20. data/lib/objects/chat_photo.rb +37 -0
  21. data/lib/objects/chosen_inline_result.rb +43 -0
  22. data/lib/objects/contact.rb +37 -0
  23. data/lib/objects/dice.rb +21 -0
  24. data/lib/objects/document.rb +27 -0
  25. data/lib/objects/file.rb +32 -0
  26. data/lib/objects/game.rb +65 -0
  27. data/lib/objects/inline_query.rb +42 -0
  28. data/lib/objects/inlinekeyboardbutton.rb +59 -0
  29. data/lib/objects/inlinekeyboardmarkup.rb +30 -0
  30. data/lib/objects/location.rb +21 -0
  31. data/lib/objects/mask_position.rb +35 -0
  32. data/lib/objects/message.rb +378 -0
  33. data/lib/objects/message_entity.rb +93 -0
  34. data/lib/objects/order_info.rb +34 -0
  35. data/lib/objects/photo_size.rb +14 -0
  36. data/lib/objects/poll.rb +97 -0
  37. data/lib/objects/poll_answer.rb +29 -0
  38. data/lib/objects/poll_option.rb +22 -0
  39. data/lib/objects/pre_checkout_query.rb +48 -0
  40. data/lib/objects/same/common.rb +37 -0
  41. data/lib/objects/same/common_2.rb +38 -0
  42. data/lib/objects/shipping_address.rb +39 -0
  43. data/lib/objects/shipping_query.rb +32 -0
  44. data/lib/objects/sticker.rb +55 -0
  45. data/lib/objects/update.rb +174 -0
  46. data/lib/objects/user.rb +66 -0
  47. data/lib/objects/user_profile_photos.rb +35 -0
  48. data/lib/objects/venue.rb +40 -0
  49. data/lib/objects/video.rb +37 -0
  50. data/lib/objects/video_note.rb +48 -0
  51. data/lib/objects/voice.rb +20 -0
  52. data/lib/teleruby.rb +4 -40
  53. data/lib/teleruby/all_apis.rb +22 -0
  54. data/lib/teleruby/api/delete_apis.rb +58 -0
  55. data/lib/teleruby/api/get_apis.rb +172 -0
  56. data/lib/teleruby/api/nstandard.rb +27 -0
  57. data/lib/teleruby/api/other_apis.rb +241 -0
  58. data/lib/teleruby/api/send_apis.rb +206 -0
  59. data/lib/teleruby/api/set_apis.rb +137 -0
  60. data/lib/teleruby/core_api.rb +52 -0
  61. data/lib/teleruby/objects/all.rb +42 -0
  62. data/lib/teleruby/objects/animation.rb +40 -0
  63. data/lib/teleruby/objects/audio.rb +39 -0
  64. data/lib/teleruby/objects/bot_command.rb +24 -0
  65. data/lib/teleruby/objects/callback_query.rb +66 -0
  66. data/lib/teleruby/objects/chat.rb +164 -0
  67. data/lib/teleruby/objects/chat_member.rb +142 -0
  68. data/lib/teleruby/objects/chat_permissions.rb +59 -0
  69. data/lib/teleruby/objects/chat_photo.rb +37 -0
  70. data/lib/teleruby/objects/chosen_inline_result.rb +45 -0
  71. data/lib/teleruby/objects/contact.rb +37 -0
  72. data/lib/teleruby/objects/dice.rb +21 -0
  73. data/lib/teleruby/objects/document.rb +29 -0
  74. data/lib/teleruby/objects/file.rb +32 -0
  75. data/lib/teleruby/objects/game.rb +65 -0
  76. data/lib/teleruby/objects/inline_query.rb +44 -0
  77. data/lib/teleruby/objects/inlinekeyboardbutton.rb +59 -0
  78. data/lib/teleruby/objects/inlinekeyboardmarkup.rb +31 -0
  79. data/lib/teleruby/objects/location.rb +21 -0
  80. data/lib/teleruby/objects/mask_position.rb +35 -0
  81. data/lib/teleruby/objects/message.rb +400 -0
  82. data/lib/teleruby/objects/message_entity.rb +95 -0
  83. data/lib/teleruby/objects/order_info.rb +36 -0
  84. data/lib/teleruby/objects/photo_size.rb +14 -0
  85. data/lib/teleruby/objects/poll.rb +97 -0
  86. data/lib/teleruby/objects/poll_answer.rb +29 -0
  87. data/lib/teleruby/objects/poll_option.rb +22 -0
  88. data/lib/teleruby/objects/pre_checkout_query.rb +50 -0
  89. data/lib/teleruby/objects/same/common.rb +31 -0
  90. data/lib/teleruby/objects/same/common_2.rb +32 -0
  91. data/lib/teleruby/objects/shipping_address.rb +39 -0
  92. data/lib/teleruby/objects/shipping_query.rb +32 -0
  93. data/lib/teleruby/objects/sticker.rb +59 -0
  94. data/lib/teleruby/objects/update.rb +207 -0
  95. data/lib/teleruby/objects/user.rb +66 -0
  96. data/lib/teleruby/objects/user_profile_photos.rb +36 -0
  97. data/lib/teleruby/objects/venue.rb +40 -0
  98. data/lib/teleruby/objects/video.rb +39 -0
  99. data/lib/teleruby/objects/video_note.rb +50 -0
  100. data/lib/teleruby/objects/voice.rb +20 -0
  101. data/lib/teleruby/version.rb +3 -0
  102. data/msg.png +0 -0
  103. data/rdoc.png +0 -0
  104. data/teleruby.gemspec +9 -7
  105. metadata +109 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c0caee7d7e27912893bc065e73730adb560a48c61b65f865b235f72dcda075e
4
- data.tar.gz: 30e673ac24781e70280aa2d9d6cf0c9b4586f83f4de2863e7744e1be0edeff62
3
+ metadata.gz: 8323bf733744d8b1f032534ad087c398b4d54d466e3990a263905698d42517ba
4
+ data.tar.gz: 89109597ff80a96beef742e102ad36f45e49f028aa0e59f12ce4a5da2f0b0e65
5
5
  SHA512:
6
- metadata.gz: d89c8ecb16f6baca6defc283b018863f0c0eb6391bb6bb58b264afa2f6537f7a0c57b4f18e6be197bc6a8b660f1463161a30d478fe1b52354db6fa02e66ff5d8
7
- data.tar.gz: 3f634c59bebf7aac80ec5e60bc4e07aad1e930afdd37caffa3db4801f280272dbe7a6f06d8890840b41942c8744ec91f332db206044a330a8163e43c53c14c53
6
+ metadata.gz: d94858861777a0c9d69b757421dcd8ac045e5e1a4d279e0ea0f31f0a1fa5cab55b1a7d61459e4d1be462e280643d0cde1d3db8b2213a58bfc306e285a15f5cbc
7
+ data.tar.gz: 7839a39dde8b1e3915553b48c5e90cc8f682f24e64c7ae4b3909145e80c92d4b28d4c3d48d4fc835fc8a43649db156c0877a870585168b3ebbf54821f2ff8033
@@ -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
+
@@ -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
+
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/ruby
2
+
3
+ module Telegram
4
+ module AllApis
5
+ require_relative 'delete_apis'
6
+ require_relative 'get_apis'
7
+ require_relative 'nstandard'
8
+ require_relative 'other_apis'
9
+ require_relative 'send_apis'
10
+ require_relative 'set_apis'
11
+ end
12
+ end
@@ -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