telegram-bot 0.12.4 → 0.13.0
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.
- checksums.yaml +4 -4
- data/.codeclimate.yml +8 -0
- data/.rubocop.yml +3 -0
- data/.travis.yml +10 -3
- data/Appraisals +5 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -1
- data/README.md +22 -11
- data/gemfiles/rails_42.gemfile +1 -1
- data/gemfiles/rails_50.gemfile +1 -1
- data/gemfiles/rails_51.gemfile +1 -1
- data/gemfiles/rails_52.gemfile +21 -0
- data/lib/telegram/bot.rb +14 -1
- data/lib/telegram/bot/client.rb +17 -15
- data/lib/telegram/bot/config_methods.rb +3 -2
- data/lib/telegram/bot/routes_helper.rb +34 -25
- data/lib/telegram/bot/updates_controller.rb +27 -19
- data/lib/telegram/bot/updates_controller/instrumentation.rb +6 -5
- data/lib/telegram/bot/updates_controller/rescue.rb +20 -0
- data/lib/telegram/bot/updates_poller.rb +33 -19
- data/lib/telegram/bot/version.rb +1 -1
- data/telegram-bot.gemspec +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd54d434c70a78a128767db94de31a6fbf07ca11
|
4
|
+
data.tar.gz: 669957947937536ba2257af7362d97c75e82a236
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abaa6ac4240292eb5200fca36b3fc30e9e30a9232a4694cf797ef3754eb8240c728203718b6a29bf8b29792b0e9312b93bfbccc5682cfaef250a12ec95e6e9e6
|
7
|
+
data.tar.gz: 77715ec8f7cc3f2f9752d1ab3faa821dbbbaf748f8c90dcc450c351e8786150301c84e1d78c87f2ae974b5413e12a49c5617fdec737d5864837ba0cc3fb1ad3a
|
data/.codeclimate.yml
ADDED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
language: ruby
|
2
2
|
cache: bundler
|
3
3
|
rvm:
|
4
|
-
- 2.
|
4
|
+
- 2.5
|
5
|
+
- 2.4
|
6
|
+
- 2.3
|
5
7
|
gemfile:
|
6
|
-
- gemfiles/
|
7
|
-
- gemfiles/rails_50.gemfile
|
8
|
+
- gemfiles/rails_52.gemfile
|
8
9
|
- gemfiles/rails_51.gemfile
|
10
|
+
- gemfiles/rails_50.gemfile
|
11
|
+
- gemfiles/rails_42.gemfile
|
9
12
|
notifications:
|
10
13
|
email: false
|
14
|
+
|
15
|
+
# for 2.5.0 until 2.5.1 is released: https://github.com/travis-ci/travis-ci/issues/8978
|
16
|
+
before_install:
|
17
|
+
- gem update --system
|
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Unreleased
|
2
2
|
|
3
|
+
# 0.13.0
|
4
|
+
|
5
|
+
- `rescue_from`.
|
6
|
+
- Support for `credentials` store in Rails 5.2.
|
7
|
+
- Deprecate `telegram_webhooks` in favor of `telegram_webhook`.
|
8
|
+
It was too complicated and such routes looked ugly.
|
9
|
+
|
3
10
|
# 0.12.4
|
4
11
|
|
5
12
|
- Fix spec helpers for callback queries.
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -130,6 +130,9 @@ can represent actions as separate methods keeping source much more readable and
|
|
130
130
|
New instance of controller is instantiated for each update.
|
131
131
|
This way every update is processed in isolation from others.
|
132
132
|
|
133
|
+
Bot controllers like usual rails controllers provides features like callbacks,
|
134
|
+
`rescue_from` and instrumentation.
|
135
|
+
|
133
136
|
```ruby
|
134
137
|
class Telegram::WebhookController < Telegram::Bot::UpdatesController
|
135
138
|
# use callbacks like in any other controllers
|
@@ -325,29 +328,37 @@ Callback queries without prefix stay untouched.
|
|
325
328
|
# This one handles `set_value:%{something}`.
|
326
329
|
def set_value_callback_query(new_value = nil, *)
|
327
330
|
save_this(value)
|
328
|
-
answer_callback_query('Saved!)
|
331
|
+
answer_callback_query('Saved!')
|
329
332
|
end
|
330
333
|
|
331
334
|
# And this one is for `make_cool:%{something}`
|
332
335
|
def make_cool_callback_query(thing = nil, *)
|
333
336
|
do_it(thing)
|
334
|
-
answer_callback_query("#{thing} is cool now! Like a callback query context.")
|
337
|
+
answer_callback_query("#{thing} is cool now! Like a callback query context.")
|
335
338
|
end
|
336
339
|
```
|
337
340
|
|
338
341
|
### Routes in Rails app
|
339
342
|
|
340
|
-
There is `
|
343
|
+
There is `telegram_webhook` helper for rails app to define routes for webhooks.
|
341
344
|
It defines routes at `telegram/#{bot.token}` and connects bots with controller.
|
342
|
-
For more options see [examples in wiki](https://github.com/telegram-bot-rb/telegram-bot/wiki/Routes-helpers-in-details).
|
343
345
|
|
344
346
|
```ruby
|
345
|
-
#
|
346
|
-
|
347
|
+
# Most off apps would require
|
348
|
+
telegram_webhook TelegramController
|
349
|
+
# which is same as
|
350
|
+
telegram_webhook TelegramController, :default
|
347
351
|
|
348
352
|
# Use different controllers for each bot:
|
349
|
-
|
350
|
-
|
353
|
+
telegram_webhook TelegramChatController, :chat
|
354
|
+
telegram_webhook TelegramAuctionController, :auction
|
355
|
+
|
356
|
+
# Defined route is named and its name depends on `Telegram.bots`.
|
357
|
+
# For single bot it will use 'telegram_webhook',
|
358
|
+
# for multiple bots it uses bot's key in the `Telegram.bots` as prefix
|
359
|
+
# (eg. `chat_telegram_webhook`).
|
360
|
+
# You can override this with `as` option:
|
361
|
+
telegram_webhook TelegramController, as: :custom_telegram_webhook
|
351
362
|
```
|
352
363
|
|
353
364
|
#### Processesing updates
|
@@ -360,7 +371,7 @@ There are several options to run it automatically:
|
|
360
371
|
- Use poller (described in the next section).
|
361
372
|
|
362
373
|
To run action without update (ex., send notifications from jobs),
|
363
|
-
you can call `#process` directly. In this case controller can be initialized
|
374
|
+
you can call `#process` directly. In this case controller can be initialized
|
364
375
|
with `:from` and/or `:chat` options instead of `update` object:
|
365
376
|
|
366
377
|
```ruby
|
@@ -374,7 +385,7 @@ Use `rake telegram:bot:poller` to run poller in rails app. It automatically load
|
|
374
385
|
changes without restart in development env.
|
375
386
|
Optionally pass bot id in `BOT` envvar (`BOT=chat`) to specify bot to run poller for.
|
376
387
|
|
377
|
-
This task requires `
|
388
|
+
This task requires `telegram_webhook` helper to be used as it connects bots with controller.
|
378
389
|
To run poller in other cases use:
|
379
390
|
|
380
391
|
```ruby
|
@@ -523,7 +534,7 @@ Yes, it's threadsafe too.
|
|
523
534
|
|
524
535
|
## Development
|
525
536
|
|
526
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
537
|
+
After checking out the repo, run `bin/setup` to install dependencies and git hooks.
|
527
538
|
Then, run `appraisal rake spec` to run the tests.
|
528
539
|
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
529
540
|
|
data/gemfiles/rails_42.gemfile
CHANGED
data/gemfiles/rails_50.gemfile
CHANGED
data/gemfiles/rails_51.gemfile
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "actionpack", "~> 5.2.0.beta2"
|
6
|
+
gem "railties", "~> 5.2.0.beta2"
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem "appraisal", "~> 2.2"
|
10
|
+
gem "pry", "~> 0.10.1"
|
11
|
+
gem "pry-byebug", "~> 3.2.0"
|
12
|
+
gem "sdoc", "~> 0.4.1"
|
13
|
+
gem "telegram-bot-types", "~> 0.3.0"
|
14
|
+
gem "rspec", "~> 3.5.0"
|
15
|
+
gem "rspec-its", "~> 1.1.0"
|
16
|
+
gem "rspec-rails", "~> 3.5.0"
|
17
|
+
gem "rubocop", "~> 0.52.1"
|
18
|
+
gem "coveralls", "~> 0.8.2", require: false
|
19
|
+
end
|
20
|
+
|
21
|
+
gemspec path: "../"
|
data/lib/telegram/bot.rb
CHANGED
@@ -5,9 +5,22 @@ module Telegram
|
|
5
5
|
|
6
6
|
module Bot
|
7
7
|
class Error < StandardError; end
|
8
|
-
|
8
|
+
|
9
|
+
# Raised for valid telegram response with 403 status code.
|
9
10
|
class Forbidden < Error; end
|
10
11
|
|
12
|
+
# Raised for valid telegram response with 404 status code.
|
13
|
+
class NotFound < Error; end
|
14
|
+
|
15
|
+
module_function
|
16
|
+
|
17
|
+
def deprecation_0_14
|
18
|
+
@deprecation ||= begin
|
19
|
+
require 'active_support/deprecation'
|
20
|
+
ActiveSupport::Deprecation.new('0.14', 'Telegram::Bot')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
11
24
|
autoload :Async, 'telegram/bot/async'
|
12
25
|
autoload :Botan, 'telegram/bot/botan'
|
13
26
|
autoload :Client, 'telegram/bot/client'
|
data/lib/telegram/bot/client.rb
CHANGED
@@ -4,7 +4,7 @@ require 'httpclient'
|
|
4
4
|
module Telegram
|
5
5
|
module Bot
|
6
6
|
class Client
|
7
|
-
URL_TEMPLATE = 'https://api.telegram.org/bot
|
7
|
+
URL_TEMPLATE = 'https://api.telegram.org/bot%<token>s/'.freeze
|
8
8
|
|
9
9
|
autoload :TypedResponse, 'telegram/bot/client/typed_response'
|
10
10
|
extend Initializers
|
@@ -36,6 +36,18 @@ module Telegram
|
|
36
36
|
def prepare_async_args(action, body = {})
|
37
37
|
[action.to_s, Async.prepare_hash(prepare_body(body))]
|
38
38
|
end
|
39
|
+
|
40
|
+
def error_for_response(response)
|
41
|
+
result = JSON.parse(response.body) rescue nil # rubocop:disable RescueModifier
|
42
|
+
return Error.new(response.reason) unless result
|
43
|
+
message = result['description'] || '-'
|
44
|
+
# This errors are raised only for valid responses from Telegram
|
45
|
+
case response.status
|
46
|
+
when 403 then Forbidden.new(message)
|
47
|
+
when 404 then NotFound.new(message)
|
48
|
+
else Error.new("#{response.reason}: #{message}")
|
49
|
+
end
|
50
|
+
end
|
39
51
|
end
|
40
52
|
|
41
53
|
attr_reader :client, :token, :username, :base_uri
|
@@ -44,23 +56,13 @@ module Telegram
|
|
44
56
|
@client = HTTPClient.new
|
45
57
|
@token = token || options[:token]
|
46
58
|
@username = username || options[:username]
|
47
|
-
@base_uri = format
|
59
|
+
@base_uri = format(URL_TEMPLATE, token: self.token)
|
48
60
|
end
|
49
61
|
|
50
62
|
def request(action, body = {})
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
result = JSON.parse(res.body) rescue nil # rubocop:disable RescueModifier
|
55
|
-
err_msg = result && result['description'] || '-'
|
56
|
-
if result
|
57
|
-
# This errors are raised only for valid responses from Telegram
|
58
|
-
case status
|
59
|
-
when 403 then raise Forbidden, err_msg
|
60
|
-
when 404 then raise NotFound, err_msg
|
61
|
-
end
|
62
|
-
end
|
63
|
-
raise Error, "#{res.reason}: #{err_msg}"
|
63
|
+
response = http_request("#{base_uri}#{action}", self.class.prepare_body(body))
|
64
|
+
raise self.class.error_for_response(response) if response.status >= 300
|
65
|
+
JSON.parse(response.body)
|
64
66
|
end
|
65
67
|
|
66
68
|
# Endpoint for low-level request. For easy host highjacking & instrumentation.
|
@@ -53,8 +53,9 @@ module Telegram
|
|
53
53
|
def bots_config
|
54
54
|
@bots_config ||=
|
55
55
|
if defined?(Rails.application)
|
56
|
-
|
57
|
-
|
56
|
+
app = Rails.application
|
57
|
+
store = app.respond_to?(:credentials) ? app.credentials : app.secrets
|
58
|
+
secrets = store.fetch(:telegram, {}).with_indifferent_access
|
58
59
|
secrets.fetch(:bots, {}).symbolize_keys.tap do |config|
|
59
60
|
default = secrets[:bot]
|
60
61
|
config[:default] = default if default
|
@@ -28,40 +28,49 @@ module Telegram
|
|
28
28
|
# telegram_webhooks TelegramController
|
29
29
|
#
|
30
30
|
# # Or pass custom bots usin any of supported config options:
|
31
|
-
# telegram_webhooks TelegramController,
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
# # Use different controllers for each bot:
|
37
|
-
# telegram_webhooks bot => TelegramChatController,
|
38
|
-
# other_bot => TelegramAuctionController
|
39
|
-
#
|
40
|
-
# # telegram_webhooks creates named routes. See
|
41
|
-
# # RoutesHelper.route_name_for_bot for more info.
|
42
|
-
# # You can override this options or specify others:
|
43
|
-
# telegram_webhooks TelegramController, as: :my_webhook
|
44
|
-
# telegram_webhooks bot => [TelegramChatController, as: :chat_webhook],
|
45
|
-
# other_bot => TelegramAuctionController,
|
46
|
-
# admin_chat: TelegramAdminChatController
|
47
|
-
#
|
31
|
+
# telegram_webhooks TelegramController, [
|
32
|
+
# bot,
|
33
|
+
# {token: token, username: username},
|
34
|
+
# other_bot_token,
|
35
|
+
# ]
|
48
36
|
def telegram_webhooks(controllers, bots = nil, **options)
|
37
|
+
Bot.deprecation_0_14.deprecation_warning(:telegram_webhooks, <<-TXT.strip_heredoc)
|
38
|
+
It brings unnecessary complexity and encourages writeng less readable code.
|
39
|
+
Please use telegram_webhook method instead.
|
40
|
+
It's signature `telegram_webhook(controller, bot = :default, **options)`.
|
41
|
+
Multiple-bot environments now requires calling this method in a loop
|
42
|
+
or using statement for each bot.
|
43
|
+
TXT
|
49
44
|
unless controllers.is_a?(Hash)
|
50
45
|
bots = bots ? Array.wrap(bots) : Telegram.bots.values
|
51
46
|
controllers = Hash[bots.map { |x| [x, controllers] }]
|
52
47
|
end
|
53
48
|
controllers.each do |bot, controller|
|
54
|
-
bot = Client.wrap(bot)
|
55
49
|
controller, bot_options = controller if controller.is_a?(Array)
|
56
|
-
|
57
|
-
to: Middleware.new(bot, controller),
|
58
|
-
as: RoutesHelper.route_name_for_bot(bot),
|
59
|
-
format: false,
|
60
|
-
}.merge!(options).merge!(bot_options || {})
|
61
|
-
post("telegram/#{RoutesHelper.escape_token bot.token}", params)
|
62
|
-
UpdatesPoller.add(bot, controller) if Telegram.bot_poller_mode?
|
50
|
+
telegram_webhook(controller, bot, options.merge(bot_options || {}))
|
63
51
|
end
|
64
52
|
end
|
53
|
+
|
54
|
+
# Define route which processes requests using given controller and bot.
|
55
|
+
#
|
56
|
+
# telegram_webhook TelegramController, bot
|
57
|
+
#
|
58
|
+
# telegram_webhook TelegramController
|
59
|
+
# # same as:
|
60
|
+
# telegram_webhook TelegramController, :default
|
61
|
+
#
|
62
|
+
# # pass additional options
|
63
|
+
# telegram_webhook TelegramController, :default, as: :custom_route_name
|
64
|
+
def telegram_webhook(controller, bot = :default, **options)
|
65
|
+
bot = Client.wrap(bot)
|
66
|
+
params = {
|
67
|
+
to: Middleware.new(bot, controller),
|
68
|
+
as: RoutesHelper.route_name_for_bot(bot),
|
69
|
+
format: false,
|
70
|
+
}.merge!(options)
|
71
|
+
post("telegram/#{RoutesHelper.escape_token bot.token}", params)
|
72
|
+
UpdatesPoller.add(bot, controller) if Telegram.bot_poller_mode?
|
73
|
+
end
|
65
74
|
end
|
66
75
|
end
|
67
76
|
end
|
@@ -53,12 +53,19 @@ module Telegram
|
|
53
53
|
class UpdatesController < AbstractController::Base # rubocop:disable ClassLength
|
54
54
|
abstract!
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
%w[
|
57
|
+
instrumentation
|
58
|
+
log_subscriber
|
59
|
+
reply_helpers
|
60
|
+
rescue
|
61
|
+
session
|
62
|
+
].each { |file| require "telegram/bot/updates_controller/#{file}" }
|
63
|
+
|
64
|
+
%w[
|
65
|
+
CallbackQueryContext
|
66
|
+
MessageContext
|
67
|
+
TypedUpdate
|
68
|
+
].each { |mod| autoload mod, "telegram/bot/updates_controller/#{mod.underscore}" }
|
62
69
|
|
63
70
|
include AbstractController::Callbacks
|
64
71
|
# Redefine callbacks with default terminator.
|
@@ -72,11 +79,11 @@ module Telegram
|
|
72
79
|
end
|
73
80
|
|
74
81
|
include AbstractController::Translation
|
82
|
+
include Rescue
|
75
83
|
include ReplyHelpers
|
76
|
-
|
77
|
-
extend Session::ConfigMethods
|
84
|
+
include Instrumentation
|
78
85
|
|
79
|
-
|
86
|
+
extend Session::ConfigMethods
|
80
87
|
|
81
88
|
PAYLOAD_TYPES = %w[
|
82
89
|
message
|
@@ -113,10 +120,17 @@ module Telegram
|
|
113
120
|
# any commands.
|
114
121
|
def command_from_text(text, username = nil)
|
115
122
|
return unless text
|
116
|
-
match = text.match
|
123
|
+
match = text.match(CMD_REGEX)
|
117
124
|
return unless match
|
118
|
-
|
119
|
-
[match[1], text.split.drop(1)]
|
125
|
+
mention = match[3]
|
126
|
+
[match[1], text.split.drop(1)] if username == true || !mention || mention == username
|
127
|
+
end
|
128
|
+
|
129
|
+
def payload_from_update(update)
|
130
|
+
update && PAYLOAD_TYPES.find do |type|
|
131
|
+
item = update[type]
|
132
|
+
return [item, type] if item
|
133
|
+
end
|
120
134
|
end
|
121
135
|
end
|
122
136
|
|
@@ -135,13 +149,7 @@ module Telegram
|
|
135
149
|
@_update = update
|
136
150
|
@_bot = bot
|
137
151
|
@_chat, @_from = options && options.values_at(:chat, :from)
|
138
|
-
|
139
|
-
payload_data = nil
|
140
|
-
update && PAYLOAD_TYPES.find do |type|
|
141
|
-
item = update[type]
|
142
|
-
payload_data = [item, type] if item
|
143
|
-
end
|
144
|
-
@_payload, @_payload_type = payload_data
|
152
|
+
@_payload, @_payload_type = self.class.payload_from_update(update)
|
145
153
|
end
|
146
154
|
|
147
155
|
# Accessor to `'chat'` field of payload. Also tries `'chat'` in `'message'`
|
@@ -4,12 +4,13 @@ module Telegram
|
|
4
4
|
# Most methods are taken from ActionController::Instrumentation,
|
5
5
|
# some are slightly modified.
|
6
6
|
module Instrumentation
|
7
|
-
|
8
|
-
def prepended(base)
|
9
|
-
base.send :config_accessor, :logger
|
10
|
-
base.extend ClassMethods
|
11
|
-
end
|
7
|
+
extend ActiveSupport::Concern
|
12
8
|
|
9
|
+
included do
|
10
|
+
config_accessor :logger
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
13
14
|
def instrument(action, *args, &block)
|
14
15
|
ActiveSupport::Notifications.instrument(
|
15
16
|
"#{action}.updates_controller.bot.telegram",
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'active_support/rescuable'
|
2
|
+
|
3
|
+
module Telegram
|
4
|
+
module Bot
|
5
|
+
class UpdatesController
|
6
|
+
module Rescue
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
include ActiveSupport::Rescuable
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def process_action(*)
|
13
|
+
super
|
14
|
+
rescue Exception => exception # rubocop:disable RescueException
|
15
|
+
rescue_with_handler(exception) || raise
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -41,40 +41,54 @@ module Telegram
|
|
41
41
|
|
42
42
|
def start
|
43
43
|
return if running
|
44
|
-
|
45
|
-
|
44
|
+
begin
|
45
|
+
@running = true
|
46
|
+
log { 'Started bot poller.' }
|
47
|
+
run
|
48
|
+
rescue Interrupt
|
49
|
+
nil # noop
|
50
|
+
ensure
|
51
|
+
@running = false
|
52
|
+
end
|
53
|
+
log { 'Stoped polling bot updates.' }
|
54
|
+
end
|
55
|
+
|
56
|
+
def run
|
46
57
|
while running
|
47
|
-
|
48
|
-
|
49
|
-
controller.dispatch(bot, update)
|
50
|
-
end
|
51
|
-
rescue Interrupt
|
52
|
-
@running = false
|
53
|
-
rescue StandardError => e
|
54
|
-
logger.error { ([e.message] + e.backtrace).join("\n") } if logger
|
55
|
-
end
|
58
|
+
updates = fetch_updates
|
59
|
+
process_updates(updates) if updates && updates.any?
|
56
60
|
end
|
57
|
-
log { 'Stop polling bot updates.' }
|
58
61
|
end
|
59
62
|
|
63
|
+
# Method to stop poller from other thread.
|
60
64
|
def stop
|
61
65
|
return unless running
|
62
|
-
log { '
|
66
|
+
log { 'Stopping polling bot updates.' }
|
63
67
|
@running = false
|
64
68
|
end
|
65
69
|
|
66
|
-
def fetch_updates
|
70
|
+
def fetch_updates(offset = self.offset)
|
67
71
|
response = bot.async(false) { bot.get_updates(offset: offset, timeout: timeout) }
|
68
|
-
|
69
|
-
|
72
|
+
response.is_a?(Array) ? response : response['result']
|
73
|
+
rescue Timeout::Error
|
74
|
+
log { 'Fetch timeout' }
|
75
|
+
nil
|
76
|
+
end
|
77
|
+
|
78
|
+
def process_updates(updates)
|
70
79
|
reload! do
|
71
80
|
updates.each do |update|
|
72
81
|
@offset = update['update_id'] + 1
|
73
|
-
|
82
|
+
process_update(update)
|
74
83
|
end
|
75
84
|
end
|
76
|
-
rescue
|
77
|
-
|
85
|
+
rescue StandardError => e
|
86
|
+
logger.error { ([e.message] + e.backtrace).join("\n") } if logger
|
87
|
+
end
|
88
|
+
|
89
|
+
# Override this method to setup custom error collector.
|
90
|
+
def process_update(update)
|
91
|
+
controller.dispatch(bot, update)
|
78
92
|
end
|
79
93
|
|
80
94
|
def reload!
|
data/lib/telegram/bot/version.rb
CHANGED
data/telegram-bot.gemspec
CHANGED
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency 'activesupport', '>= 4.0', '< 6.0'
|
24
24
|
spec.add_dependency 'httpclient', '~> 2.7'
|
25
25
|
|
26
|
-
spec.add_development_dependency 'bundler', '~> 1.
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
27
27
|
spec.add_development_dependency 'rake', '~> 10.0'
|
28
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: telegram-bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Melentiev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -70,14 +70,14 @@ dependencies:
|
|
70
70
|
requirements:
|
71
71
|
- - "~>"
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version: '1.
|
73
|
+
version: '1.16'
|
74
74
|
type: :development
|
75
75
|
prerelease: false
|
76
76
|
version_requirements: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
78
|
- - "~>"
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
version: '1.
|
80
|
+
version: '1.16'
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: rake
|
83
83
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,6 +99,7 @@ executables: []
|
|
99
99
|
extensions: []
|
100
100
|
extra_rdoc_files: []
|
101
101
|
files:
|
102
|
+
- ".codeclimate.yml"
|
102
103
|
- ".gitignore"
|
103
104
|
- ".rspec"
|
104
105
|
- ".rubocop.yml"
|
@@ -117,6 +118,7 @@ files:
|
|
117
118
|
- gemfiles/rails_42.gemfile
|
118
119
|
- gemfiles/rails_50.gemfile
|
119
120
|
- gemfiles/rails_51.gemfile
|
121
|
+
- gemfiles/rails_52.gemfile
|
120
122
|
- lib/tasks/telegram-bot.rake
|
121
123
|
- lib/telegram/bot.rb
|
122
124
|
- lib/telegram/bot/async.rb
|
@@ -143,6 +145,7 @@ files:
|
|
143
145
|
- lib/telegram/bot/updates_controller/log_subscriber.rb
|
144
146
|
- lib/telegram/bot/updates_controller/message_context.rb
|
145
147
|
- lib/telegram/bot/updates_controller/reply_helpers.rb
|
148
|
+
- lib/telegram/bot/updates_controller/rescue.rb
|
146
149
|
- lib/telegram/bot/updates_controller/rspec_helpers.rb
|
147
150
|
- lib/telegram/bot/updates_controller/session.rb
|
148
151
|
- lib/telegram/bot/updates_controller/testing.rb
|