rbender 0.5.35 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,43 +1,43 @@
1
1
  require 'yaml'
2
2
 
3
3
  module RBender
4
- module ConfigHandler
5
- @@config_path = 'config.yaml'
6
- CONFIG_NAME = 'config.yaml'
7
-
8
-
9
- def self.underscore(str)
10
- str.gsub(/::/, '/').
11
- gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
12
- gsub(/([a-z\d])([A-Z])/, '\1_\2').
13
- tr("-", "_").
14
- downcase
15
- end
16
-
17
- def self.settings
18
- begin
19
- @@settings = YAML.load(File.read(@@config_path))
20
- rescue
21
- raise "Config file doesn't exists!"
22
- end
23
-
24
- def @@settings.save
25
- File.write(@@config_path, @@settings.to_yaml)
26
- end
27
-
28
- @@settings
29
- end
30
-
31
- def self.config_path=(path)
32
- @@config_path = "#{path}/#{CONFIG_NAME}"
33
- end
34
-
35
- def self.token=(token)
36
- @@token = token
37
- end
38
-
39
- def self.token
40
- @@token
41
- end
42
- end
4
+ module ConfigHandler
5
+ @@config_path = 'config.yaml'
6
+ CONFIG_NAME = 'config.yaml'
7
+
8
+
9
+ def self.underscore(str)
10
+ str.gsub(/::/, '/').
11
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
12
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
13
+ tr("-", "_").
14
+ downcase
15
+ end
16
+
17
+ def self.settings
18
+ begin
19
+ @@settings = YAML.load(File.read(@@config_path))
20
+ rescue
21
+ raise "Config file doesn't exists!"
22
+ end
23
+
24
+ def @@settings.save
25
+ File.write(@@config_path, @@settings.to_yaml)
26
+ end
27
+
28
+ @@settings
29
+ end
30
+
31
+ def self.config_path=(path)
32
+ @@config_path = "#{path}/#{CONFIG_NAME}"
33
+ end
34
+
35
+ def self.token=(token)
36
+ @@token = token
37
+ end
38
+
39
+ def self.token
40
+ @@token
41
+ end
42
+ end
43
43
  end
@@ -0,0 +1,30 @@
1
+ class RBender::FlySettings
2
+ include Singleton
3
+
4
+ attr_reader :settings
5
+ FLY_SETTINGS = :fly_settings.freeze
6
+
7
+ def initialize
8
+ @settings = RBender::MongoClient.client[FLY_SETTINGS].find({ fly_settings: 1 })
9
+
10
+ if @settings.count == 0
11
+ @settings.insert_one({ "fly_settings" => 1 })
12
+ end
13
+ end
14
+
15
+ def set(key, value)
16
+ @settings.update_one({ "$set" => { key => value } })
17
+ end
18
+
19
+ def push(key, value)
20
+ @settings.update_one({ "$push" => { key => value } }) unless list_includes?(key, value)
21
+ end
22
+
23
+ def get(key)
24
+ @settings.first[key]
25
+ end
26
+
27
+ def list_includes?(key, value)
28
+ @settings.first[key].include?(value)
29
+ end
30
+ end
@@ -1,97 +1,96 @@
1
1
  class RBender::Keyboard
2
2
 
3
- attr_accessor :markup,
4
- :localizations,
5
- :actions,
6
- :response,
7
- :switchers,
8
- :markup_tg,
9
- :markup_final,
10
- :switch_groups,
11
- :session
3
+ attr_accessor :markup,
4
+ :localizations,
5
+ :actions,
6
+ :response,
7
+ :switchers,
8
+ :markup_tg,
9
+ :markup_final,
10
+ :switch_groups,
11
+ :session
12
12
 
13
- def initialize
14
- @actions = {}
15
- @markup = []
16
- @localizations = {}
17
- @markup_tg = nil
18
- @markup_final = {}
19
- @button_switch_group = {}
20
- @one_time = false
21
- @session = nil
22
- @hide_on_action = false
23
- @resize = false
24
- @force_invoke = false
25
- end
13
+ def initialize
14
+ @actions = {}
15
+ @markup = []
16
+ @localizations = {}
17
+ @markup_tg = nil
18
+ @markup_final = {}
19
+ @button_switch_group = {}
20
+ @one_time = false
21
+ @session = nil
22
+ @hide_on_action = false
23
+ @resize = false
24
+ @force_invoke = false
25
+ end
26
26
 
27
- def hide_on_action
28
- @hide_on_action = true
29
- end
27
+ def hide_on_action
28
+ @hide_on_action = true
29
+ end
30
30
 
31
- def force_invoked?
32
- @force_invoke
33
- end
31
+ def force_invoked?
32
+ @force_invoke
33
+ end
34
34
 
