telegram-bot 0.16.1 → 0.16.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +0 -4
- data/.github/workflows/ci.yml +9 -9
- data/.rubocop.yml +31 -12
- data/Appraisals +2 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +5 -3
- data/Rakefile +2 -0
- data/bin/console +6 -2
- data/bin/fetch-telegram-methods +5 -3
- data/bin/install_git_hooks +2 -1
- data/gemfiles/rails_51.gemfile +3 -3
- data/gemfiles/rails_52.gemfile +3 -3
- data/gemfiles/rails_60.gemfile +3 -3
- data/gemfiles/rails_61.gemfile +3 -3
- data/gemfiles/rails_70.gemfile +3 -3
- data/gemfiles/rails_71.gemfile +3 -3
- data/lib/tasks/telegram-bot.rake +6 -4
- data/lib/telegram/bot/async.rb +4 -2
- data/lib/telegram/bot/client/api_helper.rb +3 -1
- data/lib/telegram/bot/client/api_methods.txt +8 -1
- data/lib/telegram/bot/client/request_body_formatter.rb +2 -0
- data/lib/telegram/bot/client/typed_response.rb +2 -0
- data/lib/telegram/bot/client.rb +5 -3
- data/lib/telegram/bot/client_stub.rb +4 -2
- data/lib/telegram/bot/config_methods.rb +3 -1
- data/lib/telegram/bot/debug_client.rb +3 -1
- data/lib/telegram/bot/middleware.rb +3 -1
- data/lib/telegram/bot/railtie.rb +3 -1
- data/lib/telegram/bot/routes_helper.rb +2 -0
- data/lib/telegram/bot/rspec/callback_query_helpers.rb +3 -1
- data/lib/telegram/bot/rspec/client_matchers.rb +12 -10
- data/lib/telegram/bot/rspec/integration/poller.rb +2 -0
- data/lib/telegram/bot/rspec/integration/rack.rb +2 -0
- data/lib/telegram/bot/rspec/integration/rails.rb +2 -0
- data/lib/telegram/bot/rspec/integration/shared.rb +3 -1
- data/lib/telegram/bot/rspec/message_helpers.rb +2 -0
- data/lib/telegram/bot/rspec.rb +2 -0
- data/lib/telegram/bot/tasks.rb +4 -4
- data/lib/telegram/bot/updates_controller/callback_query_context.rb +2 -0
- data/lib/telegram/bot/updates_controller/commands.rb +4 -2
- data/lib/telegram/bot/updates_controller/instrumentation.rb +7 -5
- data/lib/telegram/bot/updates_controller/log_subscriber.rb +4 -2
- data/lib/telegram/bot/updates_controller/message_context.rb +7 -5
- data/lib/telegram/bot/updates_controller/reply_helpers.rb +4 -2
- data/lib/telegram/bot/updates_controller/rescue.rb +3 -1
- data/lib/telegram/bot/updates_controller/rspec_helpers.rb +2 -0
- data/lib/telegram/bot/updates_controller/session.rb +7 -4
- data/lib/telegram/bot/updates_controller/testing.rb +5 -2
- data/lib/telegram/bot/updates_controller/translation.rb +2 -0
- data/lib/telegram/bot/updates_controller/typed_update.rb +2 -0
- data/lib/telegram/bot/updates_controller.rb +49 -19
- data/lib/telegram/bot/updates_poller.rb +9 -9
- data/lib/telegram/bot/version.rb +3 -1
- data/lib/telegram/bot.rb +3 -9
- data/telegram-bot.gemspec +7 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61a22f62815ac892095b9a544fa1ce2cf2273f9e3c1d6bbe371b7a548e1f8762
|
4
|
+
data.tar.gz: 5b80eb16b7bd5bef68a4dcbf5a30cda40d1aaba95774930f9d78000dec3db624
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cbf0d110b678071dae96a0cabb0ac6142089c5482f25906a0684ba904c348300c48422c9254884025ccab214ce7487fad852b7d22ba696384937155b4030896
|
7
|
+
data.tar.gz: 54f32643648797d54ac815f989bc2902faee6ed17357e69d83fcbbfe17640ddcc3b669b83fd16e54ab72574cecccc40b03161f716340552851f017711d3bf68f
|
data/.codeclimate.yml
CHANGED
data/.github/workflows/ci.yml
CHANGED
@@ -3,15 +3,15 @@ name: Lint & Test
|
|
3
3
|
on: [push, pull_request]
|
4
4
|
|
5
5
|
jobs:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
lint:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v3
|
10
|
+
- uses: ruby/setup-ruby@v1
|
11
|
+
with:
|
12
|
+
ruby-version: '3.2'
|
13
|
+
bundler-cache: true
|
14
|
+
- run: bundle exec rubocop
|
15
15
|
|
16
16
|
test:
|
17
17
|
runs-on: ubuntu-latest
|
data/.rubocop.yml
CHANGED
@@ -1,15 +1,18 @@
|
|
1
|
-
|
2
|
-
Gemspec/RequiredRubyVersion: {Enabled: false}
|
1
|
+
require: rubocop-rails
|
3
2
|
|
4
|
-
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.4
|
5
|
+
NewCops: enable
|
6
|
+
SuggestExtensions: false
|
7
|
+
Exclude:
|
8
|
+
- gemfiles/*
|
9
|
+
- tmp/*
|
10
|
+
- vendor/**/* # for github actions
|
5
11
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
# EnforcedStyle:
|
11
|
-
# - with_first_parameter
|
12
|
-
# - with_fixed_indentation
|
12
|
+
Gemspec/DevelopmentDependencies: {Enabled: false}
|
13
|
+
|
14
|
+
Layout/ArgumentAlignment: {EnforcedStyle: with_fixed_indentation}
|
15
|
+
Layout/ParameterAlignment: {EnforcedStyle: with_fixed_indentation}
|
13
16
|
|
14
17
|
# Breaks
|
15
18
|
#
|
@@ -19,7 +22,11 @@ Layout/AlignParameters:
|
|
19
22
|
# )
|
20
23
|
Layout/ClosingParenthesisIndentation: {Enabled: false}
|
21
24
|
Layout/DotPosition: {EnforcedStyle: trailing}
|
25
|
+
Layout/EmptyLineAfterGuardClause: {Enabled: false}
|
22
26
|
Layout/FirstParameterIndentation: {EnforcedStyle: consistent}
|
27
|
+
Layout/LineContinuationLeadingSpace: {Enabled: false}
|
28
|
+
Layout/LineEndStringConcatenationIndentation: {EnforcedStyle: indented}
|
29
|
+
Layout/LineLength: {Max: 100}
|
23
30
|
# Same as Layout/ClosingParenthesisIndentation
|
24
31
|
Layout/MultilineMethodCallBraceLayout: {Enabled: false}
|
25
32
|
Layout/MultilineMethodCallIndentation: {EnforcedStyle: indented}
|
@@ -28,8 +35,16 @@ Layout/SpaceInsideHashLiteralBraces: {EnforcedStyle: no_space}
|
|
28
35
|
|
29
36
|
# Offences named scopes and `expect {}.to change {}`.
|
30
37
|
Lint/AmbiguousBlockAssociation: {Enabled: false}
|
38
|
+
Lint/EmptyBlock:
|
39
|
+
Exclude:
|
40
|
+
- spec/**/*
|
31
41
|
|
42
|
+
Naming/FileName:
|
43
|
+
Exclude:
|
44
|
+
- lib/tasks/telegram-bot.rake
|
45
|
+
Naming/MethodParameterName: {MinNameLength: 2}
|
32
46
|
Naming/PredicateName: {Enabled: false}
|
47
|
+
Naming/RescuedExceptionsVariableName: {PreferredName: exception}
|
33
48
|
Naming/VariableNumber: {EnforcedStyle: snake_case}
|
34
49
|
|
35
50
|
Style/Alias: {Enabled: false}
|
@@ -45,12 +60,16 @@ Style/ModuleFunction: {Enabled: false}
|
|
45
60
|
Style/NestedParenthesizedCalls: {Enabled: false}
|
46
61
|
Style/SignalException: {EnforcedStyle: only_raise}
|
47
62
|
Style/TrailingCommaInArguments: {Enabled: false}
|
48
|
-
Style/
|
63
|
+
Style/TrailingCommaInArrayLiteral: {EnforcedStyleForMultiline: comma}
|
64
|
+
Style/TrailingCommaInHashLiteral: {EnforcedStyleForMultiline: comma}
|
49
65
|
|
50
66
|
Metrics/AbcSize: {Max: 21}
|
51
67
|
# Other metrics are just enough.
|
52
68
|
# This one offences all specs, routes and some initializers.
|
53
69
|
Metrics/BlockLength: {Enabled: false}
|
54
|
-
Metrics/LineLength: {Max: 100}
|
55
70
|
Metrics/MethodLength: {Max: 30}
|
56
71
|
Metrics/CyclomaticComplexity: {Max: 8}
|
72
|
+
|
73
|
+
Rails/IndexWith: {Enabled: false}
|
74
|
+
Rails/RakeEnvironment: {Enabled: false}
|
75
|
+
Rails/ShortI18n: {Enabled: false}
|
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
gemspec
|
3
5
|
|
4
6
|
group :development do
|
5
7
|
gem 'appraisal', '~> 2.2'
|
6
8
|
|
7
|
-
gem '
|
8
|
-
gem 'pry-byebug', '~> 3.10.1'
|
9
|
+
gem 'debug', '~> 1.9.2'
|
9
10
|
gem 'sdoc', '~> 2.0.3'
|
10
11
|
|
11
12
|
gem 'telegram-bot-types', '~> 0.6.3'
|
@@ -14,7 +15,8 @@ group :development do
|
|
14
15
|
gem 'rspec-its', '~> 1.3.0'
|
15
16
|
gem 'rspec-rails', '~> 4.0.2'
|
16
17
|
|
17
|
-
gem 'rubocop', '~>
|
18
|
+
gem 'rubocop', '~> 1.59.0'
|
19
|
+
gem 'rubocop-rails', '~> 2.23.1'
|
18
20
|
|
19
21
|
gem 'coveralls', '~> 0.8.23', require: false
|
20
22
|
end
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/bin/fetch-telegram-methods
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
#
|
3
5
|
# Fetch list of methods from Telegram docs.
|
4
6
|
# Use it to update client.rb.
|
@@ -6,7 +8,7 @@
|
|
6
8
|
require 'net/http'
|
7
9
|
require 'nokogiri'
|
8
10
|
|
9
|
-
DOCS_URL = 'https://core.telegram.org/bots/api'
|
11
|
+
DOCS_URL = 'https://core.telegram.org/bots/api'
|
10
12
|
|
11
13
|
page_html = Net::HTTP.get(URI(DOCS_URL))
|
12
14
|
doc = Nokogiri::HTML(page_html)
|
@@ -18,11 +20,11 @@ headers = doc.css('h3, h4').
|
|
18
20
|
map { |g| g.map(&:text) }
|
19
21
|
|
20
22
|
# Method starts with lowercase and does not have spaces.
|
21
|
-
NOT_METHOD_REGEXP = /(\A[^a-z])|\s
|
23
|
+
NOT_METHOD_REGEXP = /(\A[^a-z])|\s/.freeze
|
22
24
|
|
23
25
|
# Filter method names.
|
24
26
|
method_list = headers.
|
25
|
-
map { |g| g.
|
27
|
+
map { |g| g.grep_v(NOT_METHOD_REGEXP) }.
|
26
28
|
reject(&:empty?)
|
27
29
|
|
28
30
|
api_version = doc.text.match(/^(?:Introducing )?(Bot API ([\d\.]+))\.?$/)
|
data/bin/install_git_hooks
CHANGED
data/gemfiles/rails_51.gemfile
CHANGED
@@ -7,14 +7,14 @@ gem "railties", "~> 5.1.0"
|
|
7
7
|
|
8
8
|
group :development do
|
9
9
|
gem "appraisal", "~> 2.2"
|
10
|
-
gem "
|
11
|
-
gem "pry-byebug", "~> 3.10.1"
|
10
|
+
gem "debug", "~> 1.9.2"
|
12
11
|
gem "sdoc", "~> 2.0.3"
|
13
12
|
gem "telegram-bot-types", "~> 0.6.3"
|
14
13
|
gem "rspec", "~> 3.12.0"
|
15
14
|
gem "rspec-its", "~> 1.3.0"
|
16
15
|
gem "rspec-rails", "~> 4.0.2"
|
17
|
-
gem "rubocop", "~>
|
16
|
+
gem "rubocop", "~> 1.59.0"
|
17
|
+
gem "rubocop-rails", "~> 2.23.1"
|
18
18
|
gem "coveralls", "~> 0.8.23", require: false
|
19
19
|
end
|
20
20
|
|
data/gemfiles/rails_52.gemfile
CHANGED
@@ -7,14 +7,14 @@ gem "railties", "~> 5.2.0"
|
|
7
7
|
|
8
8
|
group :development do
|
9
9
|
gem "appraisal", "~> 2.2"
|
10
|
-
gem "
|
11
|
-
gem "pry-byebug", "~> 3.10.1"
|
10
|
+
gem "debug", "~> 1.9.2"
|
12
11
|
gem "sdoc", "~> 2.0.3"
|
13
12
|
gem "telegram-bot-types", "~> 0.6.3"
|
14
13
|
gem "rspec", "~> 3.12.0"
|
15
14
|
gem "rspec-its", "~> 1.3.0"
|
16
15
|
gem "rspec-rails", "~> 4.0.2"
|
17
|
-
gem "rubocop", "~>
|
16
|
+
gem "rubocop", "~> 1.59.0"
|
17
|
+
gem "rubocop-rails", "~> 2.23.1"
|
18
18
|
gem "coveralls", "~> 0.8.23", require: false
|
19
19
|
end
|
20
20
|
|
data/gemfiles/rails_60.gemfile
CHANGED
@@ -7,14 +7,14 @@ gem "railties", "~> 6.0.0"
|
|
7
7
|
|
8
8
|
group :development do
|
9
9
|
gem "appraisal", "~> 2.2"
|
10
|
-
gem "
|
11
|
-
gem "pry-byebug", "~> 3.10.1"
|
10
|
+
gem "debug", "~> 1.9.2"
|
12
11
|
gem "sdoc", "~> 2.0.3"
|
13
12
|
gem "telegram-bot-types", "~> 0.6.3"
|
14
13
|
gem "rspec", "~> 3.12.0"
|
15
14
|
gem "rspec-its", "~> 1.3.0"
|
16
15
|
gem "rspec-rails", "~> 4.0.2"
|
17
|
-
gem "rubocop", "~>
|
16
|
+
gem "rubocop", "~> 1.59.0"
|
17
|
+
gem "rubocop-rails", "~> 2.23.1"
|
18
18
|
gem "coveralls", "~> 0.8.23", require: false
|
19
19
|
end
|
20
20
|
|
data/gemfiles/rails_61.gemfile
CHANGED
@@ -7,14 +7,14 @@ gem "railties", "~> 6.1.0"
|
|
7
7
|
|
8
8
|
group :development do
|
9
9
|
gem "appraisal", "~> 2.2"
|
10
|
-
gem "
|
11
|
-
gem "pry-byebug", "~> 3.10.1"
|
10
|
+
gem "debug", "~> 1.9.2"
|
12
11
|
gem "sdoc", "~> 2.0.3"
|
13
12
|
gem "telegram-bot-types", "~> 0.6.3"
|
14
13
|
gem "rspec", "~> 3.12.0"
|
15
14
|
gem "rspec-its", "~> 1.3.0"
|
16
15
|
gem "rspec-rails", "~> 4.0.2"
|
17
|
-
gem "rubocop", "~>
|
16
|
+
gem "rubocop", "~> 1.59.0"
|
17
|
+
gem "rubocop-rails", "~> 2.23.1"
|
18
18
|
gem "coveralls", "~> 0.8.23", require: false
|
19
19
|
end
|
20
20
|
|
data/gemfiles/rails_70.gemfile
CHANGED
@@ -7,14 +7,14 @@ gem "railties", "~> 7.0.0"
|
|
7
7
|
|
8
8
|
group :development do
|
9
9
|
gem "appraisal", "~> 2.2"
|
10
|
-
gem "
|
11
|
-
gem "pry-byebug", "~> 3.10.1"
|
10
|
+
gem "debug", "~> 1.9.2"
|
12
11
|
gem "sdoc", "~> 2.0.3"
|
13
12
|
gem "telegram-bot-types", "~> 0.6.3"
|
14
13
|
gem "rspec", "~> 3.12.0"
|
15
14
|
gem "rspec-its", "~> 1.3.0"
|
16
15
|
gem "rspec-rails", "~> 4.0.2"
|
17
|
-
gem "rubocop", "~>
|
16
|
+
gem "rubocop", "~> 1.59.0"
|
17
|
+
gem "rubocop-rails", "~> 2.23.1"
|
18
18
|
gem "coveralls", "~> 0.8.23", require: false
|
19
19
|
end
|
20
20
|
|
data/gemfiles/rails_71.gemfile
CHANGED
@@ -7,14 +7,14 @@ gem "railties", "~> 7.1.0"
|
|
7
7
|
|
8
8
|
group :development do
|
9
9
|
gem "appraisal", "~> 2.2"
|
10
|
-
gem "
|
11
|
-
gem "pry-byebug", "~> 3.10.1"
|
10
|
+
gem "debug", "~> 1.9.2"
|
12
11
|
gem "sdoc", "~> 2.0.3"
|
13
12
|
gem "telegram-bot-types", "~> 0.6.3"
|
14
13
|
gem "rspec", "~> 3.12.0"
|
15
14
|
gem "rspec-its", "~> 1.3.0"
|
16
15
|
gem "rspec-rails", "~> 4.0.2"
|
17
|
-
gem "rubocop", "~>
|
16
|
+
gem "rubocop", "~> 1.59.0"
|
17
|
+
gem "rubocop-rails", "~> 2.23.1"
|
18
18
|
gem "coveralls", "~> 0.8.23", require: false
|
19
19
|
end
|
20
20
|
|
data/lib/tasks/telegram-bot.rake
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
namespace :telegram do
|
2
4
|
namespace :bot do
|
3
5
|
desc 'Run poller. It broadcasts Rails.logger to STDOUT in dev like `rails s` do. ' \
|
@@ -6,14 +8,14 @@ namespace :telegram do
|
|
6
8
|
ENV['BOT_POLLER_MODE'] = 'true'
|
7
9
|
Rake::Task['environment'].invoke
|
8
10
|
if ENV.fetch('LOG_TO_STDOUT') { Rails.env.development? }.present?
|
9
|
-
console = ActiveSupport::Logger.new(
|
10
|
-
if
|
11
|
-
|
11
|
+
console = ActiveSupport::Logger.new($stderr)
|
12
|
+
if Rails.logger.respond_to?(:broadcast_to)
|
13
|
+
Rails.logger.broadcast_to(console)
|
12
14
|
else
|
13
15
|
Rails.logger.extend ActiveSupport::Logger.broadcast console
|
14
16
|
end
|
15
17
|
end
|
16
|
-
Telegram::Bot::UpdatesPoller.start(ENV['BOT']
|
18
|
+
Telegram::Bot::UpdatesPoller.start(ENV['BOT']&.to_sym || :default)
|
17
19
|
end
|
18
20
|
|
19
21
|
desc 'Set webhook urls for all bots'
|
data/lib/telegram/bot/async.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Telegram
|
2
4
|
module Bot
|
3
5
|
# Telegram clients can perform requests in async way with
|
@@ -128,7 +130,7 @@ module Telegram
|
|
128
130
|
#
|
129
131
|
# If no block is given returns previously set value or the global one,
|
130
132
|
# set by #async=.
|
131
|
-
def async(val = true)
|
133
|
+
def async(val = true) # rubocop:disable Style/OptionalBooleanParameter
|
132
134
|
thread_key = object_id
|
133
135
|
thread_store = Async.thread_store
|
134
136
|
return thread_store.fetch(thread_key) { @async } unless block_given?
|
@@ -137,7 +139,7 @@ module Telegram
|
|
137
139
|
thread_store[thread_key] = self.class.prepare_async_val(val)
|
138
140
|
yield
|
139
141
|
ensure
|
140
|
-
if
|
142
|
+
if old_val == MISSING_VALUE
|
141
143
|
thread_store.delete(thread_key)
|
142
144
|
else
|
143
145
|
thread_store[thread_key] = old_val
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/core_ext/string/inflections'
|
2
4
|
|
3
5
|
module Telegram
|
4
6
|
module Bot
|
5
7
|
class Client
|
6
8
|
module ApiHelper
|
7
|
-
METHODS_LIST_FILE = File.expand_path('
|
9
|
+
METHODS_LIST_FILE = File.expand_path('api_methods.txt', __dir__)
|
8
10
|
|
9
11
|
class << self
|
10
12
|
def methods_list(file = METHODS_LIST_FILE)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Generated with bin/fetch-telegram-methods
|
2
|
-
# Bot API
|
2
|
+
# Bot API 7.3
|
3
3
|
|
4
4
|
getUpdates
|
5
5
|
setWebhook
|
@@ -11,7 +11,9 @@ logOut
|
|
11
11
|
close
|
12
12
|
sendMessage
|
13
13
|
forwardMessage
|
14
|
+
forwardMessages
|
14
15
|
copyMessage
|
16
|
+
copyMessages
|
15
17
|
sendPhoto
|
16
18
|
sendAudio
|
17
19
|
sendDocument
|
@@ -26,6 +28,7 @@ sendContact
|
|
26
28
|
sendPoll
|
27
29
|
sendDice
|
28
30
|
sendChatAction
|
31
|
+
setMessageReaction
|
29
32
|
getUserProfilePhotos
|
30
33
|
getFile
|
31
34
|
banChatMember
|
@@ -70,6 +73,8 @@ hideGeneralForumTopic
|
|
70
73
|
unhideGeneralForumTopic
|
71
74
|
unpinAllGeneralForumTopicMessages
|
72
75
|
answerCallbackQuery
|
76
|
+
getUserChatBoosts
|
77
|
+
getBusinessConnection
|
73
78
|
setMyCommands
|
74
79
|
deleteMyCommands
|
75
80
|
getMyCommands
|
@@ -92,6 +97,7 @@ stopMessageLiveLocation
|
|
92
97
|
editMessageReplyMarkup
|
93
98
|
stopPoll
|
94
99
|
deleteMessage
|
100
|
+
deleteMessages
|
95
101
|
|
96
102
|
sendSticker
|
97
103
|
getStickerSet
|
@@ -101,6 +107,7 @@ createNewStickerSet
|
|
101
107
|
addStickerToSet
|
102
108
|
setStickerPositionInSet
|
103
109
|
deleteStickerFromSet
|
110
|
+
replaceStickerInSet
|
104
111
|
setStickerEmojiList
|
105
112
|
setStickerKeywords
|
106
113
|
setStickerMaskPosition
|
data/lib/telegram/bot/client.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/core_ext/hash/keys'
|
2
4
|
require 'httpclient'
|
3
5
|
|
4
6
|
module Telegram
|
5
7
|
module Bot
|
6
8
|
class Client
|
7
|
-
SERVER = 'https://api.telegram.org'
|
8
|
-
URL_TEMPLATE = '%<server>s/bot%<token>s/'
|
9
|
+
SERVER = 'https://api.telegram.org'
|
10
|
+
URL_TEMPLATE = '%<server>s/bot%<token>s/'
|
9
11
|
|
10
12
|
autoload :RequestBodyFormatter, 'telegram/bot/client/request_body_formatter'
|
11
13
|
autoload :TypedResponse, 'telegram/bot/client/typed_response'
|
@@ -41,7 +43,7 @@ module Telegram
|
|
41
43
|
end
|
42
44
|
|
43
45
|
def error_for_response(response)
|
44
|
-
result = JSON.parse(response.body) rescue nil # rubocop:disable RescueModifier
|
46
|
+
result = JSON.parse(response.body) rescue nil # rubocop:disable Style/RescueModifier
|
45
47
|
return Error.new(response.reason) unless result
|
46
48
|
message = result['description'] || '-'
|
47
49
|
# This errors are raised only for valid responses from Telegram
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Telegram
|
2
4
|
module Bot
|
3
5
|
# Stubbed client for tests. Saves all requests into #requests hash.
|
@@ -17,7 +19,7 @@ module Telegram
|
|
17
19
|
class << self
|
18
20
|
# Any call to Client.new will return ClientStub instance when `enabled` is true.
|
19
21
|
# Can be used with a block.
|
20
|
-
def stub_all!(enabled = true)
|
22
|
+
def stub_all!(enabled = true) # rubocop:disable Style/OptionalBooleanParameter
|
21
23
|
Client.extend(StubbedConstructor) unless Client < StubbedConstructor
|
22
24
|
return @_stub_all = enabled unless block_given?
|
23
25
|
begin
|
@@ -34,7 +36,7 @@ module Telegram
|
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
37
|
-
def initialize(token = nil, username = nil, **options)
|
39
|
+
def initialize(token = nil, username = nil, **options) # rubocop:disable Lint/MissingSuper
|
38
40
|
@token = token || options[:token]
|
39
41
|
@username = username || options[:username] || token
|
40
42
|
reset
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/core_ext/hash/keys'
|
2
4
|
require 'active_support/core_ext/hash/indifferent_access'
|
3
5
|
|
@@ -44,7 +46,7 @@ module Telegram
|
|
44
46
|
# from `secrets.yml` merging `telegram['bot']` at `:default` key.
|
45
47
|
#
|
46
48
|
# Can be overwritten with .bots_config=
|
47
|
-
def bots_config
|
49
|
+
def bots_config # rubocop:disable Metrics/PerceivedComplexity
|
48
50
|
@bots_config ||=
|
49
51
|
if defined?(Rails.application)
|
50
52
|
app = Rails.application
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/concern'
|
2
4
|
require 'active_support/core_ext/hash/indifferent_access'
|
3
5
|
require 'active_support/json'
|
@@ -21,7 +23,7 @@ module Telegram
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def inspect
|
24
|
-
"#<#{self.class.name}(#{controller
|
26
|
+
"#<#{self.class.name}(#{controller&.name})>"
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
data/lib/telegram/bot/railtie.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'telegram/bot/routes_helper'
|
2
4
|
|
3
5
|
module Telegram
|
@@ -10,7 +12,7 @@ module Telegram
|
|
10
12
|
end
|
11
13
|
|
12
14
|
config.before_initialize do
|
13
|
-
::ActionDispatch::Routing::Mapper.
|
15
|
+
::ActionDispatch::Routing::Mapper.include RoutesHelper
|
14
16
|
end
|
15
17
|
|
16
18
|
initializer 'telegram.bot.updates_controller.set_config' do |app|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'telegram/bot/rspec'
|
2
4
|
require 'telegram/bot/rspec/message_helpers'
|
3
5
|
|
@@ -7,7 +9,7 @@ RSpec.shared_context 'telegram/bot/callback_query' do
|
|
7
9
|
|
8
10
|
subject { -> { dispatch callback_query: payload } }
|
9
11
|
let(:payload) { {id: callback_query_id, from: from, message: message, data: data} }
|
10
|
-
let(:callback_query_id) { 11 }
|
12
|
+
let(:callback_query_id) { '11' }
|
11
13
|
let(:message_id) { 22 }
|
12
14
|
let(:message) { {message_id: message_id, chat: chat, text: 'message text'} }
|
13
15
|
let(:data) { raise '`let(:data) { "callback query data here" }` is required' }
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Telegram
|
2
4
|
module Bot
|
3
5
|
module RSpec
|
@@ -61,14 +63,14 @@ module Telegram
|
|
61
63
|
|
62
64
|
attr_reader :performed_requests, :description
|
63
65
|
|
64
|
-
def initialize(bot, action, description: nil)
|
66
|
+
def initialize(bot, action, description: nil) # rubocop:disable Lint/MissingSuper
|
65
67
|
@bot = bot
|
66
68
|
@action = action
|
67
69
|
@description = description || "make #{action} telegram request"
|
68
70
|
exactly(1)
|
69
71
|
end
|
70
72
|
|
71
|
-
def matches?(proc) # rubocop:disable AbcSize
|
73
|
+
def matches?(proc) # rubocop:disable Metrics/AbcSize
|
72
74
|
raise ArgumentError, 'matcher only supports block expectations' unless proc.is_a?(Proc)
|
73
75
|
original_requests_count = bot.requests[action].count
|
74
76
|
proc.call
|
@@ -115,15 +117,15 @@ module Telegram
|
|
115
117
|
:arg_list_matcher, :matching_requests_count
|
116
118
|
|
117
119
|
def base_message
|
118
|
-
"make #{expectation_type.to_s.tr('_', ' ')} #{expected_number} " \
|
119
|
-
"#{bot.inspect}.#{action} requests,"
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
end
|
120
|
+
msg = "make #{expectation_type.to_s.tr('_', ' ')} #{expected_number} " \
|
121
|
+
"#{bot.inspect}.#{action} requests,"
|
122
|
+
msg += " with #{arg_list_matcher}," if arg_list_matcher
|
123
|
+
msg += " but made #{matching_requests_count}"
|
124
|
+
if performed_requests
|
125
|
+
actual_args = performed_requests.map(&:inspect).join(', ')
|
126
|
+
msg += ", and #{performed_requests.count} with #{actual_args}"
|
126
127
|
end
|
128
|
+
msg
|
127
129
|
end
|
128
130
|
end
|
129
131
|
|