telegram-bot 0.15.2 → 0.15.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81fae472dfd6080e48c0b3329cc7b5e8748aa89040162a089480bf0082a72477
4
- data.tar.gz: a3620f420bcd83f58a70aa093ca8becf748156a88000f663d5b0ba5a4fb59f77
3
+ metadata.gz: 557dd6660b57db212a311ed47dc449c833dd2020fc51d13110bf95ecbc28f0b9
4
+ data.tar.gz: b3dc3085d49456ce58931e4101b90b9a35d8853e09b0b0f398e772f6885b1e5a
5
5
  SHA512:
6
- metadata.gz: 0ccbbc372a75c5861ec8751f912282227e06850ca84d23617ddda126b0ab2eaa592d4f005b976d451c87c80f9bb59d27a13d58e752d6290dc27500d9c4252b97
7
- data.tar.gz: 69553e905b7b8c7d31e8006e592ccfc824459c14dcc15f696e94866bd7a20f604dcf52a40622152602f44ec997628646a98fa75f2b766221c7cef2815c5271a1
6
+ metadata.gz: b1c07f86462d5c98528480ef526b0c14b0a94b66aa2e9b61b556bbf7ddd573a8db0b8a94149562ad481ccb802b975671f7eccc4ec6dba7b2ff98aaea21946b3a
7
+ data.tar.gz: 738791f83acc89dee90a860d6dec91a8d340bf66cebdce8411c0bfe70c1de0ce2c90f0eeaac7dfaf7a930c6e1e50d158a39e75223a3bd0edacda8466c2ec0486
data/Appraisals CHANGED
@@ -1,3 +1,8 @@
1
+ appraise 'rails-70' do
2
+ gem 'actionpack', '~> 7.0.0'
3
+ gem 'railties', '~> 7.0.0'
4
+ end
5
+
1
6
  appraise 'rails-61' do
2
7
  gem 'actionpack', '~> 6.1.0'
3
8
  gem 'railties', '~> 6.1.0'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Unreleased
2
2
 
3
+ # 0.15.6
4
+
5
+ - Rails 7.0 support.
6
+ - Fix sending File objects in nested objects in sendMediaGroup.
7
+ - Update to Bot API 5.7
8
+
9
+ # 0.15.4
10
+
11
+ - Update to Bot API 5.3
12
+
13
+ # 0.15.3
14
+
15
+ - Ruby 3.0 support: fix translation helpers.
16
+
3
17
  # 0.15.2
4
18
 
5
19
  - Ruby 3.0 support. Drop support for Ruby < 2.4.
data/Gemfile CHANGED
@@ -8,7 +8,7 @@ group :development do
8
8
  gem 'pry-byebug', '~> 3.9.0'
9
9
  gem 'sdoc', '~> 2.0.3'
10
10
 
11
- gem 'telegram-bot-types', '~> 0.6.2'
11
+ gem 'telegram-bot-types', '~> 0.6.3'
12
12
 
13
13
  gem 'rspec', '~> 3.10.0'
14
14
  gem 'rspec-its', '~> 1.3.0'