35
- # Adds button to the keyboard
36
- #
37
- # Example:
38
- # button :btn_test, "Test button" do
39
- # some_actions
40
- # end
41
- #
42
- # button :btn_with_loc, {ru: "Кнопка", en: "Button"} do
43
- # some_actions
44
- # end
35
+ # Adds button to the keyboard
36
+ #
37
+ # Example:
38
+ # button :btn_test, "Test button" do
39
+ # some_actions
40
+ # end
41
+ #
42
+ # button :btn_with_loc, {ru: "Кнопка", en: "Button"} do
43
+ # some_actions
44
+ # end
45
45
 
46
- def button(id, localizations, &action)
47
- @actions[id] = action
48
- @localizations[id] = localizations
49
- end
46
+ def button(id, description, &action)
47
+ @actions[id] = action
48
+ @localizations[id] = description
49
+ end
50
50
 
51
- # Checks keyboard one time or not
52
- def one_time?
53
- @one_time
54
- end
51
+ # Checks keyboard one time or not
52
+ def one_time?
53
+ @one_time
54
+ end
55
55
 
56
- # makes a keyboard one time
57
- def one_time
58
- @one_time = true
59
- end
56
+ # makes a keyboard one time
57
+ def one_time
58
+ @one_time = true
59
+ end
60
60
 
61
- # Add a line to markup
62
- def add_line (*buttons)
63
- @markup += [buttons]
64
- end
61
+ # Add a line to markup
62
+ def line (*buttons)
63
+ @markup += [buttons]
64
+ end
65
65
 
66
- # Set response when keyboard is invoked
67
- def set_response(new_response)
68
- @response = new_response
69
- end
66
+ # Set response when keyboard is invoked
67
+ def set_response(new_response)
68
+ @response = new_response
69
+ end
70
70
 
71
71
 
72
- # Resize telegram buttons
73
- def resize
74
- @resize = true
75
- end
72
+ # Resize telegram buttons
73
+ def resize
74
+ @resize = true
75
+ end
76
76
 
77
77
 
78
- # Method to initialize a keyboard
79
- #
80
- def build(session)
81
- markup = []
82
- @markup.each do |line|
83
- buf_line = []
84
- line.each do |button_id|
85
- button = @localizations[button_id].dup
78
+ # Method to initialize a keyboard
79
+ #
80
+ def build(session)
81
+ markup = []
82
+ @markup.each do |line|
83
+ buf_line = []
84
+ line.each do |button_id|
85
+ button = @localizations[button_id].dup
86
86
 
87
- buf_line << button
88
- @markup_final[button_id] = button
89
- end
90
- markup << buf_line
91
- end
92
- @markup_tg = Telegram::Bot::Types::ReplyKeyboardMarkup
93
- .new(keyboard: markup,
94
- one_time_keyboard: one_time?,
95
- resize_keyboard: @resize)
96
- end
87
+ buf_line << button
88
+ @markup_final[button_id] = button
89
+ end
90
+ markup << buf_line
91
+ end
92
+ @markup_tg = Telegram::Bot::Types::ReplyKeyboardMarkup.new(keyboard: markup,
93
+ one_time_keyboard: one_time?,
94
+ resize_keyboard: @resize)
95
+ end
97
96
  end
@@ -3,15 +3,16 @@ class RBender::KeyboardInline
3
3
  :buttons_actions
4
4
 
5
5
  def initialize(name, session, block)
6
- @name = name
6
+ @name = name
7
7
  @buttons_callback = {}
8
- @buttons_inline = {}
9
- @buttons_links = {}
10
- @buttons_actions = {}
11
- @markup = []
12
- @markup_tg = []
13
- @session = session
14
- @keyboard_block = block
8
+ @buttons_inline = {}
9
+ @buttons_links = {}
10
+ @buttons_actions = {}
11
+ @buttons_pay = {}
12
+ @markup = []
13
+ @markup_tg = []
14
+ @session = session
15
+ @keyboard = block
15
16
  end
16
17
 
17
18
  def session
@@ -20,31 +21,43 @@ class RBender::KeyboardInline
20
21
 
21
22
  # Adds button with callback
22
23
  def button(name, description, &action)
23
- callback = @name.to_s + RBender::CALLBACK_SPLITTER + name.to_s
24
- @buttons_callback[name] = Telegram::Bot::Types::InlineKeyboardButton.new(text: description,
25
- callback_data: callback)
24
+ callback = @name.to_s + RBender::CALLBACK_SPLITTER + name.to_s
25
+ @buttons_callback[name] = Telegram::Bot::Types::InlineKeyboardButton.new(text: description,
26
+ callback_data: callback)
26
27
  @buttons_actions[name.to_s] = action
27
28
  end
28
29
 
29
30
  # Adds link button
30
31
  def button_link(name, description, link)
31
32
  @buttons_links[name] = Telegram::Bot::Types::InlineKeyboardButton.new(text: description,
32
- url: link)
33
+ url: link)
33
34
  end
