telegram-bot 0.14.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.travis.yml +9 -12
- data/Appraisals +16 -11
- data/CHANGELOG.md +29 -0
- data/Gemfile +1 -1
- data/README.md +48 -48
- data/bin/fetch-telegram-methods +1 -1
- data/gemfiles/rails_42.gemfile +3 -3
- data/gemfiles/rails_50.gemfile +3 -3
- data/gemfiles/rails_51.gemfile +3 -3
- data/gemfiles/rails_52.gemfile +3 -3
- data/gemfiles/rails_60.gemfile +3 -5
- data/gemfiles/rails_61.gemfile +23 -0
- data/lib/tasks/telegram-bot.rake +16 -9
- data/lib/telegram/bot.rb +3 -4
- data/lib/telegram/bot/async.rb +5 -10
- data/lib/telegram/bot/client.rb +15 -5
- data/lib/telegram/bot/client/api_methods.txt +17 -1
- data/lib/telegram/bot/config_methods.rb +6 -10
- data/lib/telegram/bot/routes_helper.rb +10 -6
- data/lib/telegram/bot/tasks.rb +63 -0
- data/lib/telegram/bot/updates_controller.rb +17 -15
- data/lib/telegram/bot/updates_controller/reply_helpers.rb +19 -2
- data/lib/telegram/bot/updates_poller.rb +1 -1
- data/lib/telegram/bot/version.rb +1 -1
- data/telegram-bot.gemspec +4 -7
- metadata +14 -18
- data/lib/telegram/bot/botan.rb +0 -53
- data/lib/telegram/bot/botan/client_helpers.rb +0 -15
- data/lib/telegram/bot/botan/controller_helpers.rb +0 -33
- data/lib/telegram/bot/initializers.rb +0 -21
- data/lib/telegram/bot/rspec/integration.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36fa85feb323b053ce1768ed84b40d1c69d0e8fc78b5dc7aee1f699462f3b4d2
|
4
|
+
data.tar.gz: 56b342a641205785fecf430bdde6601b7105f5ec3446e45f7388fe8312f77b24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfca483374037e8bc4fdd70dd0c321c3b5bf37ac877a905acae8d93befd9c9ecdf8f537357852bbb095efbb247db9408d4cad78893fb245c0c0c8278b02463f4
|
7
|
+
data.tar.gz: 39f34eda4df97c673f2f482290642a5ec186d2b0017f95f4edef28a8adef055db8f1e47504c849556b0f6ab0167326ea5fc29009279442705840afb490838bee
|
data/.rubocop.yml
CHANGED
@@ -40,6 +40,7 @@ Style/IfUnlessModifier: {Enabled: false}
|
|
40
40
|
# Consistent to other definitions.
|
41
41
|
Style/EmptyMethod: {EnforcedStyle: expanded}
|
42
42
|
|
43
|
+
Style/Lambda: {EnforcedStyle: literal}
|
43
44
|
Style/ModuleFunction: {Enabled: false}
|
44
45
|
Style/NestedParenthesizedCalls: {Enabled: false}
|
45
46
|
Style/SignalException: {EnforcedStyle: only_raise}
|
data/.travis.yml
CHANGED
@@ -1,34 +1,31 @@
|
|
1
1
|
language: ruby
|
2
2
|
cache: bundler
|
3
3
|
rvm:
|
4
|
+
- 2.6
|
4
5
|
- 2.5
|
5
|
-
- 2.4
|
6
6
|
gemfile:
|
7
|
+
- gemfiles/rails_60.gemfile
|
7
8
|
- gemfiles/rails_52.gemfile
|
8
|
-
- gemfiles/rails_51.gemfile
|
9
9
|
matrix:
|
10
10
|
include:
|
11
11
|
# old rails
|
12
|
+
- rvm: 2.5
|
13
|
+
gemfile: gemfiles/rails_51.gemfile
|
12
14
|
- rvm: 2.5
|
13
15
|
gemfile: gemfiles/rails_50.gemfile
|
14
16
|
- rvm: 2.5
|
15
17
|
gemfile: gemfiles/rails_42.gemfile
|
16
18
|
# old rubies
|
19
|
+
- rvm: 2.4
|
20
|
+
gemfile: gemfiles/rails_52.gemfile
|
17
21
|
- rvm: 2.3
|
18
22
|
gemfile: gemfiles/rails_52.gemfile
|
19
23
|
# future rails
|
20
24
|
- rvm: 2.5
|
21
|
-
gemfile: gemfiles/
|
22
|
-
# Allow rails 6 to fail while master branch is used
|
25
|
+
gemfile: gemfiles/rails_61.gemfile
|
26
|
+
# Allow rails 6.1 to fail while master branch is used
|
23
27
|
allow_failures:
|
24
28
|
- rvm: 2.5
|
25
|
-
gemfile: gemfiles/
|
29
|
+
gemfile: gemfiles/rails_61.gemfile
|
26
30
|
notifications:
|
27
31
|
email: false
|
28
|
-
|
29
|
-
# for 2.5.0 until 2.5.1 is released:
|
30
|
-
# https://github.com/travis-ci/travis-ci/issues/8978
|
31
|
-
# https://github.com/travis-ci/travis-ci/issues/8969#issuecomment-354135622
|
32
|
-
before_install:
|
33
|
-
- gem update --system
|
34
|
-
- gem install bundler
|
data/Appraisals
CHANGED
@@ -1,26 +1,31 @@
|
|
1
|
-
appraise 'rails-
|
1
|
+
appraise 'rails-61' do
|
2
2
|
git 'https://github.com/rails/rails.git' do
|
3
|
-
gem 'actionpack', '~> 6.
|
4
|
-
gem 'railties', '~> 6.
|
3
|
+
gem 'actionpack', '~> 6.1.0.alpha'
|
4
|
+
gem 'railties', '~> 6.1.0.alpha'
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
|
+
appraise 'rails-60' do
|
9
|
+
gem 'actionpack', '~> 6.0.0'
|
10
|
+
gem 'railties', '~> 6.0.0'
|
11
|
+
end
|
12
|
+
|
8
13
|
appraise 'rails-52' do
|
9
|
-
gem 'actionpack', '~> 5.2.0
|
10
|
-
gem 'railties', '~> 5.2.0
|
14
|
+
gem 'actionpack', '~> 5.2.0'
|
15
|
+
gem 'railties', '~> 5.2.0'
|
11
16
|
end
|
12
17
|
|
13
18
|
appraise 'rails-51' do
|
14
|
-
gem 'actionpack', '~> 5.1'
|
15
|
-
gem 'railties', '~> 5.1'
|
19
|
+
gem 'actionpack', '~> 5.1.0'
|
20
|
+
gem 'railties', '~> 5.1.0'
|
16
21
|
end
|
17
22
|
|
18
23
|
appraise 'rails-50' do
|
19
|
-
gem 'actionpack', '~> 5.0'
|
20
|
-
gem 'railties', '~> 5.0'
|
24
|
+
gem 'actionpack', '~> 5.0.0'
|
25
|
+
gem 'railties', '~> 5.0.0'
|
21
26
|
end
|
22
27
|
|
23
28
|
appraise 'rails-42' do
|
24
|
-
gem 'actionpack', '~> 4.2'
|
25
|
-
gem 'railties', '~> 4.2'
|
29
|
+
gem 'actionpack', '~> 4.2.0'
|
30
|
+
gem 'railties', '~> 4.2.0'
|
26
31
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,34 @@
|
|
1
1
|
# Unreleased
|
2
2
|
|
3
|
+
# 0.15.0
|
4
|
+
|
5
|
+
- Add `:path` option to `telegram_webhook` route helper.
|
6
|
+
- __Breaking change!__ Default route is generated using hashed bot token.
|
7
|
+
Please reconfigure webhook after update (`rake telegram:bot:set_webhook`).
|
8
|
+
- Update to Bot API 5.0, add rake tasks for `deleteWebhook`, `close` & `logOut`.
|
9
|
+
- Add `server` option for client to support local bot API servers.
|
10
|
+
|
11
|
+
# 0.14.4
|
12
|
+
|
13
|
+
- Update to Bot API 4.7
|
14
|
+
|
15
|
+
# 0.14.3
|
16
|
+
|
17
|
+
- Rails 6.0 support.
|
18
|
+
- Update to Bot API 4.4.
|
19
|
+
|
20
|
+
# 0.14.2
|
21
|
+
|
22
|
+
- Add reply helpers: `answer_pre_checkout_query`, `answer_shipping_query`.
|
23
|
+
- Update to Bot API 4.3.
|
24
|
+
|
25
|
+
# 0.14.1
|
26
|
+
|
27
|
+
- Read config from secrets when credentials don't provide it in rails >= 5.2.
|
28
|
+
- Remove botan.io support. It's already shut down, so it should not be a braking change.
|
29
|
+
https://github.com/botanio/sdk#this-service-will-be-shut-down-on-25th-may-2018
|
30
|
+
- Update to Bot API 4.1.
|
31
|
+
|
3
32
|
# 0.14.0
|
4
33
|
|
5
34
|
- Make integration & controller specs consistent.
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,8 +4,6 @@
|
|
4
4
|
[![Code Climate](https://codeclimate.com/github/telegram-bot-rb/telegram-bot/badges/gpa.svg)](https://codeclimate.com/github/telegram-bot-rb/telegram-bot)
|
5
5
|
[![Build Status](https://travis-ci.org/telegram-bot-rb/telegram-bot.svg)](https://travis-ci.org/telegram-bot-rb/telegram-bot)
|
6
6
|
|
7
|
-
__Breaking changes in v0.14!__ See [upgrading guide](https://github.com/telegram-bot-rb/telegram-bot/wiki/Upgrading-to-0.14).
|
8
|
-
|
9
7
|
Tools for developing Telegram bots. Best used with Rails, but can be used in
|
10
8
|
[standalone app](https://github.com/telegram-bot-rb/telegram-bot/wiki/Not-rails-application).
|
11
9
|
Supposed to be used in webhook-mode in production, and poller-mode
|
@@ -19,7 +17,7 @@ Package contains:
|
|
19
17
|
- Middleware and routes helpers for production env.
|
20
18
|
- Poller with automatic source-reloader for development env.
|
21
19
|
- Rake tasks to update webhook urls.
|
22
|
-
- __[Async mode](#async-mode)__
|
20
|
+
- __[Async mode](#async-mode)__.
|
23
21
|
Let the queue adapter handle network errors!
|
24
22
|
|
25
23
|
Here is sample [telegram_bot_app](https://github.com/telegram-bot-rb/telegram_bot_app)
|
@@ -55,9 +53,32 @@ require 'telegram/bot'
|
|
55
53
|
|
56
54
|
## Usage
|
57
55
|
|
56
|
+
### Configuration
|
57
|
+
|
58
|
+
While clients can be instantiated explicitly, there is `Telegram.bots_config=` method
|
59
|
+
to configure app-wide clients, which are accessible via `Telegram.bots`.
|
60
|
+
It accepts hash of `{bot_id: bot_config}`, and there is special id `:default`
|
61
|
+
which is used for `Telegram.bot`.
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
Telegram.bots_config = {
|
65
|
+
default: DEFAULT_BOT_TOKEN,
|
66
|
+
chat: {
|
67
|
+
token: CHAT_BOT_TOKEN,
|
68
|
+
username: 'ChatBot', # to support commands with mentions (/help@ChatBot)
|
69
|
+
server: 'http://local.bot.api.server', # for Local Bot API Server
|
70
|
+
},
|
71
|
+
}
|
72
|
+
|
73
|
+
Telegram.bot.get_updates
|
74
|
+
Telegram.bot == Telegram.bots[:default] # true
|
75
|
+
Telegram.bots[:chat].send_message(...)
|
76
|
+
```
|
77
|
+
|
58
78
|
### Configuration in Rails app
|
59
79
|
|
60
|
-
|
80
|
+
In Rails app `Telegram.bots_config` is read from `secrets.yml` automatically
|
81
|
+
from `telegram` section:
|
61
82
|
|
62
83
|
```yml
|
63
84
|
development:
|
@@ -68,6 +89,7 @@ development:
|
|
68
89
|
bot:
|
69
90
|
token: TOKEN
|
70
91
|
username: SomeBot
|
92
|
+
server: http://local.bot.api.server
|
71
93
|
|
72
94
|
# For multiple bots in single app use hash of `internal_bot_id => settings`
|
73
95
|
bots:
|
@@ -79,6 +101,17 @@ development:
|
|
79
101
|
username: ChatBot
|
80
102
|
```
|
81
103
|
|
104
|
+
For Rails >= 5.2 `Telegram::Bot` searches for config first in credentials and then in secrets.
|
105
|
+
To use credentials as config store, add telegram section to credentials instead of secrets using
|
106
|
+
`rails credentials:edit`. In this case be aware of that [Rails < 6.0 may not load
|
107
|
+
credentials in dev environment by default](https://github.com/telegram-bot-rb/telegram-bot/issues/74#issuecomment-384205609).
|
108
|
+
In Rails >= 6.0 run `rails credentials:edit --environment development` to configure bot
|
109
|
+
in each environment.
|
110
|
+
|
111
|
+
I suggest not using Rails 5.2 credentials because it can lead to leakage of sensitive data
|
112
|
+
and it's more difficult to use in multiple environments. See
|
113
|
+
[secure_credentials](https://github.com/printercu/secure_credentials) gem for better option.
|
114
|
+
|
82
115
|
From now clients will be accessible with `Telegram.bots[:chat]` or `Telegram.bots[:auction]`.
|
83
116
|
Single bot can be accessed with `Telegram.bot` or `Telegram.bots[:default]`.
|
84
117
|
|
@@ -201,12 +234,14 @@ def reply_with(type, params); end
|
|
201
234
|
def answer_inline_query(results, params = {}); end
|
202
235
|
def answer_callback_query(text, params = {}); end
|
203
236
|
def edit_message(type, params = {}); end
|
237
|
+
def answer_pre_checkout_query(ok, params = {}); end
|
238
|
+
def answer_shipping_query(ok, params = {}); end
|
204
239
|
```
|
205
240
|
|
206
241
|
#### Optional typecasting
|
207
242
|
|
208
243
|
You can enable typecasting of `update` with `telegram-bot-types` by including
|
209
|
-
`Telegram::Bot::
|
244
|
+
`Telegram::Bot::UpdatesController::TypedUpdate`:
|
210
245
|
|
211
246
|
```ruby
|
212
247
|
class Telegram::WebhookController < Telegram::Bot::UpdatesController
|
@@ -334,7 +369,7 @@ end
|
|
334
369
|
### Routes in Rails app
|
335
370
|
|
336
371
|
There is `telegram_webhook` helper for rails app to define routes for webhooks.
|
337
|
-
It defines routes at `telegram/#{bot.token}` and connects bots with controller.
|
372
|
+
It defines routes at `telegram/#{hash_of(bot.token)}` and connects bots with controller.
|
338
373
|
|
339
374
|
```ruby
|
340
375
|
# Most off apps would require
|
@@ -443,10 +478,11 @@ RSpec.describe TelegramWebhooksController, telegram_bot: :rails do
|
|
443
478
|
# dispatch_command(cmd, *args)
|
444
479
|
|
445
480
|
# Available matchers can be found in Telegram::Bot::RSpec::ClientMatchers.
|
446
|
-
it 'shows usage of basic matchers'
|
447
|
-
# The most basic one is #make_telegram_request(bot,
|
448
|
-
|
449
|
-
|
481
|
+
it 'shows usage of basic matchers' do
|
482
|
+
# The most basic one is #make_telegram_request(bot, action).
|
483
|
+
# It works similar to `receive` matcher and supports chaining `.with(args).exactly(n).times`.
|
484
|
+
expect { dispatch_command(:start) }.to make_telegram_request(bot, :sendMessage).
|
485
|
+
with(hash_including(text: 'msg text'))
|
450
486
|
|
451
487
|
# There are some shortcuts for dispatching basic updates and testing responses.
|
452
488
|
expect { dispatch_message('Hi') }.to send_telegram_message(bot, /msg regexp/, some: :option)
|
@@ -494,48 +530,12 @@ While webhooks-mode is prefered, poller still can be used in production.
|
|
494
530
|
See [comparison and examples](https://github.com/telegram-bot-rb/telegram-bot/wiki/Deployment)
|
495
531
|
for details.
|
496
532
|
|
497
|
-
### Botan.io metrics
|
498
|
-
|
499
|
-
Initialize with `bot = Telegram::Bot::Client.new(token, botan: 'botan token')`
|
500
|
-
or just add `botan` key in `secrets.yml`:
|
501
|
-
|
502
|
-
```yml
|
503
|
-
telegram:
|
504
|
-
bot:
|
505
|
-
token: bot_token
|
506
|
-
botan: botan_token
|
507
|
-
```
|
508
|
-
|
509
|
-
Access to Botan client with `bot.botan`.
|
510
|
-
Use `bot.botan.track(event, uid, payload)` to track events.
|
511
|
-
|
512
|
-
There are some helpers for controllers in `Telegram::Bot::Botan::ControllerHelpers`:
|
513
|
-
|
514
|
-
```ruby
|
515
|
-
class Telegram::WebhookController < Telegram::Bot::UpdatesController
|
516
|
-
include Telegram::Bot::Botan::ControllerHelpers
|
517
|
-
|
518
|
-
# This will track with event: action_name & data: payload
|
519
|
-
before_action :botan_track_action
|
520
|
-
|
521
|
-
def smth(*)
|
522
|
-
# This will track event for current user only when botan is configured.
|
523
|
-
botan_track :my_event, custom_data
|
524
|
-
|
525
|
-
# or get access directly to botan client:
|
526
|
-
botan.track(...)
|
527
|
-
end
|
528
|
-
end
|
529
|
-
```
|
530
|
-
|
531
|
-
There is no stubbing for botan clients, so don't set botan token in tests.
|
532
|
-
|
533
533
|
### Async mode
|
534
534
|
|
535
535
|
There is built in support for async requests using ActiveJob. Without Rails
|
536
536
|
you can implement your own worker class to handle such requests. This allows:
|
537
537
|
|
538
|
-
- Process updates very fast, without waiting for telegram
|
538
|
+
- Process updates very fast, without waiting for telegram responses.
|
539
539
|
- Handle and retry network and other errors with queue adapter.
|
540
540
|
- ???
|
541
541
|
|
@@ -543,7 +543,7 @@ Instead of performing request instantly client serializes it, pushes to queue,
|
|
543
543
|
and immediately return control back. The job is then fetched with a worker
|
544
544
|
and real API request is performed. And this all is absolutely transparent for the app.
|
545
545
|
|
546
|
-
To enable this mode add `async: true` to bot's
|
546
|
+
To enable this mode add `async: true` to bot's config.
|
547
547
|
For more information and custom configuration check out
|
548
548
|
[docs](http://www.rubydoc.info/github/telegram-bot-rb/telegram-bot/master/Telegram/Bot/Async) or
|
549
549
|
[source](https://github.com/telegram-bot-rb/telegram-bot/blob/master/lib/telegram/bot/async.rb).
|
data/bin/fetch-telegram-methods
CHANGED
@@ -25,7 +25,7 @@ method_list = headers.
|
|
25
25
|
map { |g| g.reject { |x| x.match?(NOT_METHOD_REGEXP) } }.
|
26
26
|
reject(&:empty?)
|
27
27
|
|
28
|
-
api_version = doc.text.match(/^(Bot API ([\d\.]+))\.?$/)
|
28
|
+
api_version = doc.text.match(/^(?:Introducing )?(Bot API ([\d\.]+))\.?$/)
|
29
29
|
|
30
30
|
result = ['# Generated with bin/fetch-telegram-methods']
|
31
31
|
result << "# #{api_version[1]}" if api_version
|
data/gemfiles/rails_42.gemfile
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "actionpack", "~> 4.2"
|
6
|
-
gem "railties", "~> 4.2"
|
5
|
+
gem "actionpack", "~> 4.2.0"
|
6
|
+
gem "railties", "~> 4.2.0"
|
7
7
|
|
8
8
|
group :development do
|
9
9
|
gem "appraisal", "~> 2.2"
|
10
10
|
gem "pry", "~> 0.10.1"
|
11
11
|
gem "pry-byebug", "~> 3.2.0"
|
12
12
|
gem "sdoc", "~> 0.4.1"
|
13
|
-
gem "telegram-bot-types", "~> 0.6.
|
13
|
+
gem "telegram-bot-types", "~> 0.6.2"
|
14
14
|
gem "rspec", "~> 3.5.0"
|
15
15
|
gem "rspec-its", "~> 1.1.0"
|
16
16
|
gem "rspec-rails", "~> 3.5.0"
|
data/gemfiles/rails_50.gemfile
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "actionpack", "~> 5.0"
|
6
|
-
gem "railties", "~> 5.0"
|
5
|
+
gem "actionpack", "~> 5.0.0"
|
6
|
+
gem "railties", "~> 5.0.0"
|
7
7
|
|
8
8
|
group :development do
|
9
9
|
gem "appraisal", "~> 2.2"
|
10
10
|
gem "pry", "~> 0.10.1"
|
11
11
|
gem "pry-byebug", "~> 3.2.0"
|
12
12
|
gem "sdoc", "~> 0.4.1"
|
13
|
-
gem "telegram-bot-types", "~> 0.6.
|
13
|
+
gem "telegram-bot-types", "~> 0.6.2"
|
14
14
|
gem "rspec", "~> 3.5.0"
|
15
15
|
gem "rspec-its", "~> 1.1.0"
|
16
16
|
gem "rspec-rails", "~> 3.5.0"
|
data/gemfiles/rails_51.gemfile
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "actionpack", "~> 5.1"
|
6
|
-
gem "railties", "~> 5.1"
|
5
|
+
gem "actionpack", "~> 5.1.0"
|
6
|
+
gem "railties", "~> 5.1.0"
|
7
7
|
|
8
8
|
group :development do
|
9
9
|
gem "appraisal", "~> 2.2"
|
10
10
|
gem "pry", "~> 0.10.1"
|
11
11
|
gem "pry-byebug", "~> 3.2.0"
|
12
12
|
gem "sdoc", "~> 0.4.1"
|
13
|
-
gem "telegram-bot-types", "~> 0.6.
|
13
|
+
gem "telegram-bot-types", "~> 0.6.2"
|
14
14
|
gem "rspec", "~> 3.5.0"
|
15
15
|
gem "rspec-its", "~> 1.1.0"
|
16
16
|
gem "rspec-rails", "~> 3.5.0"
|
data/gemfiles/rails_52.gemfile
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "actionpack", "~> 5.2.0
|
6
|
-
gem "railties", "~> 5.2.0
|
5
|
+
gem "actionpack", "~> 5.2.0"
|
6
|
+
gem "railties", "~> 5.2.0"
|
7
7
|
|
8
8
|
group :development do
|
9
9
|
gem "appraisal", "~> 2.2"
|
10
10
|
gem "pry", "~> 0.10.1"
|
11
11
|
gem "pry-byebug", "~> 3.2.0"
|
12
12
|
gem "sdoc", "~> 0.4.1"
|
13
|
-
gem "telegram-bot-types", "~> 0.6.
|
13
|
+
gem "telegram-bot-types", "~> 0.6.2"
|
14
14
|
gem "rspec", "~> 3.5.0"
|
15
15
|
gem "rspec-its", "~> 1.1.0"
|
16
16
|
gem "rspec-rails", "~> 3.5.0"
|
data/gemfiles/rails_60.gemfile
CHANGED
@@ -2,17 +2,15 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
gem "railties", "~> 6.0.0.alpha"
|
8
|
-
end
|
5
|
+
gem "actionpack", "~> 6.0.0"
|
6
|
+
gem "railties", "~> 6.0.0"
|
9
7
|
|
10
8
|
group :development do
|
11
9
|
gem "appraisal", "~> 2.2"
|
12
10
|
gem "pry", "~> 0.10.1"
|
13
11
|
gem "pry-byebug", "~> 3.2.0"
|
14
12
|
gem "sdoc", "~> 0.4.1"
|
15
|
-
gem "telegram-bot-types", "~> 0.6.
|
13
|
+
gem "telegram-bot-types", "~> 0.6.2"
|
16
14
|
gem "rspec", "~> 3.5.0"
|
17
15
|
gem "rspec-its", "~> 1.1.0"
|
18
16
|
gem "rspec-rails", "~> 3.5.0"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
git "https://github.com/rails/rails.git" do
|
6
|
+
gem "actionpack", "~> 6.1.0.alpha"
|
7
|
+
gem "railties", "~> 6.1.0.alpha"
|
8
|
+
end
|
9
|
+
|
10
|
+
group :development do
|
11
|
+
gem "appraisal", "~> 2.2"
|
12
|
+
gem "pry", "~> 0.10.1"
|
13
|
+
gem "pry-byebug", "~> 3.2.0"
|
14
|
+
gem "sdoc", "~> 0.4.1"
|
15
|
+
gem "telegram-bot-types", "~> 0.6.2"
|
16
|
+
gem "rspec", "~> 3.5.0"
|
17
|
+
gem "rspec-its", "~> 1.1.0"
|
18
|
+
gem "rspec-rails", "~> 3.5.0"
|
19
|
+
gem "rubocop", "~> 0.52.1"
|
20
|
+
gem "coveralls", "~> 0.8.2", require: false
|
21
|
+
end
|
22
|
+
|
23
|
+
gemspec path: "../"
|
data/lib/tasks/telegram-bot.rake
CHANGED
@@ -14,15 +14,22 @@ namespace :telegram do
|
|
14
14
|
|
15
15
|
desc 'Set webhook urls for all bots'
|
16
16
|
task set_webhook: :environment do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
Telegram::Bot::Tasks.set_webhook
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Delete webhooks for all or specific BOT'
|
21
|
+
task :delete_webhook do
|
22
|
+
Telegram::Bot::Tasks.delete_webhook
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Perform logOut command for all or specific BOT'
|
26
|
+
task :log_out do
|
27
|
+
Telegram::Bot::Tasks.log_out
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'Perform `close` command for all or specific BOT'
|
31
|
+
task :close do
|
32
|
+
Telegram::Bot::Tasks.close
|
26
33
|
end
|
27
34
|
end
|
28
35
|
end
|
data/lib/telegram/bot.rb
CHANGED
@@ -14,21 +14,20 @@ module Telegram
|
|
14
14
|
|
15
15
|
module_function
|
16
16
|
|
17
|
-
def
|
17
|
+
def deprecation_0_16
|
18
18
|
@deprecation ||= begin
|
19
19
|
require 'active_support/deprecation'
|
20
|
-
ActiveSupport::Deprecation.new('0.
|
20
|
+
ActiveSupport::Deprecation.new('0.16', 'Telegram::Bot')
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
autoload :Async, 'telegram/bot/async'
|
25
|
-
autoload :Botan, 'telegram/bot/botan'
|
26
25
|
autoload :Client, 'telegram/bot/client'
|
27
26
|
autoload :ClientStub, 'telegram/bot/client_stub'
|
28
27
|
autoload :DebugClient, 'telegram/bot/debug_client'
|
29
|
-
autoload :Initializers, 'telegram/bot/initializers'
|
30
28
|
autoload :Middleware, 'telegram/bot/middleware'
|
31
29
|
autoload :RSpec, 'telegram/bot/rspec'
|
30
|
+
autoload :Tasks, 'telegram/bot/tasks'
|
32
31
|
autoload :UpdatesController, 'telegram/bot/updates_controller'
|
33
32
|
autoload :UpdatesPoller, 'telegram/bot/updates_poller'
|
34
33
|
end
|
data/lib/telegram/bot/async.rb
CHANGED
@@ -1,28 +1,23 @@
|
|
1
1
|
module Telegram
|
2
2
|
module Bot
|
3
|
-
# Telegram
|
3
|
+
# Telegram clients can perform requests in async way with
|
4
4
|
# any job adapter (ActiveJob by default). Using Rails you don't need any
|
5
5
|
# additional configuration. However you may want to enable async requests
|
6
|
-
# by default with `async: true` in `secrets.yml`.
|
7
|
-
# async setting from client and must be configured separately.
|
6
|
+
# by default with `async: true` in `secrets.yml`.
|
8
7
|
#
|
9
8
|
# telegram:
|
10
9
|
# bots:
|
11
10
|
# chat_async:
|
12
11
|
# token: secret
|
13
12
|
# async: true # enable async mode for client
|
14
|
-
# botan: botan_token # in this way botan will not be async
|
15
|
-
# botan: # in this way - it's in async mode
|
16
|
-
# token: botan_token
|
17
|
-
# async: true
|
18
13
|
#
|
19
14
|
# Without Rails To start using async requests
|
20
15
|
# initialize client with `id` kwarg and make sure the client is
|
21
16
|
# accessible via `Teletgram.bots[id]` in job worker. Or just use
|
22
17
|
# `Telegram.bots_config=` for configuration.
|
23
18
|
#
|
24
|
-
# Being in async mode `#request` enqueues job
|
25
|
-
# http request instead of performing it
|
19
|
+
# Being in async mode `#request` enqueues job to perform
|
20
|
+
# http request instead of performing it immediately.
|
26
21
|
# Async behavior is controlled with `#async=` writer
|
27
22
|
# and can be enabled/disabled for the block with `#async`:
|
28
23
|
#
|
@@ -34,7 +29,7 @@ module Telegram
|
|
34
29
|
# while `#async(val, &block)` is thread-safe.
|
35
30
|
#
|
36
31
|
# It can be set with custom job class or classname. By default it defines
|
37
|
-
# job classes
|
32
|
+
# job classes inherited from ApplicationJob, which
|
38
33
|
# can be accessed via `.default_async_job`. You can integrate it with any
|
39
34
|
# other job provider by defining a class with `.perform_later(bot_id, *args)`
|
40
35
|
# method. See Async::Job for implemetation.
|
data/lib/telegram/bot/client.rb
CHANGED
@@ -1,21 +1,31 @@
|
|
1
|
+
require 'active_support/core_ext/hash/keys'
|
1
2
|
require 'json'
|
2
3
|
require 'httpclient'
|
3
4
|
|
4
5
|
module Telegram
|
5
6
|
module Bot
|
6
7
|
class Client
|
7
|
-
|
8
|
+
SERVER = 'https://api.telegram.org'.freeze
|
9
|
+
URL_TEMPLATE = '%<server>s/bot%<token>s/'.freeze
|
8
10
|
|
9
11
|
autoload :TypedResponse, 'telegram/bot/client/typed_response'
|
10
|
-
extend Initializers
|
11
12
|
prepend Async
|
12
|
-
prepend Botan::ClientHelpers
|
13
13
|
include DebugClient
|
14
14
|
|
15
15
|
require 'telegram/bot/client/api_helper'
|
16
16
|
include ApiHelper
|
17
17
|
|
18
18
|
class << self
|
19
|
+
# Accepts different options to initialize bot.
|
20
|
+
def wrap(input, **options)
|
21
|
+
case input
|
22
|
+
when Symbol then by_id(input) or raise "#{name} #{input.inspect} not configured"
|
23
|
+
when self then input
|
24
|
+
when Hash then new(**input.symbolize_keys, **options)
|
25
|
+
else new(input, **options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
19
29
|
def by_id(id)
|
20
30
|
Telegram.bots[id]
|
21
31
|
end
|
@@ -52,11 +62,11 @@ module Telegram
|
|
52
62
|
|
53
63
|
attr_reader :client, :token, :username, :base_uri
|
54
64
|
|
55
|
-
def initialize(token = nil, username = nil, **options)
|
65
|
+
def initialize(token = nil, username = nil, server: SERVER, **options)
|
56
66
|
@client = HTTPClient.new
|
57
67
|
@token = token || options[:token]
|
58
68
|
@username = username || options[:username]
|
59
|
-
@base_uri = format(URL_TEMPLATE, token: self.token)
|
69
|
+
@base_uri = format(URL_TEMPLATE, server: server, token: self.token)
|
60
70
|
end
|
61
71
|
|
62
72
|
def request(action, body = {})
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Generated with bin/fetch-telegram-methods
|
2
|
-
# Bot API
|
2
|
+
# Bot API 5.0
|
3
3
|
|
4
4
|
getUpdates
|
5
5
|
setWebhook
|
@@ -7,12 +7,16 @@ deleteWebhook
|
|
7
7
|
getWebhookInfo
|
8
8
|
|
9
9
|
getMe
|
10
|
+
logOut
|
11
|
+
close
|
10
12
|
sendMessage
|
11
13
|
forwardMessage
|
14
|
+
copyMessage
|
12
15
|
sendPhoto
|
13
16
|
sendAudio
|
14
17
|
sendDocument
|
15
18
|
sendVideo
|
19
|
+
sendAnimation
|
16
20
|
sendVoice
|
17
21
|
sendVideoNote
|
18
22
|
sendMediaGroup
|
@@ -21,6 +25,8 @@ editMessageLiveLocation
|
|
21
25
|
stopMessageLiveLocation
|
22
26
|
sendVenue
|
23
27
|
sendContact
|
28
|
+
sendPoll
|
29
|
+
sendDice
|
24
30
|
sendChatAction
|
25
31
|
getUserProfilePhotos
|
26
32
|
getFile
|
@@ -28,6 +34,8 @@ kickChatMember
|
|
28
34
|
unbanChatMember
|
29
35
|
restrictChatMember
|
30
36
|
promoteChatMember
|
37
|
+
setChatAdministratorCustomTitle
|
38
|
+
setChatPermissions
|
31
39
|
exportChatInviteLink
|
32
40
|
setChatPhoto
|
33
41
|
deleteChatPhoto
|
@@ -35,6 +43,7 @@ setChatTitle
|
|
35
43
|
setChatDescription
|
36
44
|
pinChatMessage
|
37
45
|
unpinChatMessage
|
46
|
+
unpinAllChatMessages
|
38
47
|
leaveChat
|
39
48
|
getChat
|
40
49
|
getChatAdministrators
|
@@ -43,10 +52,14 @@ getChatMember
|
|
43
52
|
setChatStickerSet
|
44
53
|
deleteChatStickerSet
|
45
54
|
answerCallbackQuery
|
55
|
+
setMyCommands
|
56
|
+
getMyCommands
|
46
57
|
|
47
58
|
editMessageText
|
48
59
|
editMessageCaption
|
60
|
+
editMessageMedia
|
49
61
|
editMessageReplyMarkup
|
62
|
+
stopPoll
|
50
63
|
deleteMessage
|
51
64
|
|
52
65
|
sendSticker
|
@@ -56,6 +69,7 @@ createNewStickerSet
|
|
56
69
|
addStickerToSet
|
57
70
|
setStickerPositionInSet
|
58
71
|
deleteStickerFromSet
|
72
|
+
setStickerSetThumb
|
59
73
|
|
60
74
|
answerInlineQuery
|
61
75
|
|
@@ -63,6 +77,8 @@ sendInvoice
|
|
63
77
|
answerShippingQuery
|
64
78
|
answerPreCheckoutQuery
|
65
79
|
|
80
|
+
setPassportDataErrors
|
81
|
+
|
66
82
|
sendGame
|
67
83
|
setGameScore
|
68
84
|
getGameHighScores
|
@@ -40,11 +40,6 @@ module Telegram
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
# Hash of botan clients made from #bots.
|
44
|
-
def botans
|
45
|
-
@botans ||= bots.map { |k, v| [k, v.botan] }.to_h
|
46
|
-
end
|
47
|
-
|
48
43
|
# Returns config for .bots method. By default uses `telegram['bots']` section
|
49
44
|
# from `secrets.yml` merging `telegram['bot']` at `:default` key.
|
50
45
|
#
|
@@ -53,10 +48,12 @@ module Telegram
|
|
53
48
|
@bots_config ||=
|
54
49
|
if defined?(Rails.application)
|
55
50
|
app = Rails.application
|
56
|
-
store = app.respond_to?(:credentials)
|
57
|
-
secrets
|
58
|
-
|
59
|
-
|
51
|
+
store = app.credentials[:telegram] if app.respond_to?(:credentials)
|
52
|
+
store ||= app.secrets[:telegram] if app.respond_to?(:secrets)
|
53
|
+
store ||= {}
|
54
|
+
store = store.with_indifferent_access
|
55
|
+
store.fetch(:bots, {}).symbolize_keys.tap do |config|
|
56
|
+
default = store[:bot]
|
60
57
|
config[:default] = default if default
|
61
58
|
end
|
62
59
|
else
|
@@ -69,7 +66,6 @@ module Telegram
|
|
69
66
|
@bots = nil
|
70
67
|
@bot = nil
|
71
68
|
@bots_config = nil
|
72
|
-
@botans = nil
|
73
69
|
end
|
74
70
|
end
|
75
71
|
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'openssl'
|
3
|
+
|
1
4
|
require 'telegram/bot'
|
2
5
|
require 'active_support/core_ext/array/wrap'
|
3
6
|
|
@@ -17,10 +20,8 @@ module Telegram
|
|
17
20
|
end || 'telegram_webhook'
|
18
21
|
end
|
19
22
|
|
20
|
-
|
21
|
-
|
22
|
-
def escape_token(token)
|
23
|
-
token && token.tr(':', '_')
|
23
|
+
def token_hash(token)
|
24
|
+
Base64.urlsafe_encode64(OpenSSL::Digest::SHA1.digest(token), padding: false)
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
@@ -34,14 +35,17 @@ module Telegram
|
|
34
35
|
#
|
35
36
|
# # pass additional options
|
36
37
|
# telegram_webhook TelegramController, :default, as: :custom_route_name
|
37
|
-
|
38
|
+
#
|
39
|
+
# # Default path is generated using hashed bot token. Override it using:
|
40
|
+
# telegram_webhook TelegramController, :default, path: 'top/secret'
|
41
|
+
def telegram_webhook(controller, bot = :default, path: nil, **options)
|
38
42
|
bot = Client.wrap(bot)
|
39
43
|
params = {
|
40
44
|
to: Middleware.new(bot, controller),
|
41
45
|
as: RoutesHelper.route_name_for_bot(bot),
|
42
46
|
format: false,
|
43
47
|
}.merge!(options)
|
44
|
-
post("telegram/#{RoutesHelper.
|
48
|
+
post(path || "telegram/#{bot.token && RoutesHelper.token_hash(bot.token)}", params)
|
45
49
|
UpdatesPoller.add(bot, controller) if Telegram.bot_poller_mode?
|
46
50
|
end
|
47
51
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Telegram
|
4
|
+
module Bot
|
5
|
+
module Tasks
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def set_webhook
|
9
|
+
routes = Rails.application.routes.url_helpers
|
10
|
+
cert_file = ENV['CERT']
|
11
|
+
cert = File.open(cert_file) if cert_file
|
12
|
+
each_bot do |key, bot|
|
13
|
+
route_name = RoutesHelper.route_name_for_bot(bot)
|
14
|
+
url = routes.send("#{route_name}_url")
|
15
|
+
say("Setting webhook for #{key}...")
|
16
|
+
bot.set_webhook(
|
17
|
+
url: url,
|
18
|
+
certificate: cert,
|
19
|
+
ip_address: ENV['IP_ADDRESS'],
|
20
|
+
drop_pending_updates: drop_pending_updates,
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete_webhook
|
26
|
+
each_bot do |key, bot|
|
27
|
+
say("Deleting webhook for #{key}...")
|
28
|
+
bot.delete_webhook(drop_pending_updates: drop_pending_updates)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def log_out
|
33
|
+
each_bot do |key, bot|
|
34
|
+
say("Logging out #{key}...")
|
35
|
+
bot.log_out
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def close
|
40
|
+
each_bot do |key, bot|
|
41
|
+
say("Closing #{key}...")
|
42
|
+
bot.close
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def say(text)
|
49
|
+
puts(text) unless Rails.env.test? # rubocop:disable Rails/Output
|
50
|
+
end
|
51
|
+
|
52
|
+
def each_bot(&block)
|
53
|
+
id = ENV['BOT'].try!(:to_sym)
|
54
|
+
bots = id ? {id => Client.by_id(id)} : Telegram.bots
|
55
|
+
bots.each { |key, bot| bot.async(false) { block[key, bot] } }
|
56
|
+
end
|
57
|
+
|
58
|
+
def drop_pending_updates
|
59
|
+
ENV['DROP_PENDING_UPDATES'].try!(:downcase) == 'true'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -7,13 +7,13 @@ module Telegram
|
|
7
7
|
module Bot
|
8
8
|
# Base class to create update processors. With callbacks, session and helpers.
|
9
9
|
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
10
|
+
# Public methods ending with `!` handle messages with commands.
|
11
|
+
# Message text is automatically parsed into method arguments.
|
12
|
+
# Be sure to use default values and
|
13
13
|
# splat arguments in every action method to not get errors, when user
|
14
14
|
# sends command without necessary args / with extra args.
|
15
15
|
#
|
16
|
-
# def start(token = nil, *)
|
16
|
+
# def start!(token = nil, *)
|
17
17
|
# if token
|
18
18
|
# # ...
|
19
19
|
# else
|
@@ -21,25 +21,21 @@ module Telegram
|
|
21
21
|
# end
|
22
22
|
# end
|
23
23
|
#
|
24
|
-
# def help(*)
|
24
|
+
# def help!(*)
|
25
25
|
# respond_with :message, text:
|
26
26
|
# end
|
27
27
|
#
|
28
28
|
# To process plain text messages (without commands) or other updates just
|
29
|
-
# define public method with name of payload type.
|
30
|
-
# as an argument
|
29
|
+
# define public method with name of payload type.
|
30
|
+
# By default they receive payload as an argument, but some of them are called
|
31
|
+
# with more usefuk args:
|
31
32
|
#
|
32
33
|
# def message(message)
|
33
34
|
# respond_with :message, text: "Echo: #{message['text']}"
|
34
35
|
# end
|
35
36
|
#
|
36
|
-
# def inline_query(query)
|
37
|
-
# answer_inline_query results_for_query(query), is_personal: true
|
38
|
-
# end
|
39
|
-
#
|
40
|
-
# # To process conflicting commands (`/message args`) just use `on_` prefix:
|
41
|
-
# def on_message(*args)
|
42
|
-
# # ...
|
37
|
+
# def inline_query(query, offset)
|
38
|
+
# answer_inline_query results_for_query(query, offset), is_personal: true
|
43
39
|
# end
|
44
40
|
#
|
45
41
|
# To process update run:
|
@@ -101,6 +97,8 @@ module Telegram
|
|
101
97
|
callback_query
|
102
98
|
shipping_query
|
103
99
|
pre_checkout_query
|
100
|
+
poll
|
101
|
+
poll_answer
|
104
102
|
].freeze
|
105
103
|
|
106
104
|
class << self
|
@@ -152,7 +150,7 @@ module Telegram
|
|
152
150
|
# Accessor to `'from'` field of payload. Can be overriden with `from` option
|
153
151
|
# for #initialize.
|
154
152
|
def from
|
155
|
-
@_from ||= payload
|
153
|
+
@_from ||= payload.is_a?(Hash) ? payload['from'] : payload.try(:from)
|
156
154
|
end
|
157
155
|
|
158
156
|
# Processes current update.
|
@@ -210,6 +208,10 @@ module Telegram
|
|
210
208
|
[payload_type, [payload['data']]]
|
211
209
|
end
|
212
210
|
|
211
|
+
def action_for_poll_answer
|
212
|
+
[payload_type, [payload['poll_id'], payload['option_ids']]]
|
213
|
+
end
|
214
|
+
|
213
215
|
# Silently ignore unsupported messages to not fail when user crafts
|
214
216
|
# an update with usupported command, callback query context, etc.
|
215
217
|
def action_missing(action, *_args)
|
@@ -21,7 +21,7 @@ module Telegram
|
|
21
21
|
respond_with(type, params)
|
22
22
|
end
|
23
23
|
|
24
|
-
# Same as
|
24
|
+
# Same as respond_with, but for inline queries.
|
25
25
|
def answer_inline_query(results, params = {})
|
26
26
|
params = params.merge(
|
27
27
|
inline_query_id: payload['id'],
|
@@ -30,7 +30,7 @@ module Telegram
|
|
30
30
|
bot.answer_inline_query(params)
|
31
31
|
end
|
32
32
|
|
33
|
-
# Same as
|
33
|
+
# Same as respond_with, but for callback queries.
|
34
34
|
def answer_callback_query(text, params = {})
|
35
35
|
params = params.merge(
|
36
36
|
callback_query_id: payload['id'],
|
@@ -39,6 +39,23 @@ module Telegram
|
|
39
39
|
bot.answer_callback_query(params)
|
40
40
|
end
|
41
41
|
|
42
|
+
# Same as respond_with, but for pre checkout queries.
|
43
|
+
def answer_pre_checkout_query(ok, params = {})
|
44
|
+
params = params.merge(
|
45
|
+
pre_checkout_query_id: payload['id'],
|
46
|
+
ok: ok,
|
47
|
+
)
|
48
|
+
bot.answer_pre_checkout_query(params)
|
49
|
+
end
|
50
|
+
|
51
|
+
def answer_shipping_query(ok, params = {})
|
52
|
+
params = params.merge(
|
53
|
+
shipping_query_id: payload['id'],
|
54
|
+
ok: ok,
|
55
|
+
)
|
56
|
+
bot.answer_shipping_query(params)
|
57
|
+
end
|
58
|
+
|
42
59
|
# Edit message from callback query.
|
43
60
|
def edit_message(type, params = {})
|
44
61
|
params =
|
data/lib/telegram/bot/version.rb
CHANGED
data/telegram-bot.gemspec
CHANGED
@@ -17,15 +17,12 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
|
20
|
-
spec.post_install_message = 'Breaking changes in v0.14! ' \
|
21
|
-
'See upgrade guide at https://github.com/telegram-bot-rb/telegram-bot/wiki/Upgrading-to-0.14'
|
22
|
-
|
23
20
|
spec.required_ruby_version = '~> 2.0'
|
24
21
|
|
25
|
-
spec.add_dependency 'actionpack', '>= 4.0', '< 6.
|
26
|
-
spec.add_dependency 'activesupport', '>= 4.0', '< 6.
|
22
|
+
spec.add_dependency 'actionpack', '>= 4.0', '< 6.1'
|
23
|
+
spec.add_dependency 'activesupport', '>= 4.0', '< 6.1'
|
27
24
|
spec.add_dependency 'httpclient', '~> 2.7'
|
28
25
|
|
29
|
-
spec.add_development_dependency 'bundler', '
|
30
|
-
spec.add_development_dependency 'rake', '~>
|
26
|
+
spec.add_development_dependency 'bundler', '> 1.16'
|
27
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
31
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.15.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: 2020-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '4.0'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '6.
|
22
|
+
version: '6.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '4.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '6.
|
32
|
+
version: '6.1'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: activesupport
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
version: '4.0'
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '6.
|
42
|
+
version: '6.1'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
version: '4.0'
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '6.
|
52
|
+
version: '6.1'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: httpclient
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,14 +68,14 @@ dependencies:
|
|
68
68
|
name: bundler
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
|
-
- - "
|
71
|
+
- - ">"
|
72
72
|
- !ruby/object:Gem::Version
|
73
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
80
|
version: '1.16'
|
81
81
|
- !ruby/object:Gem::Dependency
|
@@ -84,14 +84,14 @@ dependencies:
|
|
84
84
|
requirements:
|
85
85
|
- - "~>"
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version: '
|
87
|
+
version: '13.0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
90
|
version_requirements: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
92
|
- - "~>"
|
93
93
|
- !ruby/object:Gem::Version
|
94
|
-
version: '
|
94
|
+
version: '13.0'
|
95
95
|
description:
|
96
96
|
email:
|
97
97
|
- melentievm@gmail.com
|
@@ -120,12 +120,10 @@ files:
|
|
120
120
|
- gemfiles/rails_51.gemfile
|
121
121
|
- gemfiles/rails_52.gemfile
|
122
122
|
- gemfiles/rails_60.gemfile
|
123
|
+
- gemfiles/rails_61.gemfile
|
123
124
|
- lib/tasks/telegram-bot.rake
|
124
125
|
- lib/telegram/bot.rb
|
125
126
|
- lib/telegram/bot/async.rb
|
126
|
-
- lib/telegram/bot/botan.rb
|
127
|
-
- lib/telegram/bot/botan/client_helpers.rb
|
128
|
-
- lib/telegram/bot/botan/controller_helpers.rb
|
129
127
|
- lib/telegram/bot/client.rb
|
130
128
|
- lib/telegram/bot/client/api_helper.rb
|
131
129
|
- lib/telegram/bot/client/api_methods.txt
|
@@ -133,19 +131,18 @@ files:
|
|
133
131
|
- lib/telegram/bot/client_stub.rb
|
134
132
|
- lib/telegram/bot/config_methods.rb
|
135
133
|
- lib/telegram/bot/debug_client.rb
|
136
|
-
- lib/telegram/bot/initializers.rb
|
137
134
|
- lib/telegram/bot/middleware.rb
|
138
135
|
- lib/telegram/bot/railtie.rb
|
139
136
|
- lib/telegram/bot/routes_helper.rb
|
140
137
|
- lib/telegram/bot/rspec.rb
|
141
138
|
- lib/telegram/bot/rspec/callback_query_helpers.rb
|
142
139
|
- lib/telegram/bot/rspec/client_matchers.rb
|
143
|
-
- lib/telegram/bot/rspec/integration.rb
|
144
140
|
- lib/telegram/bot/rspec/integration/poller.rb
|
145
141
|
- lib/telegram/bot/rspec/integration/rack.rb
|
146
142
|
- lib/telegram/bot/rspec/integration/rails.rb
|
147
143
|
- lib/telegram/bot/rspec/integration/shared.rb
|
148
144
|
- lib/telegram/bot/rspec/message_helpers.rb
|
145
|
+
- lib/telegram/bot/tasks.rb
|
149
146
|
- lib/telegram/bot/updates_controller.rb
|
150
147
|
- lib/telegram/bot/updates_controller/callback_query_context.rb
|
151
148
|
- lib/telegram/bot/updates_controller/commands.rb
|
@@ -166,7 +163,7 @@ homepage: https://github.com/telegram-bot-rb/telegram-bot
|
|
166
163
|
licenses:
|
167
164
|
- MIT
|
168
165
|
metadata: {}
|
169
|
-
post_install_message:
|
166
|
+
post_install_message:
|
170
167
|
rdoc_options: []
|
171
168
|
require_paths:
|
172
169
|
- lib
|
@@ -181,8 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
178
|
- !ruby/object:Gem::Version
|
182
179
|
version: '0'
|
183
180
|
requirements: []
|
184
|
-
|
185
|
-
rubygems_version: 2.7.6
|
181
|
+
rubygems_version: 3.1.4
|
186
182
|
signing_key:
|
187
183
|
specification_version: 4
|
188
184
|
summary: Library for building Telegram Bots with Rails integration
|
data/lib/telegram/bot/botan.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
module Telegram
|
2
|
-
module Bot
|
3
|
-
class Botan
|
4
|
-
TRACK_URI = 'https://api.botan.io/track'.freeze
|
5
|
-
|
6
|
-
autoload :ClientHelpers, 'telegram/bot/botan/client_helpers'
|
7
|
-
autoload :ControllerHelpers, 'telegram/bot/botan/controller_helpers'
|
8
|
-
class Error < Bot::Error; end
|
9
|
-
|
10
|
-
extend Initializers
|
11
|
-
prepend Async
|
12
|
-
include DebugClient
|
13
|
-
|
14
|
-
class << self
|
15
|
-
def by_id(id)
|
16
|
-
Telegram.botans[id]
|
17
|
-
end
|
18
|
-
|
19
|
-
def prepare_async_args(method, uri, query = {}, body = nil)
|
20
|
-
[method.to_s, uri.to_s, Async.prepare_hash(query), body]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
attr_reader :client, :token
|
25
|
-
|
26
|
-
def initialize(token = nil, **options)
|
27
|
-
@client = HTTPClient.new
|
28
|
-
@token = token || options[:token]
|
29
|
-
end
|
30
|
-
|
31
|
-
def track(event, uid, payload = {})
|
32
|
-
request(:post, TRACK_URI, {name: event, uid: uid}, payload.to_json)
|
33
|
-
end
|
34
|
-
|
35
|
-
def request(method, uri, query = {}, body = nil)
|
36
|
-
res = http_request(method, uri, query.merge(token: token), body)
|
37
|
-
status = res.status
|
38
|
-
return JSON.parse(res.body) if status < 300
|
39
|
-
result = JSON.parse(res.body) rescue nil # rubocop:disable RescueModifier
|
40
|
-
err_msg = "#{res.reason}: #{result && result['info'] || '-'}"
|
41
|
-
raise Error, err_msg
|
42
|
-
end
|
43
|
-
|
44
|
-
def http_request(method, uri, query, body)
|
45
|
-
client.request(method, uri, query, body)
|
46
|
-
end
|
47
|
-
|
48
|
-
def inspect
|
49
|
-
"#<#{self.class.name}##{object_id}(#{@id})>"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Telegram
|
2
|
-
module Bot
|
3
|
-
class Botan
|
4
|
-
# Helpers for botan.io metrics.
|
5
|
-
module ClientHelpers
|
6
|
-
attr_reader :botan
|
7
|
-
|
8
|
-
def initialize(*, botan: nil, **options)
|
9
|
-
super
|
10
|
-
@botan = Botan.wrap(botan, id: id) if botan
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Telegram
|
2
|
-
module Bot
|
3
|
-
class Botan
|
4
|
-
# Helpers for botan.io metrics.
|
5
|
-
module ControllerHelpers
|
6
|
-
class MissingFrom < Error; end
|
7
|
-
|
8
|
-
protected
|
9
|
-
|
10
|
-
def botan
|
11
|
-
@botan ||= bot.try!(:botan)
|
12
|
-
end
|
13
|
-
|
14
|
-
# Track custom event for user taken from `from` field:
|
15
|
-
#
|
16
|
-
# botan_track :my_event, {data: :val}
|
17
|
-
#
|
18
|
-
def botan_track(event, data = {})
|
19
|
-
raise MissingFrom, 'Can not track without user' unless from
|
20
|
-
botan.try! { |x| x.track(event, from['id'], data) }
|
21
|
-
end
|
22
|
-
|
23
|
-
# Track current action and payload for current user. Best used with `before_action`:
|
24
|
-
#
|
25
|
-
# before_action :botan_track_action
|
26
|
-
#
|
27
|
-
def botan_track_action
|
28
|
-
botan_track(action_name, payload)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/hash/keys'
|
2
|
-
|
3
|
-
module Telegram
|
4
|
-
module Bot
|
5
|
-
module Initializers
|
6
|
-
# Accepts different options to initialize bot.
|
7
|
-
def wrap(input, **options)
|
8
|
-
case input
|
9
|
-
when Symbol then by_id(input) or raise "#{name} #{input.inspect} not configured"
|
10
|
-
when self then input
|
11
|
-
when Hash then new(**input.symbolize_keys, **options)
|
12
|
-
else new(input, **options)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def by_id(_id)
|
17
|
-
raise 'Not implemented'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
require 'telegram/bot'
|
2
|
-
Telegram::Bot.deprecation_0_15.warn(
|
3
|
-
"`require 'telegram/bot/rspec/integration'` is deprecated in favor of " \
|
4
|
-
"`require 'telegram/bot/rspec/integration/rails'`"
|
5
|
-
)
|
6
|
-
require 'telegram/bot/rspec/integration/rails'
|
7
|
-
|
8
|
-
Telegram::Bot::RSpec.with_include_context do |config|
|
9
|
-
config.include_context 'telegram/bot/integration/rails', telegram_bot: true
|
10
|
-
end
|