data/README.md CHANGED
@@ -2,7 +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.org/telegram-bot-rb/telegram-bot.svg)](https://travis-ci.org/telegram-bot-rb/telegram-bot)
5
+ [![Build Status](https://app.travis-ci.com/telegram-bot-rb/telegram-bot.svg)](https://app.travis-ci.com/github/telegram-bot-rb/telegram-bot)
6
6
 
7
7
  Tools for developing Telegram bots. Best used with Rails, but can be used in
8
8
  [standalone app](https://github.com/telegram-bot-rb/telegram-bot/wiki/Not-rails-application).
@@ -25,9 +25,33 @@ with session, keyboards and inline queries.
25
25
  Run it on your local machine in 1 minute!
26
26
 
27
27
  And here is [app template](https://github.com/telegram-bot-rb/rails_template)
28
- to generate clean app in seconds.
29
-
30
- Examples and cookbook in [wiki](https://github.com/telegram-bot-rb/telegram-bot/wiki).
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)
31
55
 
32
56
  ## Installation
33
57
 
@@ -39,11 +63,15 @@ gem 'telegram-bot'
39
63
 
40
64
  And then execute:
41
65
 
42
- $ bundle
66
+ ```
67
+ bundle
68
+ ```
43
69
 
44
70
  Or install it yourself as:
45
71
 
46
- $ gem install telegram-bot
72
+ ```
73
+ gem install telegram-bot
74
+ ```
47
75
 
48
76
  Require if necessary:
49
77
 
@@ -170,19 +198,18 @@ Bot controllers like usual rails controllers provides features like callbacks,
170
198
 
171
199
  ```ruby
172
200
  class Telegram::WebhookController < Telegram::Bot::UpdatesController
173
- # use callbacks like in any other controllers
201
+ # use callbacks like in any other controller
174
202
  around_action :with_locale
175
203
 
176
- # Every update can have one of: message, inline_query, chosen_inline_result,
204
+ # Every update has one of: message, inline_query, chosen_inline_result,
177
205
  # callback_query, etc.
178
- # Define method with same name to respond to this updates.
206
+ # Define method with the same name to handle this type of update.
179
207
  def message(message)
180
- # message can be also accessed via instance method
181
- message == self.payload # true
182
208
  # store_message(message['text'])
183
209
  end
184
210
 
185
- # This basic methods receives commonly used params:
211
+ # For the following types of updates commonly used params are passed as arguments,
212
+ # full payload object is available with `payload` instance method.
186
213
  #
187
214
  # message(payload)
188
215
  # inline_query(query, offset)
@@ -193,14 +220,19 @@ class Telegram::WebhookController < Telegram::Bot::UpdatesController
193
220
  # Command arguments will be parsed and passed to the method.
194
221
  # Be sure to use splat args and default values to not get errors when
195
222
  # someone passed more or less arguments in the message.
196
- def start!(data = nil, *)
197
- # do_smth_with(data)
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'])
198
228
 
199
229
  # There are `chat` & `from` shortcut methods.
200
- # For callback queries `chat` if taken from `message` when it's available.
230
+ # For callback queries `chat` is taken from `message` when it's available.
201
231
  response = from ? "Hello #{from['username']}!" : 'Hi there!'
232
+
202
233
  # There is `respond_with` helper to set `chat_id` from received message:
203
234
  respond_with :message, text: response
235
+
204
236
  # `reply_with` also sets `reply_to_message_id`:
205
237
  reply_with :photo, photo: File.open('party.jpg')
206
238
  end
@@ -223,10 +255,10 @@ end
223
255
 
224
256
  #### Reply helpers
225
257
 
226
- There are helpers to respond for basic actions. They just set chat/message/query
227
- identifiers from update. See
258
+ There are helpers for basic responses. They just set chat/message/query
259
+ identifiers from the update. See
228
260
  [`ReplyHelpers`](https://github.com/telegram-bot-rb/telegram-bot/blob/master/lib/telegram/bot/updates_controller/reply_helpers.rb)
229
- module for more information. Here are this methods signatures:
261
+ module for more information. Here are these methods signatures:
230
262
 
231
263
  ```ruby
232
264
  def respond_with(type, params); end
@@ -389,7 +421,7 @@ telegram_webhook TelegramAuctionController, :auction
389
421
  telegram_webhook TelegramController, as: :custom_telegram_webhook
390
422
  ```
391
423
 
392
- #### Processesing updates
424
+ #### Processing updates
393
425
 
394
426
  To process update with controller call `.dispatch(bot, update)` on it.
395
427
  There are several options to run it automatically:
@@ -507,7 +539,7 @@ end
507
539
 
508
540
  There is a context for testing bot controller in the way similar to Rails controller tests.
509
541
  It's supposed to be a low-level alternative for integration tests. Among the differences is
510
- that controller tests use a single controller instance for all dispatches in specific exaple,
542
+ that controller tests use a single controller instance for all dispatches in specific example,
511
543
  session is stubbed (does not use configured store engine), and update is not serialized
512
544
  so it also supports mocks. This can be useful for unit testing, but should not be used as
513
545
  the default way to test the bot.
@@ -10,7 +10,7 @@ group :development do
10
10
  gem "pry", "~> 0.13.1"
11
11
  gem "pry-byebug", "~> 3.9.0"
12
12
  gem "sdoc", "~> 2.0.3"
13
- gem "telegram-bot-types", "~> 0.6.2"
13
+ gem "telegram-bot-types", "~> 0.6.3"
14
14
  gem "rspec", "~> 3.10.0"
15
15
  gem "rspec-its", "~> 1.3.0"
16
16
  gem "rspec-rails", "~> 4.0.2"
@@ -10,7 +10,7 @@ group :development do
10
10
  gem "pry", "~> 0.13.1"
11
11
  gem "pry-byebug", "~> 3.9.0"
12
12
  gem "sdoc", "~> 2.0.3"
13
- gem "telegram-bot-types", "~> 0.6.2"
13
+ gem "telegram-bot-types", "~> 0.6.3"
14
14
  gem "rspec", "~> 3.10.0"
15
15
  gem "rspec-its", "~> 1.3.0"
16
16
  gem "rspec-rails", "~> 4.0.2"
@@ -10,7 +10,7 @@ group :development do
10
10
  gem "pry", "~> 0.13.1"
11
11
  gem "pry-byebug", "~> 3.9.0"
12
12
  gem "sdoc", "~> 2.0.3"
13
- gem "telegram-bot-types", "~> 0.6.2"
13
+ gem "telegram-bot-types", "~> 0.6.3"
14
14
  gem "rspec", "~> 3.10.0"
15
15
  gem "rspec-its", "~> 1.3.0"
16
16
  gem "rspec-rails", "~> 4.0.2"
@@ -10,7 +10,7 @@ group :development do
10
10
  gem "pry", "~> 0.13.1"
11
11
  gem "pry-byebug", "~> 3.9.0"
12
12
  gem "sdoc", "~> 2.0.3"
13
- gem "telegram-bot-types", "~> 0.6.2"
13
+ gem "telegram-bot-types", "~> 0.6.3"
14
14
  gem "rspec", "~> 3.10.0"
15
15
  gem "rspec-its", "~> 1.3.0"
16
16
  gem "rspec-rails", "~> 4.0.2"
@@ -10,7 +10,7 @@ group :development do
10
10
  gem "pry", "~> 0.13.1"
11
11
  gem "pry-byebug", "~> 3.9.0"
12
12
  gem "sdoc", "~> 2.0.3"
13
- gem "telegram-bot-types", "~> 0.6.2"
13
+ gem "telegram-bot-types", "~> 0.6.3"
14
14
  gem "rspec", "~> 3.10.0"
15
15
  gem "rspec-its", "~> 1.3.0"
16
16
  gem "rspec-rails", "~> 4.0.2"
@@ -10,7 +10,7 @@ group :development do
10
10
  gem "pry", "~> 0.13.1"
11
11
  gem "pry-byebug", "~> 3.9.0"
12
12
  gem "sdoc", "~> 2.0.3"
13
- gem "telegram-bot-types", "~> 0.6.2"
13
+ gem "telegram-bot-types", "~> 0.6.3"
14
14
  gem "rspec", "~> 3.10.0"
15
15
  gem "rspec-its", "~> 1.3.0"
16
16
  gem "rspec-rails", "~> 4.0.2"
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "actionpack", "~> 7.0.0"
6
+ gem "railties", "~> 7.0.0"
7
+
8
+ group :development do
9
+ gem "appraisal", "~> 2.2"
10
+ gem "pry", "~> 0.13.1"
11
+ gem "pry-byebug", "~> 3.9.0"
12
+ gem "sdoc", "~> 2.0.3"
13
+ gem "telegram-bot-types", "~> 0.6.3"
14
+ gem "rspec", "~> 3.10.0"
15
+ gem "rspec-its", "~> 1.3.0"
16
+ gem "rspec-rails", "~> 4.0.2"
17
+ gem "rubocop", "~> 0.52.1"
18
+ gem "coveralls", "~> 0.8.23", require: false
19
+ end
20
+
21
+ gemspec path: "../"
@@ -1,5 +1,5 @@
1
1
  # Generated with bin/fetch-telegram-methods
2
- # Bot API 5.0
2
+ # Bot API 5.7
3
3
 
4
4
  getUpdates
5
5
  setWebhook
@@ -30,13 +30,20 @@ sendDice
30
30
  sendChatAction
31
31
  getUserProfilePhotos
32
32
  getFile
33
- kickChatMember
33
+ banChatMember
34
34
  unbanChatMember
35
35
  restrictChatMember
36
36
  promoteChatMember
37
37
  setChatAdministratorCustomTitle
38
+ banChatSenderChat
39
+ unbanChatSenderChat
38
40
  setChatPermissions
39
41
  exportChatInviteLink
42
+ createChatInviteLink
43
+ editChatInviteLink
44
+ revokeChatInviteLink
45
+ approveChatJoinRequest
46
+ declineChatJoinRequest
40
47
  setChatPhoto
41
48
  deleteChatPhoto
42
49
  setChatTitle
@@ -47,12 +54,13 @@ unpinAllChatMessages
47
54
  leaveChat
48
55
  getChat
49
56
  getChatAdministrators
50
- getChatMembersCount
57
+ getChatMemberCount
51
58
  getChatMember
52
59
  setChatStickerSet
53
60
  deleteChatStickerSet
54
61
  answerCallbackQuery
55
62
  setMyCommands
63
+ deleteMyCommands
56
64
  getMyCommands
57
65
 
58
66
  editMessageText
@@ -0,0 +1,48 @@
1
+ require 'json'
2
+
3
+ module Telegram
4
+ module Bot
5
+ class Client
6
+ # Encodes nested hashes and arrays as json and extract File objects from them
7
+ # to the top level. Top-level File objects are handled by httpclient.
8
+ # More details: https://core.telegram.org/bots/api#sending-files
9
+ module RequestBodyFormatter
10
+ extend self
11
+
12
+ def format(body, action)
13
+ body = body.dup
14
+ if action.to_s == 'sendMediaGroup'
15
+ body = extract_files_from_array!(body, :media)
16
+ end
17
+ body.each do |key, val|
18
+ body[key] = val.to_json if val.is_a?(Hash) || val.is_a?(Array)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def extract_files_from_array!(body, field_name)
25
+ field_name = [field_name.to_sym, field_name.to_s].find { |x| body.key?(x) }
26
+ return body unless field_name && body[field_name].is_a?(Array)
27
+ files = {}
28
+ body[field_name] = body[field_name].map { |x| extract_files_from_hash(x, files) }
29
+ body.merge!(files)
30
+ end
31
+
32
+ # Replace File objects with `attach` URIs. File objects are added into `files` hash.
33
+ def extract_files_from_hash(hash, files)
34
+ return hash unless hash.is_a?(Hash)
35
+ hash.transform_values do |value|
36
+ if value.is_a?(File)
37
+ arg_name = "_file#{files.size}"
38
+ files[arg_name] = value
39
+ "attach://#{arg_name}"
40
+ else
41
+ value
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,5 +1,4 @@
1
1
  require 'active_support/core_ext/hash/keys'
2
- require 'json'
3
2
  require 'httpclient'
4
3
 
5
4
  module Telegram
@@ -8,7 +7,9 @@ module Telegram
8
7
  SERVER = 'https://api.telegram.org'.freeze
9
8
  URL_TEMPLATE = '%<server>s/bot%<token>s/'.freeze
10
9
 
10
+ autoload :RequestBodyFormatter, 'telegram/bot/client/request_body_formatter'
11
11
  autoload :TypedResponse, 'telegram/bot/client/typed_response'
12
+
12
13
  prepend Async
13
14
  include DebugClient
14
15
 
@@ -35,16 +36,8 @@ module Telegram
35
36
  prepend TypedResponse
36
37
  end
37
38
 
38
- # Encodes nested hashes as json.
39
- def prepare_body(body)
40
- body = body.dup
41
- body.each do |k, val|
42
- body[k] = val.to_json if val.is_a?(Hash) || val.is_a?(Array)
43
- end
44
- end
45
-
46
39
  def prepare_async_args(action, body = {})
47
- [action.to_s, Async.prepare_hash(prepare_body(body))]
40
+ [action.to_s, Async.prepare_hash(RequestBodyFormatter.format(body, action))]
48
41
  end
49
42
 
50
43
  def error_for_response(response)
@@ -70,7 +63,7 @@ module Telegram
70
63
  end
71
64
 
72
65
  def request(action, body = {})
73
- response = http_request("#{base_uri}#{action}", self.class.prepare_body(body))
66
+ response = http_request("#{base_uri}#{action}", RequestBodyFormatter.format(body, action))
74
67
  raise self.class.error_for_response(response) if response.status >= 300
75
68
  JSON.parse(response.body)
76
69
  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
 
@@ -99,6 +99,8 @@ module Telegram
99
99
  pre_checkout_query
100
100
  poll
101
101
  poll_answer
102
+ my_chat_member
103
+ chat_member
102
104
  ].freeze
103
105
 
104
106
  class << self
@@ -1,6 +1,6 @@
1
1
  module Telegram
2
2
  module Bot
3
- VERSION = '0.15.2'.freeze
3
+ VERSION = '0.15.6'.freeze
4
4
 
5
5
  def self.gem_version
6
6
  Gem::Version.new VERSION
data/telegram-bot.gemspec CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.required_ruby_version = '>= 2.4'
21
21
 
22
- spec.add_dependency 'actionpack', '>= 4.0', '< 6.2'
23
- spec.add_dependency 'activesupport', '>= 4.0', '< 6.2'
22
+ spec.add_dependency 'actionpack', '>= 4.0', '< 7.1'
23
+ spec.add_dependency 'activesupport', '>= 4.0', '< 7.1'
24
24
  spec.add_dependency 'httpclient', '~> 2.7'
25
25
 
26
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.15.2
4
+ version: 0.15.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Melentiev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-26 00:00:00.000000000 Z
11
+ date: 2022-03-13 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.2'
22
+ version: '7.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.2'
32
+ version: '7.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.2'
42
+ version: '7.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.2'
52
+ version: '7.1'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: httpclient
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -121,12 +121,14 @@ files:
121
121
  - gemfiles/rails_52.gemfile
122
122
  - gemfiles/rails_60.gemfile
123
123
  - gemfiles/rails_61.gemfile
124
+ - gemfiles/rails_70.gemfile
124
125
  - lib/tasks/telegram-bot.rake
125
126
  - lib/telegram/bot.rb
126
127
  - lib/telegram/bot/async.rb
127
128
  - lib/telegram/bot/client.rb
128
129
  - lib/telegram/bot/client/api_helper.rb
129
130
  - lib/telegram/bot/client/api_methods.txt
131
+ - lib/telegram/bot/client/request_body_formatter.rb
130
132
  - lib/telegram/bot/client/typed_response.rb
131
133
  - lib/telegram/bot/client_stub.rb
132
134
  - lib/telegram/bot/config_methods.rb
@@ -178,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
180
  - !ruby/object:Gem::Version
179
181
  version: '0'
180
182
  requirements: []
181
- rubygems_version: 3.1.4
183
+ rubygems_version: 3.2.3
182
184
  signing_key:
183
185
  specification_version: 4
184
186
  summary: Library for building Telegram Bots with Rails integration