34
35
 
35
36
  # Adds inline switch mode button
36
37
  def button_inline(name, description, inline_query)
37
- @buttons_inline[name] = Telegram::Bot::Types::InlineKeyboardButton.new(text: description,
38
+ @buttons_inline[name] = Telegram::Bot::Types::InlineKeyboardButton.new(text: description,
38
39
  switch_inline_query: inline_query)
39
40
  end
40
41
 
42
+ def button_game(name, description, callback_game)
43
+ @buttons_inline[name] = Telegram::Bot::Types::InlineKeyboardButton.new(text: description,
44
+ callback_game: callback_game)
45
+ end
46
+
47
+ # def button_callback
48
+
49
+ def button_pay(name, description)
50
+ @buttons_pay[name] = Telegram::Bot::Types::InlineKeyboardButton.new(text: description,
51
+ pay: true)
52
+ end
53
+
41
54
  # Adds a line to markup
42
- def add_line(*buttons)
55
+ def line(*buttons)
43
56
  @markup += [buttons]
44
57
  end
45
58
 
46
59
  def invoke
47
- instance_eval(&@keyboard_block)
60
+ instance_eval(&@keyboard)
48
61
  end
49
62
 
50
63
  def build
@@ -55,6 +68,7 @@ class RBender::KeyboardInline
55
68
  buttons.merge! @buttons_callback
56
69
  buttons.merge! @buttons_links
57
70
  buttons.merge! @buttons_inline
71
+ buttons.merge! @buttons_pay
58
72
 
59
73
  markup = []
60
74
  @markup.each do |btn_row|
@@ -2,381 +2,458 @@ require 'faraday'
2
2
 
3
3
  class RBender::Methods
4
4
 
5
- def initialize(message, api, session)
6
- @message = message
7
- @api = api
8
- @session = session
9
- end
10
-
11
- #--------------
12
- # User methods
13
- #--------------
14
-
15
- # Set message user gets while keyboard has invoked
16
- def set_response(new_response)
17
- @keyboard.set_response(new_response)
18
- end
19
-
20
- # Returns session hash
21
- def session
22
- @session
23
- end
24
-
25
- # Returns message object
26
- def message
27
- @message
28
- end
29
-
30
- def switch(state_to)
31
- @session[:state_stack].push(@session[:state])
32
- @session[:state] = state_to
33
- end
34
-
35
- def switch_prev
36
- @session[:state] = @session[:state_stack].pop
37
- end
38
-
39
-
40
- #--------------
41
- # API METHODS
42
- #--------------
43
- # Hides inline keyboard
44
- # Must be called from any inline keyboard state
45
-
46
- def send_message(text:,
47
- chat_id: @message.from.id,
48
- parse_mode: nil,
49
- disable_web_page_preview: nil,
50
- disable_notification: nil,
51
- reply_to_message_id: nil,
52
- reply_markup: nil)
53
-
54
- if text.strip.empty?
55
- raise "A text can't be empty or consists of space symbols only"
56
- end
57
- @api.send_message chat_id: chat_id,
58
- text: text,
59
- disable_web_page_preview: disable_web_page_preview,
60
- disable_notification: disable_notification,
61
- reply_to_message_id: reply_to_message_id,
62
- parse_mode: parse_mode,
63
- reply_markup: reply_markup
64
- end
65
-
66
- def edit_message_text(inline_message_id: nil,
67
- text:,
68
- chat_id: @message.from.id,
69
- message_id: @message.message.message_id,
70
- parse_mode: nil,
71
- disable_web_page_preview: nil,
72
- reply_markup: nil)
73
- if text.strip.empty?
74
- raise "A text can't be empty or consists of space symbols only"
75
- end
76
- @api.edit_message_text chat_id: chat_id,
77
- message_id: message_id,
78
- text: text,
79
- inline_message_id: inline_message_id,
80
- parse_mode: parse_mode,
81
- disable_web_page_preview: disable_web_page_preview,
82
- reply_markup: reply_markup
83
- end
84
-
85
- def edit_message_caption(inline_message_id: nil,
86
- caption: nil,
87
- chat_id: @message.from.id,
88
- message_id: @message.message.message_id,
89
- reply_markup: nil)
90
- if text.strip.empty?
91
- raise "A text can't be empty or consists of space symbols only"
92
- end
93
- @api.edit_message_text chat_id: chat_id,
94
- message_id: message_id,
95
- caption: caption,
96
- inline_message_id: inline_message_id,
97
- reply_markup: reply_markup
98
- end
99
-
100
- def edit_message_reply_markup(chat_id: @message.from.id,
101
- message_id: @message.message.message_id,
102
- inline_message_id: nil,
103
- reply_markup: nil)
104
- @api.edit_message_reply_markup chat_id: chat_id,
105
- message_id: message_id,
106
- inline_message_id: inline_message_id,
107
- reply_markup: reply_markup
108
- end
109
-
110
- def delete_message(chat_id: @message.from.id,
111
- message_id:)
112
- @api.delete_message(chat_id: chat_id,
113
- message_id: message_id)
114
- end
115
-
116
-
117
- def get_file(file_id:)
118
- @api.get_file file_id: file_id
119
- end
120
-
121
- def get_me()
122
- @api.get_me
123
- end
124
-
125
- def forward_message(chat_id:,
126
- from_chat_id: @message.from.id,
127
- disable_notification: false,
128
- message_id:)
129
- @api.forward_message(chat_id: chat_id,
130
- from_chat_id: from_chat_id,
131
- disable_notification: disable_notification,
132
- message_id: message_id)
133
- end
134
-
135
- def send_photo(chat_id: @message.from.id,
136
- photo:,
137
- caption: nil,
138
- disable_notification: false,
139
- reply_to_message_id: nil,
140
- reply_markup: nil)
141
- @api.send_photo(chat_id: chat_id,
142
- photo: photo,
143
- caption: caption,
144
- disable_notification: disable_notification,
145
- reply_to_message_id: reply_to_message_id,
146
- reply_markup: reply_markup)
147
- end
148
-
149
- def send_audio(chat_id: @message.from.to,
150
- audio:,
151
- caption: nil,
152
- duration: nil,
153
- performer: nil,
154
- title: nil,
155
- disable_notification: false,
156
- reply_to_message_id: nil,
157
- reply_markup: nil)
158
-
159
- @api.send_audio(chat_id: chat_id,
160
- audio: audio,
161
- caption: caption,
162
- duration: duration,
163
- performer: performer,
164
- title: title,
165
- disable_notification: disable_notification,
166
- reply_to_message_id: reply_to_message_id,
167
- reply_markup: reply_markup)
168
- end
169
-
170
- def send_document(chat_id: @message.from.id,
171
- document:,
172
- caption: nil,
173
- disable_notification: false,
174
- reply_to_message_id: nil,
175
- reply_markup: nil)
176
- @api.send_document(chat_id: chat_id,
177
- document: document,
178
- caption: caption,
179
- disable_notification: disable_notification,
180
- reply_to_message_id: reply_to_message_id,
181
- reply_markup: reply_markup)
182
- end
183
-
184
- def send_sticker(chat_id: @message.from.id,
185
- sticker:,
186
- caption: nil,
187
- disable_notification: false,
188
- reply_to_message_id: nil,
189
- reply_markup: nil)
190
- @api.send_sticker(chat_id: chat_id,
191
- sticker: sticker,
192
- caption: caption,
193
- disable_notification: disable_notification,
194
- reply_to_message_id: reply_to_message_id,
195
- reply_markup: reply_markup)
196
- end
197
-
198
- def send_video(chat_id: @message.from.id,
199
- video:,
200
- width: nil,
201
- height: nil,
202
- caption: nil,
203
- duration: nil,
204
- disable_notification: false,
205
- reply_to_message_id: nil,
206
- reply_markup: nil)
207
- @api.send_video(chat_id: chat_id,
208
- video: video,
209
- width: width,
210
- height: height,
211
- caption: caption,
212
- duration: duration,
213
- disable_notification: disable_notification,
214
- reply_to_message_id: reply_to_message_id,
215
- reply_markup: reply_markup)
216
- end
217
-
218
- def send_voice(chat_id: @message.from.to,
219
- voice:,
220
- caption: nil,
221
- duration: nil,
222
- disable_notification: false,
223
- reply_to_message_id: nil,
224
- reply_markup: nil)
225
-
226
- @api.send_voice(chat_id: chat_id,
227
- voice: voice,
228
- caption: caption,
229
- duration: duration,
230
- disable_notification: disable_notification,
231
- reply_to_message_id: reply_to_message_id,
232
- reply_markup: reply_markup)
233
- end
234
-
235
- def send_video_note(chat_id: @message.from.id,
236
- video_note:,
237
- length: nil,
238
- duration: nil,
239
- disable_notification: false,
240
- reply_to_message_id: nil,
241
- reply_markup: nil)
242
- @api.send_video_note(chat_id: chat_id,
243
- video_note: video_note,
244
- length: length,
245
- duration: duration,
246
- disable_notification: disable_notification,
247
- reply_to_message_id: reply_to_message_id,
248
- reply_markup: reply_markup)
249
- end
250
-
251
- def send_location(chat_id: @message.from.to,
252
- latitude:,
253
- longitude:,
254
- disable_notification: false,
255
- reply_to_message_id: nil,
256
- reply_markup: nil)
257
-
258
- @api.send_location(chat_id: chat_id,
259
- latitude: latitude,
260
- longitude: longitude,
261
- disable_notification: disable_notification,
262
- reply_to_message_id: reply_to_message_id,
263
- reply_markup: reply_markup)
264
- end
265
-
266
- def send_venue(chat_id: @message.from.to,
267
- latitude:,
268
- longitude:,
269
- title:,
270
- address:,
271
- foursquare_id: nil,
272
- disable_notification: false,
273
- reply_to_message_id: nil,
274
- reply_markup: nil)
275
-
276
- @api.send_venue(chat_id: chat_id,
277
- latitude: latitude,
278
- longitude: longitude,
279
- title: title,
280
- address: address,
281
- foursquare_id: foursquare_id,
282
- disable_notification: disable_notification,
283
- reply_to_message_id: reply_to_message_id,
284
- reply_markup: reply_markup)
285
- end
286
-
287
- def send_contact(chat_id: @message.from.to,
288
- phone_number:,
289
- first_name:,
290
- last_name: nil,
291
- disable_notification: false,
292
- reply_to_message_id: nil,
293
- reply_markup: nil)
294
-
295
- @api.send_contact(chat_id: chat_id,
296
- phone_number: phone_number,
297
- first_name: first_name,
298
- last_name: last_name,
299
- disable_notification: disable_notification,
300
- reply_to_message_id: reply_to_message_id,
301
- reply_markup: reply_markup)
302
- end
303
-
304
- def send_chat_action(chat_id: @message.from.id,
305
- action:)
306
- @api.send_chat_action(chat_id: chat_id,
307
- action: action)
308
- end
309
-
310
- def get_user_profile_photos(chat_id: @message.from.id,
311
- offset: nil,
312
- limit: nil)
313
- @api.get_user_profile_photos(chat_id: chat_id,
314
- offset: offset,
315
- limit: limit)
316
- end
317
-
318
- def kick_chat_member(chat_id:,
319
- user_id:)
320
- @api.kick_chat_member(chat_id: chat_id,
321
- user_id: user_id)
322
- end
323
-
324
- def unban_chat_member(chat_id:,
325
- user_id:)
326
- @api.unban_chat_member(chat_id: chat_id,
327
- user_id: user_id)
328
- end
329
-
330
- def leave_chat(chat_id:)
331
- @api.leave_chat(chat_id: chat_id)
332
- end
333
-
334
- def get_chat(chat_id:)
335
- @api.get_chat(chat_id: chat_id)
336
- end
337
-
338
- def get_chat_administrators(chat_id:)
339
- @api.get_chat_administrators(chat_id: chat_id)
340
- end
341
-
342
- def get_chat_members_count(chat_id:)
343
- @api.get_chat_members_count(chat_id: chat_id)
344
- end
345
-
346
- def get_chat_member(chat_id:, user_id:)
347
- @api.get_chat_member(chat_id: chat_id,
348
- user_id: user_id)
349
- end
350
-
351
- def upload_file(filename, content_type)
352
- filepath = "#{__dir__}/public/#{filename}"
353
- Faraday::UploadIO.new(filepath, content_type)
354
- end
355
-
356
- alias file upload_file
357
- alias upload upload_file
358
-
359
- def download_file(file_path:, to:)
360
- url = 'https://api.telegram.org/file/bot'
361
- token = RBender::ConfigHandler.token
362
- path = Dir.pwd + "/public/#{to}"
363
-
364
-
365
- http_conn = Faraday.new do |builder|
366
- builder.adapter(Faraday.default_adapter)
367
- end
368
-
369
- response = http_conn.get "#{url}#{token}/#{file_path}"
370
-
371
- dir = File.dirname(path)
372
-
373
- unless File.directory?(dir)
374
- FileUtils.mkdir_p(dir)
375
- end
376
-
377
- File.open(path, 'wb') { |fp| fp.write(response.body)}
378
- end
379
-
380
- alias download download_file
5
+ def initialize(message, api, session)
6
+ @message = message
7
+ @api = api
8
+ @session = session
9
+ end
10
+
11
+ #--------------
12
+ # User methods
13
+ #--------------
14
+
15
+ # Set message user gets while keyboard has invoked
16
+ def set_response(new_response)
17
+ @keyboard.set_response(new_response)
18
+ end
19
+
20
+ # Returns session hash
21
+ def session
22
+ @session
23
+ end
24
+
25
+ # Returns message object
26
+ def message
27
+ case @message
28
+ when Telegram::Bot::Types::CallbackQuery
29
+ @message.message
30
+ when Telegram::Bot::Types::Message
31
+ @message
32
+ else
33
+ @message
34
+ end
35
+ end
36
+
37
+ def chat_id
38
+ message().chat.id
39
+ end
40
+
41
+ def switch(state_to)
42
+ @session[:state] = state_to
43
+ end
44
+
45
+ #--------------
46
+ # API METHODS
47
+ #--------------
48
+ # Hides inline keyboard
49
+ # Must be called from any inline keyboard state
50
+
51
+ def send_message(text:,
52
+ chat_id: chat_id(),
53
+ parse_mode: nil,
54
+ disable_web_page_preview: nil,
55
+ disable_notification: nil,
56
+ reply_to_message_id: nil,
57
+ reply_markup: nil)
58
+
59
+ if text.strip.empty?
60
+ raise "A text can't be empty or consists of space symbols only"
61
+ end
62
+ @api.send_message chat_id: chat_id,
63
+ text: text,
64
+ disable_web_page_preview: disable_web_page_preview,
65
+ disable_notification: disable_notification,
66
+ reply_to_message_id: reply_to_message_id,
67
+ parse_mode: parse_mode,
68
+ reply_markup: reply_markup
69
+ end
70
+
71
+ def edit_message_text(inline_message_id: nil,
72
+ text:,
73
+ chat_id: chat_id(),
74
+ message_id: message().message_id,
75
+ parse_mode: nil,
76
+ disable_web_page_preview: nil,
77
+ reply_markup: nil)
78
+ if text.strip.empty?
79
+ raise "A text can't be empty or consists of space symbols only"
80
+ end
81
+ @api.edit_message_text chat_id: chat_id,
82
+ message_id: message_id,
83
+ text: text,
84
+ inline_message_id: inline_message_id,
85
+ parse_mode: parse_mode,
86
+ disable_web_page_preview: disable_web_page_preview,
87
+ reply_markup: reply_markup
88
+ end
89
+
90
+ def edit_message_caption(inline_message_id: nil,
91
+ caption: nil,
92
+ chat_id: chat_id(),
93
+ message_id: message().message_id,
94
+ reply_markup: nil)
95
+ if text.strip.empty?
96
+ raise "A text can't be empty or consists of space symbols only"
97
+ end
98
+ @api.edit_message_text chat_id: chat_id,
99
+ message_id: message_id,
100
+ caption: caption,
101
+ inline_message_id: inline_message_id,
102
+ reply_markup: reply_markup
103
+ end
104
+
105
+ def edit_message_reply_markup(chat_id: chat_id(),
106
+ message_id: message().message_id,
107
+ inline_message_id: nil,
108
+ reply_markup: nil)
109
+ @api.edit_message_reply_markup chat_id: chat_id,
110
+ message_id: message_id,
111
+ inline_message_id: inline_message_id,
112
+ reply_markup: reply_markup
113
+ end
114
+
115
+ def answer_callback_query(callback_query_id: @message.id,
116
+ text: nil,
117
+ show_alert: nil,
118
+ url: nil,
119
+ cache_time: nil)
120
+ @api.answer_callback_query(callback_query_id: callback_query_id,
121
+ text: text,
122
+ show_alert: show_alert,
123
+ url: url,
124
+ cache_time: cache_time)
125
+ end
126
+
127
+ def delete_message(chat_id: chat_id(),
128
+ message_id: message().message_id)
129
+ @api.delete_message(chat_id: chat_id,
130
+ message_id: message_id)
131
+ end
132
+
133
+
134
+ def get_file(file_id:)
135
+ result = @api.get_file(file_id: file_id)
136
+ result['ok'] ? result['result'] : nil
137
+ end
138
+
139
+ def get_file_path(file_id:)
140
+ result = @api.get_file(file_id: file_id)
141
+ result['ok'] ? result['result']['file_path'] : nil
142
+ end
143
+
144
+ def get_me()
145
+ @api.get_me
146
+ end
147
+
148
+ def forward_message(chat_id:,
149
+ from_chat_id: chat_id(),
150
+ disable_notification: false,
151
+ message_id:)
152
+ @api.forward_message(chat_id: chat_id,
153
+ from_chat_id: from_chat_id,
154
+ disable_notification: disable_notification,
155
+ message_id: message_id)
156
+ end
157
+
158
+ def send_photo(chat_id: chat_id(),
159
+ photo:,
160
+ caption: nil,
161
+ disable_notification: false,
162
+ reply_to_message_id: nil,
163
+ reply_markup: nil)
164
+ @api.send_photo(chat_id: chat_id,
165
+ photo: photo,
166
+ caption: caption,
167
+ disable_notification: disable_notification,
168
+ reply_to_message_id: reply_to_message_id,
169
+ reply_markup: reply_markup)
170
+ end
171
+
172
+ def send_audio(chat_id: chat_id(),
173
+ audio:,
174
+ caption: nil,
175
+ duration: nil,
176
+ performer: nil,
177
+ title: nil,
178
+ disable_notification: false,
179
+ reply_to_message_id: nil,
180
+ reply_markup: nil)
181
+
182
+ @api.send_audio(chat_id: chat_id,
183
+ audio: audio,
184
+ caption: caption,
185
+ duration: duration,
186
+ performer: performer,
187
+ title: title,
188
+ disable_notification: disable_notification,
189
+ reply_to_message_id: reply_to_message_id,
190
+ reply_markup: reply_markup)
191
+ end
192
+
193
+ def send_media_group(chat_id: chat_id(),
194
+ media:,
195
+ disable_notification: nil,
196
+ reply_to_message_id: nil)
197
+ @api.send_media_group(chat_id: chat_id,
198
+ media: media,
199
+ disable_notification: disable_notification,
200
+ reply_to_message_id: reply_to_message_id)
201
+ end
202
+
203
+ def send_document(chat_id: chat_id(),
204
+ document:,
205
+ caption: nil,
206
+ disable_notification: false,
207
+ reply_to_message_id: nil,
208
+ reply_markup: nil)
209
+ @api.send_document(chat_id: chat_id,
210
+ document: document,
211
+ caption: caption,
212
+ disable_notification: disable_notification,
213
+ reply_to_message_id: reply_to_message_id,
214
+ reply_markup: reply_markup)
215
+ end
216
+
217
+ def send_sticker(chat_id: chat_id(),
218
+ sticker:,
219
+ caption: nil,
220
+ disable_notification: false,
221
+ reply_to_message_id: nil,
222
+ reply_markup: nil)
223
+ @api.send_sticker(chat_id: chat_id,
224
+ sticker: sticker,
225
+ caption: caption,
226
+ disable_notification: disable_notification,
227
+ reply_to_message_id: reply_to_message_id,
228
+ reply_markup: reply_markup)
229
+ end
230
+
231
+ def send_video(chat_id: chat_id(),
232
+ video:,
233
+ width: nil,
234
+ height: nil,
235
+ caption: nil,
236
+ duration: nil,
237
+ disable_notification: false,
238
+ reply_to_message_id: nil,
239
+ reply_markup: nil)
240
+ @api.send_video(chat_id: chat_id,
241
+ video: video,
242
+ width: width,
243
+ height: height,
244
+ caption: caption,
245
+ duration: duration,
246
+ disable_notification: disable_notification,
247
+ reply_to_message_id: reply_to_message_id,
248
+ reply_markup: reply_markup)
249
+ end
250
+
251
+ def send_voice(chat_id: chat_id(),
252
+ voice:,
253
+ caption: nil,
254
+ duration: nil,
255
+ disable_notification: false,
256
+ reply_to_message_id: nil,
257
+ reply_markup: nil)
258
+
259
+ @api.send_voice(chat_id: chat_id,
260
+ voice: voice,
261
+ caption: caption,
262
+ duration: duration,
263
+ disable_notification: disable_notification,
264
+ reply_to_message_id: reply_to_message_id,
265
+ reply_markup: reply_markup)
266
+ end
267
+
268
+ def send_video_note(chat_id: chat_id(),
269
+ video_note:,
270
+ length: nil,
271
+ duration: nil,
272
+ disable_notification: false,
273
+ reply_to_message_id: nil,
274
+ reply_markup: nil)
275
+ @api.send_video_note(chat_id: chat_id,
276
+ video_note: video_note,
277
+ length: length,
278
+ duration: duration,
279
+ disable_notification: disable_notification,
280
+ reply_to_message_id: reply_to_message_id,
281
+ reply_markup: reply_markup)
282
+ end
283
+
284
+ def send_location(chat_id: chat_id(),
285
+ latitude:,
286
+ longitude:,
287
+ disable_notification: false,
288
+ reply_to_message_id: nil,
289
+ reply_markup: nil)
290
+
291
+ @api.send_location(chat_id: chat_id,
292
+ latitude: latitude,
293
+ longitude: longitude,
294
+ disable_notification: disable_notification,
295
+ reply_to_message_id: reply_to_message_id,
296
+ reply_markup: reply_markup)
297
+ end
298
+
299
+ def send_venue(chat_id: chat_id(),
300
+ latitude:,
301
+ longitude:,
302
+ title:,
303
+ address:,
304
+ foursquare_id: nil,
305
+ disable_notification: false,
306
+ reply_to_message_id: nil,
307
+ reply_markup: nil)
308
+
309
+ @api.send_venue(chat_id: chat_id,
310
+ latitude: latitude,
311
+ longitude: longitude,
312
+ title: title,
313
+ address: address,
314
+ foursquare_id: foursquare_id,
315
+ disable_notification: disable_notification,
316
+ reply_to_message_id: reply_to_message_id,
317
+ reply_markup: reply_markup)
318
+ end
319
+
320
+ def send_contact(chat_id: chat_id(),
321
+ phone_number:,
322
+ first_name:,
323
+ last_name: nil,
324
+ disable_notification: false,
325
+ reply_to_message_id: nil,
326
+ reply_markup: nil)
327
+
328
+ @api.send_contact(chat_id: chat_id,
329
+ phone_number: phone_number,
330
+ first_name: first_name,
331
+ last_name: last_name,
332
+ disable_notification: disable_notification,
333
+ reply_to_message_id: reply_to_message_id,
334
+ reply_markup: reply_markup)
335
+ end
336
+
337
+ def send_chat_action(chat_id: chat_id(),
338
+ action:)
339
+ @api.send_chat_action(chat_id: chat_id,
340
+ action: action)
341
+ end
342
+
343
+ def get_user_profile_photos(chat_id: chat_id(),
344
+ offset: nil,
345
+ limit: nil)
346
+ @api.get_user_profile_photos(chat_id: chat_id,
347
+ offset: offset,
348
+ limit: limit)
349
+ end
350
+
351
+ def kick_chat_member(chat_id:,
352
+ user_id:)
353
+ @api.kick_chat_member(chat_id: chat_id,
354
+ user_id: user_id)
355
+ end
356
+
357
+ def unban_chat_member(chat_id:,
358
+ user_id:)
359
+ @api.unban_chat_member(chat_id: chat_id,
360
+ user_id: user_id)
361
+ end
362
+
363
+ def leave_chat(chat_id:)
364
+ @api.leave_chat(chat_id: chat_id)
365
+ end
366
+
367
+ def get_chat(chat_id:)
368
+ @api.get_chat(chat_id: chat_id)
369
+ end
370
+
371
+ def get_chat_administrators(chat_id:)
372
+ @api.get_chat_administrators(chat_id: chat_id)
373
+ end
374
+
375
+ def get_chat_members_count(chat_id:)
376
+ @api.get_chat_members_count(chat_id: chat_id)
377
+ end
378
+
379
+ def get_chat_member(chat_id:, user_id:)
380
+ @api.get_chat_member(chat_id: chat_id,
381
+ user_id: user_id)
382
+ end
383
+
384
+ def upload_file(file_path)
385
+ full_path = "#{Dir.pwd}/public/#{file_path}"
386
+ Faraday::UploadIO.new(full_path, "multipart/form-data")
387
+ end
388
+
389
+ alias file upload_file
390
+ alias upload upload_file
391
+
392
+ def download_file(file_path:, to:)
393
+ url = 'https://api.telegram.org/file/bot'
394
+ token = RBender::ConfigHandler.token
395
+ path = Dir.pwd + "/public/#{to}"
396
+
397
+
398
+ http_conn = Faraday.new do |builder|
399
+ builder.adapter(Faraday.default_adapter)
400
+ end
401
+
402
+ response = http_conn.get "#{url}#{token}/#{file_path}"
403
+
404
+ dir = File.dirname(path)
405
+
406
+ unless File.directory?(dir)
407
+ FileUtils.mkdir_p(dir)
408
+ end
409
+
410
+ File.open(path, 'wb') { |fp| fp.write(response.body) }
411
+ end
412
+
413
+ alias download download_file
414
+
415
+ def send_invoice(chat_id: chat_id(), title:, description:,
416
+ payload:, provider_token:, start_parameter:, currency:,
417
+ prices:, provider_data: nil, photo_url: nil, photo_size: nil,
418
+ photo_width: nil, need_name: nil, need_phone_number: nil, need_email: nil,
419
+ need_shipping_address:, send_phone_number_to_provider: nil, send_email_to_provider: nil,
420
+ is_flexible: nil, disable_notification: nil, reply_to_message_id: nil, reply_markup: nil)
421
+
422
+ @api.send_invoice(chat_id: chat_id,
423
+ title: title,
424
+ description: description,
425
+ payload: payload,
426
+ provider_token: provider_token,
427
+ start_parameter: start_parameter,
428
+ currency: currency,
429
+ prices: prices, provider_data: provider_data,
430
+ photo_url: photo_url,
431
+ photo_size: photo_size,
432
+ photo_width: photo_width,
433
+ need_name: need_name,
434
+ need_phone_number: need_phone_number,
435
+ need_email: need_email,
436
+ need_shipping_address: need_shipping_address,
437
+ send_phone_number_to_provider: send_phone_number_to_provider,
438
+ send_email_to_provider: send_email_to_provider,
439
+ is_flexible: is_flexible,
440
+ disable_notification: disable_notification,
441
+ reply_to_message_id: reply_to_message_id,
442
+ reply_markup: reply_markup)
443
+ end
444
+
445
+ def answer_shipping_query(shipping_query_id:, ok:,
446
+ shipping_options: nil, error_message: nil)
447
+ @api.answer_shipping_query(shipping_query_id: shipping_query_id,
448
+ shipping_options: shipping_options,
449
+ error_message: error_message,
450
+ ok: ok)
451
+ end
452
+
453
+ def answer_pre_checkout_query(pre_checkout_query_id: message().id, ok:, error_message: nil)
454
+ @api.answer_pre_checkout_query(pre_checkout_query_id: pre_checkout_query_id,
455
+ error_message: error_message,
456
+ ok: ok)
457
+ end
381
458
  end
382
459