telegram-bot 0.14.4 → 0.15.4
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 -10
- data/Appraisals +2 -4
- data/CHANGELOG.md +24 -0
- data/Gemfile +8 -8
- data/README.md +61 -26
- data/bin/fetch-telegram-methods +1 -1
- data/gemfiles/rails_42.gemfile +7 -7
- data/gemfiles/rails_50.gemfile +7 -7
- data/gemfiles/rails_51.gemfile +7 -7
- data/gemfiles/rails_52.gemfile +7 -7
- data/gemfiles/rails_60.gemfile +7 -7
- data/gemfiles/rails_61.gemfile +9 -11
- data/lib/tasks/telegram-bot.rake +16 -9
- data/lib/telegram/bot.rb +3 -3
- data/lib/telegram/bot/client.rb +15 -4
- data/lib/telegram/bot/client/api_methods.txt +11 -3
- data/lib/telegram/bot/client_stub.rb +2 -2
- data/lib/telegram/bot/routes_helper.rb +10 -6
- data/lib/telegram/bot/tasks.rb +63 -0
- data/lib/telegram/bot/updates_controller.rb +2 -0
- data/lib/telegram/bot/updates_controller/instrumentation.rb +1 -1
- data/lib/telegram/bot/updates_controller/translation.rb +4 -4
- data/lib/telegram/bot/updates_poller.rb +1 -1
- data/lib/telegram/bot/version.rb +1 -1
- data/telegram-bot.gemspec +3 -6
- metadata +14 -15
- 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: ce64ac3361d5b02948e28ddef05bdc084ea6f6681889bda5ccd2d77e544f3a91
|
4
|
+
data.tar.gz: 02f9adbc5cb3fc0af167c7f55c7bf716a9fef3f88706339be9948e50c410d11a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b85de3de3da3f5adea3412a1642f6dbe831ed3b79d6a228eddf210c3ba6228396b9e9c69513848331d0a04261a6623487e7b1db8b5268aced95f18624225e49
|
7
|
+
data.tar.gz: 396074577bc0bbe7f7bb189408ec5134d66a44629928a95bd0fa60ec43474be60bb110f778d4de65d3d96ce4ffedd50436c88219df1198928bc4655a4c014143
|
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,13 +1,21 @@
|
|
1
|
+
os: linux
|
2
|
+
dist: xenial
|
1
3
|
language: ruby
|
2
4
|
cache: bundler
|
3
5
|
rvm:
|
4
6
|
- 2.6
|
5
7
|
- 2.5
|
6
8
|
gemfile:
|
9
|
+
- gemfiles/rails_61.gemfile
|
7
10
|
- gemfiles/rails_60.gemfile
|
8
11
|
- gemfiles/rails_52.gemfile
|
9
|
-
|
12
|
+
jobs:
|
10
13
|
include:
|
14
|
+
# ruby 3.x
|
15
|
+
- rvm: 3.0
|
16
|
+
gemfile: gemfiles/rails_61.gemfile
|
17
|
+
- rvm: 3.0
|
18
|
+
gemfile: gemfiles/rails_60.gemfile
|
11
19
|
# old rails
|
12
20
|
- rvm: 2.5
|
13
21
|
gemfile: gemfiles/rails_51.gemfile
|
@@ -18,14 +26,5 @@ matrix:
|
|
18
26
|
# old rubies
|
19
27
|
- rvm: 2.4
|
20
28
|
gemfile: gemfiles/rails_52.gemfile
|
21
|
-
- rvm: 2.3
|
22
|
-
gemfile: gemfiles/rails_52.gemfile
|
23
|
-
# future rails
|
24
|
-
- rvm: 2.5
|
25
|
-
gemfile: gemfiles/rails_61.gemfile
|
26
|
-
# Allow rails 6.1 to fail while master branch is used
|
27
|
-
allow_failures:
|
28
|
-
- rvm: 2.5
|
29
|
-
gemfile: gemfiles/rails_61.gemfile
|
30
29
|
notifications:
|
31
30
|
email: false
|
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
# Unreleased
|
2
2
|
|
3
|
+
# 0.15.4
|
4
|
+
|
5
|
+
- Update to Bot API 5.3
|
6
|
+
|
7
|
+
# 0.15.3
|
8
|
+
|
9
|
+
- Ruby 3.0 support: fix translation helpers.
|
10
|
+
|
11
|
+
# 0.15.2
|
12
|
+
|
13
|
+
- Ruby 3.0 support. Drop support for Ruby < 2.4.
|
14
|
+
|
15
|
+
# 0.15.1
|
16
|
+
|
17
|
+
- Rails 6.1 support.
|
18
|
+
|
19
|
+
# 0.15.0
|
20
|
+
|
21
|
+
- Add `:path` option to `telegram_webhook` route helper.
|
22
|
+
- __Breaking change!__ Default route is generated using hashed bot token.
|
23
|
+
Please reconfigure webhook after update (`rake telegram:bot:set_webhook`).
|
24
|
+
- Update to Bot API 5.0, add rake tasks for `deleteWebhook`, `close` & `logOut`.
|
25
|
+
- Add `server` option for client to support local bot API servers.
|
26
|
+
|
3
27
|
# 0.14.4
|
4
28
|
|
5
29
|
- Update to Bot API 4.7
|
data/Gemfile
CHANGED
@@ -4,17 +4,17 @@ gemspec
|
|
4
4
|
group :development do
|
5
5
|
gem 'appraisal', '~> 2.2'
|
6
6
|
|
7
|
-
gem 'pry', '~> 0.
|
8
|
-
gem 'pry-byebug', '~> 3.
|
9
|
-
gem 'sdoc', '~> 0.
|
7
|
+
gem 'pry', '~> 0.13.1'
|
8
|
+
gem 'pry-byebug', '~> 3.9.0'
|
9
|
+
gem 'sdoc', '~> 2.0.3'
|
10
10
|
|
11
|
-
gem 'telegram-bot-types', '~> 0.6.
|
11
|
+
gem 'telegram-bot-types', '~> 0.6.3'
|
12
12
|
|
13
|
-
gem 'rspec', '~> 3.
|
14
|
-
gem 'rspec-its', '~> 1.
|
15
|
-
gem 'rspec-rails', '~>
|
13
|
+
gem 'rspec', '~> 3.10.0'
|
14
|
+
gem 'rspec-its', '~> 1.3.0'
|
15
|
+
gem 'rspec-rails', '~> 4.0.2'
|
16
16
|
|
17
17
|
gem 'rubocop', '~> 0.52.1'
|
18
18
|
|
19
|
-
gem 'coveralls', '~> 0.8.
|
19
|
+
gem 'coveralls', '~> 0.8.23', require: false
|
20
20
|
end
|
data/README.md
CHANGED
@@ -2,9 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/telegram-bot.svg)](http://badge.fury.io/rb/telegram-bot)
|
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
|
-
[![Build Status](https://travis-ci.
|
6
|
-
|
7
|
-
__Breaking changes in v0.14!__ See [upgrade guide](https://github.com/telegram-bot-rb/telegram-bot/wiki/Upgrading-to-0.14).
|
5
|
+
[![Build Status](https://travis-ci.com/telegram-bot-rb/telegram-bot.svg)](https://travis-ci.com/telegram-bot-rb/telegram-bot)
|
8
6
|
|
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).
|
@@ -27,9 +25,33 @@ with session, keyboards and inline queries.
|
|
27
25
|
Run it on your local machine in 1 minute!
|
28
26
|
|
29
27
|
And here is [app template](https://github.com/telegram-bot-rb/rails_template)
|
30
|
-
to generate
|
31
|
-
|
32
|
-
|
28
|
+
to generate new rails app in seconds.
|
29
|
+
|
30
|
+
See examples and cookbook in [the wiki](https://github.com/telegram-bot-rb/telegram-bot/wiki).
|
31
|
+
|
32
|
+
## Table of Contents
|
33
|
+
|
34
|
+
* [Installation](#installation)
|
35
|
+
* [Usage](#usage)
|
36
|
+
* [Configuration](#configuration)
|
37
|
+
* [Configuration in Rails app](#configuration-in-rails-app)
|
38
|
+
* [Client](#client)
|
39
|
+
* [Typed responses](#typed-responses)
|
40
|
+
* [Controller](#controller)
|
41
|
+
* [Reply helpers](#reply-helpers)
|
42
|
+
* [Optional typecasting](#optional-typecasting)
|
43
|
+
* [Session](#session)
|
44
|
+
* [Message context](#message-context)
|
45
|
+
* [Callback queries](#callback-queries)
|
46
|
+
* [Routes in Rails app](#routes-in-rails-app)
|
47
|
+
* [Processing updates](#processing-updates)
|
48
|
+
* [Development & Debugging](#development--debugging)
|
49
|
+
* [Testing](#testing)
|
50
|
+
* [Deployment](#deployment)
|
51
|
+
* [Async mode](#async-mode)
|
52
|
+
* [Limitations](#limitations)
|
53
|
+
* [Development](#development)
|
54
|
+
* [Contributing](#contributing)
|
33
55
|
|
34
56
|
## Installation
|
35
57
|
|
@@ -41,11 +63,15 @@ gem 'telegram-bot'
|
|
41
63
|
|
42
64
|
And then execute:
|
43
65
|
|
44
|
-
|
66
|
+
```
|
67
|
+
bundle
|
68
|
+
```
|
45
69
|
|
46
70
|
Or install it yourself as:
|
47
71
|
|
48
|
-
|
72
|
+
```
|
73
|
+
gem install telegram-bot
|
74
|
+
```
|
49
75
|
|
50
76
|
Require if necessary:
|
51
77
|
|
@@ -65,7 +91,11 @@ which is used for `Telegram.bot`.
|
|
65
91
|
```ruby
|
66
92
|
Telegram.bots_config = {
|
67
93
|
default: DEFAULT_BOT_TOKEN,
|
68
|
-
chat: {
|
94
|
+
chat: {
|
95
|
+
token: CHAT_BOT_TOKEN,
|
96
|
+
username: 'ChatBot', # to support commands with mentions (/help@ChatBot)
|
97
|
+
server: 'http://local.bot.api.server', # for Local Bot API Server
|
98
|
+
},
|
69
99
|
}
|
70
100
|
|
71
101
|
Telegram.bot.get_updates
|
@@ -87,6 +117,7 @@ development:
|
|
87
117
|
bot:
|
88
118
|
token: TOKEN
|
89
119
|
username: SomeBot
|
120
|
+
server: http://local.bot.api.server
|
90
121
|
|
91
122
|
# For multiple bots in single app use hash of `internal_bot_id => settings`
|
92
123
|
bots:
|
@@ -128,9 +159,9 @@ bot.send_message(chat_id: chat_id, text: 'Test')
|
|
128
159
|
```
|
129
160
|
|
130
161
|
There is no magic, they just pass params as is and set `path_suffix`.
|
131
|
-
See [
|
132
|
-
|
133
|
-
new API versions.
|
162
|
+
See [list of available methods](https://github.com/telegram-bot-rb/telegram-bot/blob/master/lib/telegram/bot/client/api_methods.txt)
|
163
|
+
fetched from [API docs](https://core.telegram.org/bots/api).
|
164
|
+
Please open PR or issue if it misses methods from new API versions.
|
134
165
|
|
135
166
|
Any API request error will raise `Telegram::Bot::Error` with description in its message.
|
136
167
|
Special `Telegram::Bot::Forbidden` is raised when bot can't post messages to the chat anymore.
|
@@ -167,19 +198,18 @@ Bot controllers like usual rails controllers provides features like callbacks,
|
|
167
198
|
|
168
199
|
```ruby
|
169
200
|
class Telegram::WebhookController < Telegram::Bot::UpdatesController
|
170
|
-
# use callbacks like in any other
|
201
|
+
# use callbacks like in any other controller
|
171
202
|
around_action :with_locale
|
172
203
|
|
173
|
-
# Every update
|
204
|
+
# Every update has one of: message, inline_query, chosen_inline_result,
|
174
205
|
# callback_query, etc.
|
175
|
-
# Define method with same name to
|
206
|
+
# Define method with the same name to handle this type of update.
|
176
207
|
def message(message)
|
177
|
-
# message can be also accessed via instance method
|
178
|
-
message == self.payload # true
|
179
208
|
# store_message(message['text'])
|
180
209
|
end
|
181
210
|
|
182
|
-
#
|
211
|
+
# For the following types of updates commonly used params are passed as arguments,
|
212
|
+
# full payload object is available with `payload` instance method.
|
183
213
|
#
|
184
214
|
# message(payload)
|
185
215
|
# inline_query(query, offset)
|
@@ -190,14 +220,19 @@ class Telegram::WebhookController < Telegram::Bot::UpdatesController
|
|
190
220
|
# Command arguments will be parsed and passed to the method.
|
191
221
|
# Be sure to use splat args and default values to not get errors when
|
192
222
|
# someone passed more or less arguments in the message.
|
193
|
-
def start!(
|
194
|
-
# do_smth_with(
|
223
|
+
def start!(word = nil, *other_words)
|
224
|
+
# do_smth_with(word)
|
225
|
+
|
226
|
+
# full message object is also available via `payload` instance method:
|
227
|
+
# process_raw_message(payload['text'])
|
195
228
|
|
196
229
|
# There are `chat` & `from` shortcut methods.
|
197
|
-
# For callback queries `chat`
|
230
|
+
# For callback queries `chat` is taken from `message` when it's available.
|
198
231
|
response = from ? "Hello #{from['username']}!" : 'Hi there!'
|
232
|
+
|
199
233
|
# There is `respond_with` helper to set `chat_id` from received message:
|
200
234
|
respond_with :message, text: response
|
235
|
+
|
201
236
|
# `reply_with` also sets `reply_to_message_id`:
|
202
237
|
reply_with :photo, photo: File.open('party.jpg')
|
203
238
|
end
|
@@ -220,10 +255,10 @@ end
|
|
220
255
|
|
221
256
|
#### Reply helpers
|
222
257
|
|
223
|
-
There are helpers
|
224
|
-
identifiers from update. See
|
258
|
+
There are helpers for basic responses. They just set chat/message/query
|
259
|
+
identifiers from the update. See
|
225
260
|
[`ReplyHelpers`](https://github.com/telegram-bot-rb/telegram-bot/blob/master/lib/telegram/bot/updates_controller/reply_helpers.rb)
|
226
|
-
module for more information. Here are
|
261
|
+
module for more information. Here are these methods signatures:
|
227
262
|
|
228
263
|
```ruby
|
229
264
|
def respond_with(type, params); end
|
@@ -366,7 +401,7 @@ end
|
|
366
401
|
### Routes in Rails app
|
367
402
|
|
368
403
|
There is `telegram_webhook` helper for rails app to define routes for webhooks.
|
369
|
-
It defines routes at `telegram/#{bot.token}` and connects bots with controller.
|
404
|
+
It defines routes at `telegram/#{hash_of(bot.token)}` and connects bots with controller.
|
370
405
|
|
371
406
|
```ruby
|
372
407
|
# Most off apps would require
|
@@ -386,7 +421,7 @@ telegram_webhook TelegramAuctionController, :auction
|
|
386
421
|
telegram_webhook TelegramController, as: :custom_telegram_webhook
|
387
422
|
```
|
388
423
|
|
389
|
-
####
|
424
|
+
#### Processing updates
|
390
425
|
|
391
426
|
To process update with controller call `.dispatch(bot, update)` on it.
|
392
427
|
There are several options to run it automatically:
|
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
@@ -7,15 +7,15 @@ gem "railties", "~> 4.2.0"
|
|
7
7
|
|
8
8
|
group :development do
|
9
9
|
gem "appraisal", "~> 2.2"
|
10
|
-
gem "pry", "~> 0.
|
11
|
-
gem "pry-byebug", "~> 3.
|
12
|
-
gem "sdoc", "~> 0.
|
10
|
+
gem "pry", "~> 0.13.1"
|
11
|
+
gem "pry-byebug", "~> 3.9.0"
|
12
|
+
gem "sdoc", "~> 2.0.3"
|
13
13
|
gem "telegram-bot-types", "~> 0.6.2"
|
14
|
-
gem "rspec", "~> 3.
|
15
|
-
gem "rspec-its", "~> 1.
|
16
|
-
gem "rspec-rails", "~>
|
14
|
+
gem "rspec", "~> 3.10.0"
|
15
|
+
gem "rspec-its", "~> 1.3.0"
|
16
|
+
gem "rspec-rails", "~> 4.0.2"
|
17
17
|
gem "rubocop", "~> 0.52.1"
|
18
|
-
gem "coveralls", "~> 0.8.
|
18
|
+
gem "coveralls", "~> 0.8.23", require: false
|
19
19
|
end
|
20
20
|
|
21
21
|
gemspec path: "../"
|
data/gemfiles/rails_50.gemfile
CHANGED
@@ -7,15 +7,15 @@ gem "railties", "~> 5.0.0"
|
|
7
7
|
|
8
8
|
group :development do
|
9
9
|
gem "appraisal", "~> 2.2"
|
10
|
-
gem "pry", "~> 0.
|
11
|
-
gem "pry-byebug", "~> 3.
|
12
|
-
gem "sdoc", "~> 0.
|
10
|
+
gem "pry", "~> 0.13.1"
|
11
|
+
gem "pry-byebug", "~> 3.9.0"
|
12
|
+
gem "sdoc", "~> 2.0.3"
|
13
13
|
gem "telegram-bot-types", "~> 0.6.2"
|
14
|
-
gem "rspec", "~> 3.
|
15
|
-
gem "rspec-its", "~> 1.
|
16
|
-
gem "rspec-rails", "~>
|
14
|
+
gem "rspec", "~> 3.10.0"
|
15
|
+
gem "rspec-its", "~> 1.3.0"
|
16
|
+
gem "rspec-rails", "~> 4.0.2"
|
17
17
|
gem "rubocop", "~> 0.52.1"
|
18
|
-
gem "coveralls", "~> 0.8.
|
18
|
+
gem "coveralls", "~> 0.8.23", require: false
|
19
19
|
end
|
20
20
|
|
21
21
|
gemspec path: "../"
|
data/gemfiles/rails_51.gemfile
CHANGED
@@ -7,15 +7,15 @@ gem "railties", "~> 5.1.0"
|
|
7
7
|
|
8
8
|
group :development do
|
9
9
|
gem "appraisal", "~> 2.2"
|
10
|
-
gem "pry", "~> 0.
|
11
|
-
gem "pry-byebug", "~> 3.
|
12
|
-
gem "sdoc", "~> 0.
|
10
|
+
gem "pry", "~> 0.13.1"
|
11
|
+
gem "pry-byebug", "~> 3.9.0"
|
12
|
+
gem "sdoc", "~> 2.0.3"
|
13
13
|
gem "telegram-bot-types", "~> 0.6.2"
|
14
|
-
gem "rspec", "~> 3.
|
15
|
-
gem "rspec-its", "~> 1.
|
16
|
-
gem "rspec-rails", "~>
|
14
|
+
gem "rspec", "~> 3.10.0"
|
15
|
+
gem "rspec-its", "~> 1.3.0"
|
16
|
+
gem "rspec-rails", "~> 4.0.2"
|
17
17
|
gem "rubocop", "~> 0.52.1"
|
18
|
-
gem "coveralls", "~> 0.8.
|
18
|
+
gem "coveralls", "~> 0.8.23", require: false
|
19
19
|
end
|
20
20
|
|
21
21
|
gemspec path: "../"
|
data/gemfiles/rails_52.gemfile
CHANGED
@@ -7,15 +7,15 @@ gem "railties", "~> 5.2.0"
|
|
7
7
|
|
8
8
|
group :development do
|
9
9
|
gem "appraisal", "~> 2.2"
|
10
|
-
gem "pry", "~> 0.
|
11
|
-
gem "pry-byebug", "~> 3.
|
12
|
-
gem "sdoc", "~> 0.
|
10
|
+
gem "pry", "~> 0.13.1"
|
11
|
+
gem "pry-byebug", "~> 3.9.0"
|
12
|
+
gem "sdoc", "~> 2.0.3"
|
13
13
|
gem "telegram-bot-types", "~> 0.6.2"
|
14
|
-
gem "rspec", "~> 3.
|
15
|
-
gem "rspec-its", "~> 1.
|
16
|
-
gem "rspec-rails", "~>
|
14
|
+
gem "rspec", "~> 3.10.0"
|
15
|
+
gem "rspec-its", "~> 1.3.0"
|
16
|
+
gem "rspec-rails", "~> 4.0.2"
|
17
17
|
gem "rubocop", "~> 0.52.1"
|
18
|
-
gem "coveralls", "~> 0.8.
|
18
|
+
gem "coveralls", "~> 0.8.23", require: false
|
19
19
|
end
|
20
20
|
|
21
21
|
gemspec path: "../"
|
data/gemfiles/rails_60.gemfile
CHANGED
@@ -7,15 +7,15 @@ gem "railties", "~> 6.0.0"
|
|
7
7
|
|
8
8
|
group :development do
|
9
9
|
gem "appraisal", "~> 2.2"
|
10
|
-
gem "pry", "~> 0.
|
11
|
-
gem "pry-byebug", "~> 3.
|
12
|
-
gem "sdoc", "~> 0.
|
10
|
+
gem "pry", "~> 0.13.1"
|
11
|
+
gem "pry-byebug", "~> 3.9.0"
|
12
|
+
gem "sdoc", "~> 2.0.3"
|
13
13
|
gem "telegram-bot-types", "~> 0.6.2"
|
14
|
-
gem "rspec", "~> 3.
|
15
|
-
gem "rspec-its", "~> 1.
|
16
|
-
gem "rspec-rails", "~>
|
14
|
+
gem "rspec", "~> 3.10.0"
|
15
|
+
gem "rspec-its", "~> 1.3.0"
|
16
|
+
gem "rspec-rails", "~> 4.0.2"
|
17
17
|
gem "rubocop", "~> 0.52.1"
|
18
|
-
gem "coveralls", "~> 0.8.
|
18
|
+
gem "coveralls", "~> 0.8.23", require: false
|
19
19
|
end
|
20
20
|
|
21
21
|
gemspec path: "../"
|
data/gemfiles/rails_61.gemfile
CHANGED
@@ -2,22 +2,20 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
gem "railties", "~> 6.1.0.alpha"
|
8
|
-
end
|
5
|
+
gem "actionpack", "~> 6.1.0"
|
6
|
+
gem "railties", "~> 6.1.0"
|
9
7
|
|
10
8
|
group :development do
|
11
9
|
gem "appraisal", "~> 2.2"
|
12
|
-
gem "pry", "~> 0.
|
13
|
-
gem "pry-byebug", "~> 3.
|
14
|
-
gem "sdoc", "~> 0.
|
10
|
+
gem "pry", "~> 0.13.1"
|
11
|
+
gem "pry-byebug", "~> 3.9.0"
|
12
|
+
gem "sdoc", "~> 2.0.3"
|
15
13
|
gem "telegram-bot-types", "~> 0.6.2"
|
16
|
-
gem "rspec", "~> 3.
|
17
|
-
gem "rspec-its", "~> 1.
|
18
|
-
gem "rspec-rails", "~>
|
14
|
+
gem "rspec", "~> 3.10.0"
|
15
|
+
gem "rspec-its", "~> 1.3.0"
|
16
|
+
gem "rspec-rails", "~> 4.0.2"
|
19
17
|
gem "rubocop", "~> 0.52.1"
|
20
|
-
gem "coveralls", "~> 0.8.
|
18
|
+
gem "coveralls", "~> 0.8.23", require: false
|
21
19
|
end
|
22
20
|
|
23
21
|
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,10 +14,10 @@ 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
|
|
@@ -25,9 +25,9 @@ module Telegram
|
|
25
25
|
autoload :Client, 'telegram/bot/client'
|
26
26
|
autoload :ClientStub, 'telegram/bot/client_stub'
|
27
27
|
autoload :DebugClient, 'telegram/bot/debug_client'
|
28
|
-
autoload :Initializers, 'telegram/bot/initializers'
|
29
28
|
autoload :Middleware, 'telegram/bot/middleware'
|
30
29
|
autoload :RSpec, 'telegram/bot/rspec'
|
30
|
+
autoload :Tasks, 'telegram/bot/tasks'
|
31
31
|
autoload :UpdatesController, 'telegram/bot/updates_controller'
|
32
32
|
autoload :UpdatesPoller, 'telegram/bot/updates_poller'
|
33
33
|
end
|
data/lib/telegram/bot/client.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
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
13
|
include DebugClient
|
13
14
|
|
@@ -15,6 +16,16 @@ module Telegram
|
|
15
16
|
include ApiHelper
|
16
17
|
|
17
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
|
+
|
18
29
|
def by_id(id)
|
19
30
|
Telegram.bots[id]
|
20
31
|
end
|
@@ -51,11 +62,11 @@ module Telegram
|
|
51
62
|
|
52
63
|
attr_reader :client, :token, :username, :base_uri
|
53
64
|
|
54
|
-
def initialize(token = nil, username = nil, **options)
|
65
|
+
def initialize(token = nil, username = nil, server: SERVER, **options)
|
55
66
|
@client = HTTPClient.new
|
56
67
|
@token = token || options[:token]
|
57
68
|
@username = username || options[:username]
|
58
|
-
@base_uri = format(URL_TEMPLATE, token: self.token)
|
69
|
+
@base_uri = format(URL_TEMPLATE, server: server, token: self.token)
|
59
70
|
end
|
60
71
|
|
61
72
|
def request(action, body = {})
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Generated with bin/fetch-telegram-methods
|
2
|
-
# Bot API
|
2
|
+
# Bot API 5.3
|
3
3
|
|
4
4
|
getUpdates
|
5
5
|
setWebhook
|
@@ -7,8 +7,11 @@ 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
|
@@ -27,28 +30,33 @@ sendDice
|
|
27
30
|
sendChatAction
|
28
31
|
getUserProfilePhotos
|
29
32
|
getFile
|
30
|
-
|
33
|
+
banChatMember
|
31
34
|
unbanChatMember
|
32
35
|
restrictChatMember
|
33
36
|
promoteChatMember
|
34
37
|
setChatAdministratorCustomTitle
|
35
38
|
setChatPermissions
|
36
39
|
exportChatInviteLink
|
40
|
+
createChatInviteLink
|
41
|
+
editChatInviteLink
|
42
|
+
revokeChatInviteLink
|
37
43
|
setChatPhoto
|
38
44
|
deleteChatPhoto
|
39
45
|
setChatTitle
|
40
46
|
setChatDescription
|
41
47
|
pinChatMessage
|
42
48
|
unpinChatMessage
|
49
|
+
unpinAllChatMessages
|
43
50
|
leaveChat
|
44
51
|
getChat
|
45
52
|
getChatAdministrators
|
46
|
-
|
53
|
+
getChatMemberCount
|
47
54
|
getChatMember
|
48
55
|
setChatStickerSet
|
49
56
|
deleteChatStickerSet
|
50
57
|
answerCallbackQuery
|
51
58
|
setMyCommands
|
59
|
+
deleteMyCommands
|
52
60
|
getMyCommands
|
53
61
|
|
54
62
|
editMessageText
|
@@ -5,11 +5,11 @@ module Telegram
|
|
5
5
|
attr_reader :requests
|
6
6
|
|
7
7
|
module StubbedConstructor
|
8
|
-
def new(*args)
|
8
|
+
def new(*args, **kwargs)
|
9
9
|
if self == ClientStub || !ClientStub.stub_all?
|
10
10
|
super
|
11
11
|
else
|
12
|
-
ClientStub.new(*args)
|
12
|
+
ClientStub.new(*args, **kwargs)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
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
|
@@ -12,15 +12,15 @@ module Telegram
|
|
12
12
|
|
13
13
|
module ClassMethods
|
14
14
|
# Class-level helper for lazy translations.
|
15
|
-
def translate(key, options
|
15
|
+
def translate(key, **options)
|
16
16
|
key = "#{controller_path.tr('/', '.')}#{key}" if key.to_s.start_with?('.')
|
17
|
-
I18n.translate(key, options)
|
17
|
+
I18n.translate(key, **options)
|
18
18
|
end
|
19
19
|
alias :t :translate
|
20
20
|
end
|
21
21
|
|
22
22
|
# See toplevel description.
|
23
|
-
def translate(key, options
|
23
|
+
def translate(key, **options)
|
24
24
|
if key.to_s.start_with?('.')
|
25
25
|
path = controller_path.tr('/', '.')
|
26
26
|
defaults = [:"#{path}#{key}"]
|
@@ -28,7 +28,7 @@ module Telegram
|
|
28
28
|
options[:default] = defaults.flatten
|
29
29
|
key = "#{path}.#{action_name_i18n_key}#{key}"
|
30
30
|
end
|
31
|
-
I18n.translate(key, options)
|
31
|
+
I18n.translate(key, **options)
|
32
32
|
end
|
33
33
|
alias :t :translate
|
34
34
|
|
data/lib/telegram/bot/version.rb
CHANGED
data/telegram-bot.gemspec
CHANGED
@@ -17,13 +17,10 @@ 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.
|
21
|
-
'See upgrade guide at https://github.com/telegram-bot-rb/telegram-bot/wiki/Upgrading-to-0.14'
|
20
|
+
spec.required_ruby_version = '>= 2.4'
|
22
21
|
|
23
|
-
spec.
|
24
|
-
|
25
|
-
spec.add_dependency 'actionpack', '>= 4.0', '< 6.1'
|
26
|
-
spec.add_dependency 'activesupport', '>= 4.0', '< 6.1'
|
22
|
+
spec.add_dependency 'actionpack', '>= 4.0', '< 6.2'
|
23
|
+
spec.add_dependency 'activesupport', '>= 4.0', '< 6.2'
|
27
24
|
spec.add_dependency 'httpclient', '~> 2.7'
|
28
25
|
|
29
26
|
spec.add_development_dependency 'bundler', '> 1.16'
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Melentiev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-25 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.2'
|
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.2'
|
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.2'
|
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.2'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: httpclient
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,7 +92,7 @@ dependencies:
|
|
92
92
|
- - "~>"
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '13.0'
|
95
|
-
description:
|
95
|
+
description:
|
96
96
|
email:
|
97
97
|
- melentievm@gmail.com
|
98
98
|
executables: []
|
@@ -131,19 +131,18 @@ files:
|
|
131
131
|
- lib/telegram/bot/client_stub.rb
|
132
132
|
- lib/telegram/bot/config_methods.rb
|
133
133
|
- lib/telegram/bot/debug_client.rb
|
134
|
-
- lib/telegram/bot/initializers.rb
|
135
134
|
- lib/telegram/bot/middleware.rb
|
136
135
|
- lib/telegram/bot/railtie.rb
|
137
136
|
- lib/telegram/bot/routes_helper.rb
|
138
137
|
- lib/telegram/bot/rspec.rb
|
139
138
|
- lib/telegram/bot/rspec/callback_query_helpers.rb
|
140
139
|
- lib/telegram/bot/rspec/client_matchers.rb
|
141
|
-
- lib/telegram/bot/rspec/integration.rb
|
142
140
|
- lib/telegram/bot/rspec/integration/poller.rb
|
143
141
|
- lib/telegram/bot/rspec/integration/rack.rb
|
144
142
|
- lib/telegram/bot/rspec/integration/rails.rb
|
145
143
|
- lib/telegram/bot/rspec/integration/shared.rb
|
146
144
|
- lib/telegram/bot/rspec/message_helpers.rb
|
145
|
+
- lib/telegram/bot/tasks.rb
|
147
146
|
- lib/telegram/bot/updates_controller.rb
|
148
147
|
- lib/telegram/bot/updates_controller/callback_query_context.rb
|
149
148
|
- lib/telegram/bot/updates_controller/commands.rb
|
@@ -164,23 +163,23 @@ homepage: https://github.com/telegram-bot-rb/telegram-bot
|
|
164
163
|
licenses:
|
165
164
|
- MIT
|
166
165
|
metadata: {}
|
167
|
-
post_install_message:
|
166
|
+
post_install_message:
|
168
167
|
rdoc_options: []
|
169
168
|
require_paths:
|
170
169
|
- lib
|
171
170
|
required_ruby_version: !ruby/object:Gem::Requirement
|
172
171
|
requirements:
|
173
|
-
- - "
|
172
|
+
- - ">="
|
174
173
|
- !ruby/object:Gem::Version
|
175
|
-
version: '2.
|
174
|
+
version: '2.4'
|
176
175
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
176
|
requirements:
|
178
177
|
- - ">="
|
179
178
|
- !ruby/object:Gem::Version
|
180
179
|
version: '0'
|
181
180
|
requirements: []
|
182
|
-
rubygems_version: 3.
|
183
|
-
signing_key:
|
181
|
+
rubygems_version: 3.1.4
|
182
|
+
signing_key:
|
184
183
|
specification_version: 4
|
185
184
|
summary: Library for building Telegram Bots with Rails integration
|
186
185
|
test_files: []
|
@@ -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
|