telegram-bot 0.14.3 → 0.15.3

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: 86966ea026e7fee0f7fdf41ed9ed276ffe40573f2ca80b381d37fa3841e4106b
4
- data.tar.gz: 31a39fd06a2d8ea5dc1f724ffba44df1ec20c56622825a3c871101b27d8ef0cf
3
+ metadata.gz: 7cb3d6a6238c7d07cf8b6f33743dc5bc5a5442b9695f716cd22098b9dae341a6
4
+ data.tar.gz: 3d0d9ff96175d7e63041d2f76048f158f75fcc19bd059270e479e4034a21db3f
5
5
  SHA512:
6
- metadata.gz: c78d6cba52499218f9946d218b0b0224eea69abae54f4cc51e551120aa827955acdd20ba2dce76e4ca76906424a86292683c06e4ef034a4c6c3839b895beb35b
7
- data.tar.gz: d3d9a48d327f364f1419fbf5a665564a3c63e53955515f7eb1d52d91af30e7e69690d958450bb02c4f66cae6e543df71cb35a79111716fcc1107211b7f30256f
6
+ metadata.gz: d406dace6502e17764530733200f9f1d5a14d496087b35449a086675e1c15cd3cdcc71119e744422338f5367f75fffb82abc793dcc17f08c30b76565d487fd52
7
+ data.tar.gz: 97e4323e43fee40885628fadeb179edeff9d3d73da12e8803dfbf2ce36e2ec5ac94b7499da14721e4cedee44ca38dc9d1d36a5cf21b2c4918bb8f48230e2a794
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
- matrix:
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
@@ -1,8 +1,6 @@
1
1
  appraise 'rails-61' do
2
- git 'https://github.com/rails/rails.git' do
3
- gem 'actionpack', '~> 6.1.0.alpha'
4
- gem 'railties', '~> 6.1.0.alpha'
5
- end
2
+ gem 'actionpack', '~> 6.1.0'
3
+ gem 'railties', '~> 6.1.0'
6
4
  end
7
5
 
8
6
  appraise 'rails-60' do
data/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Unreleased
2
2
 
3
+ # 0.15.3
4
+
5
+ - Ruby 3.0 support: fix translation helpers.
6
+
7
+ # 0.15.2
8
+
9
+ - Ruby 3.0 support. Drop support for Ruby < 2.4.
10
+
11
+ # 0.15.1
12
+
13
+ - Rails 6.1 support.
14
+
15
+ # 0.15.0
16
+
17
+ - Add `:path` option to `telegram_webhook` route helper.
18
+ - __Breaking change!__ Default route is generated using hashed bot token.
19
+ Please reconfigure webhook after update (`rake telegram:bot:set_webhook`).
20
+ - Update to Bot API 5.0, add rake tasks for `deleteWebhook`, `close` & `logOut`.
21
+ - Add `server` option for client to support local bot API servers.
22
+
23
+ # 0.14.4
24
+
25
+ - Update to Bot API 4.7
26
+
27
+ # 0.14.3
28
+
3
29
  - Rails 6.0 support.
4
30
  - Update to Bot API 4.4.
5
31
 
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.10.1'
8
- gem 'pry-byebug', '~> 3.2.0'
9
- gem 'sdoc', '~> 0.4.1'
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.0'
11
+ gem 'telegram-bot-types', '~> 0.6.2'
12
12
 
13
- gem 'rspec', '~> 3.5.0'
14
- gem 'rspec-its', '~> 1.1.0'
15
- gem 'rspec-rails', '~> 3.5.0'
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.2', require: false
19
+ gem 'coveralls', '~> 0.8.23', require: false
20
20
  end
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 [upgrade 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
@@ -65,7 +63,11 @@ which is used for `Telegram.bot`.
65
63
  ```ruby
66
64
  Telegram.bots_config = {
67
65
  default: DEFAULT_BOT_TOKEN,
68
- chat: {token: CHAT_BOT_TOKEN, username: 'chatbot'},
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
+ },
69
71
  }
70
72
 
71
73
  Telegram.bot.get_updates
@@ -87,6 +89,7 @@ development:
87
89
  bot:
88
90
  token: TOKEN
89
91
  username: SomeBot
92
+ server: http://local.bot.api.server
90
93
 
91
94
  # For multiple bots in single app use hash of `internal_bot_id => settings`
92
95
  bots:
@@ -128,9 +131,9 @@ bot.send_message(chat_id: chat_id, text: 'Test')
128
131
  ```
129
132
 
130
133
  There is no magic, they just pass params as is and set `path_suffix`.
131
- See [`Client`](https://github.com/telegram-bot-rb/telegram-bot/blob/master/lib/telegram/bot/client.rb)
132
- class for list of available methods. Please open PR or issue if it misses methods from
133
- new API versions.
134
+ See [list of available methods](https://github.com/telegram-bot-rb/telegram-bot/blob/master/lib/telegram/bot/client/api_methods.txt)
135
+ fetched from [API docs](https://core.telegram.org/bots/api).
136
+ Please open PR or issue if it misses methods from new API versions.
134
137
 
135
138
  Any API request error will raise `Telegram::Bot::Error` with description in its message.
136
139
  Special `Telegram::Bot::Forbidden` is raised when bot can't post messages to the chat anymore.
@@ -366,7 +369,7 @@ end
366
369
  ### Routes in Rails app
367
370
 
368
371
  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.
372
+ It defines routes at `telegram/#{hash_of(bot.token)}` and connects bots with controller.
370
373
 
371
374
  ```ruby
372
375
  # Most off apps would require
@@ -475,10 +478,11 @@ RSpec.describe TelegramWebhooksController, telegram_bot: :rails do
475
478
  # dispatch_command(cmd, *args)
476
479
 
477
480
  # Available matchers can be found in Telegram::Bot::RSpec::ClientMatchers.
478
- it 'shows usage of basic matchers'
479
- # The most basic one is #make_telegram_request(bot, endpoint, params_matcher)
480
- expect { dispatch_command(:start) }.
481
- to make_telegram_request(bot, :sendMessage, hash_including(text: 'msg text'))
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'))
482
486
 
483
487
  # There are some shortcuts for dispatching basic updates and testing responses.
484
488
  expect { dispatch_message('Hi') }.to send_telegram_message(bot, /msg regexp/, some: :option)
@@ -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
@@ -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.10.1"
11
- gem "pry-byebug", "~> 3.2.0"
12
- gem "sdoc", "~> 0.4.1"
13
- gem "telegram-bot-types", "~> 0.6.0"
14
- gem "rspec", "~> 3.5.0"
15
- gem "rspec-its", "~> 1.1.0"
16
- gem "rspec-rails", "~> 3.5.0"
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.2"
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.2", require: false
18
+ gem "coveralls", "~> 0.8.23", require: false
19
19
  end
20
20
 
21
21
  gemspec path: "../"
@@ -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.10.1"
11
- gem "pry-byebug", "~> 3.2.0"
12
- gem "sdoc", "~> 0.4.1"
13
- gem "telegram-bot-types", "~> 0.6.0"
14
- gem "rspec", "~> 3.5.0"
15
- gem "rspec-its", "~> 1.1.0"
16
- gem "rspec-rails", "~> 3.5.0"
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.2"
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.2", require: false
18
+ gem "coveralls", "~> 0.8.23", require: false
19
19
  end
20
20
 
21
21
  gemspec path: "../"
@@ -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.10.1"
11
- gem "pry-byebug", "~> 3.2.0"
12
- gem "sdoc", "~> 0.4.1"
13
- gem "telegram-bot-types", "~> 0.6.0"
14
- gem "rspec", "~> 3.5.0"
15
- gem "rspec-its", "~> 1.1.0"
16
- gem "rspec-rails", "~> 3.5.0"
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.2"
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.2", require: false
18
+ gem "coveralls", "~> 0.8.23", require: false
19
19
  end
20
20
 
21
21
  gemspec path: "../"
@@ -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.10.1"
11
- gem "pry-byebug", "~> 3.2.0"
12
- gem "sdoc", "~> 0.4.1"
13
- gem "telegram-bot-types", "~> 0.6.0"
14
- gem "rspec", "~> 3.5.0"
15
- gem "rspec-its", "~> 1.1.0"
16
- gem "rspec-rails", "~> 3.5.0"
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.2"
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.2", require: false
18
+ gem "coveralls", "~> 0.8.23", require: false
19
19
  end
20
20
 
21
21
  gemspec path: "../"
@@ -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.10.1"
11
- gem "pry-byebug", "~> 3.2.0"
12
- gem "sdoc", "~> 0.4.1"
13
- gem "telegram-bot-types", "~> 0.6.0"
14
- gem "rspec", "~> 3.5.0"
15
- gem "rspec-its", "~> 1.1.0"
16
- gem "rspec-rails", "~> 3.5.0"
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.2"
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.2", require: false
18
+ gem "coveralls", "~> 0.8.23", require: false
19
19
  end
20
20
 
21
21
  gemspec path: "../"
@@ -2,22 +2,20 @@
2
2
 
3
3
  source "https://rubygems.org"
4
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
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.10.1"
13
- gem "pry-byebug", "~> 3.2.0"
14
- gem "sdoc", "~> 0.4.1"
15
- gem "telegram-bot-types", "~> 0.6.0"
16
- gem "rspec", "~> 3.5.0"
17
- gem "rspec-its", "~> 1.1.0"
18
- gem "rspec-rails", "~> 3.5.0"
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.2"
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.2", require: false
18
+ gem "coveralls", "~> 0.8.23", require: false
21
19
  end
22
20
 
23
21
  gemspec path: "../"
@@ -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
- routes = Rails.application.routes.url_helpers
18
- cert_file = ENV['CERT']
19
- cert = File.open(cert_file) if cert_file
20
- Telegram.bots.each do |key, bot|
21
- route_name = Telegram::Bot::RoutesHelper.route_name_for_bot(bot)
22
- url = routes.send("#{route_name}_url")
23
- puts "Setting webhook for #{key}..."
24
- bot.async(false) { bot.set_webhook(url: url, certificate: cert) }
25
- end
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 deprecation_0_15
17
+ def deprecation_0_16
18
18
  @deprecation ||= begin
19
19
  require 'active_support/deprecation'
20
- ActiveSupport::Deprecation.new('0.15', 'Telegram::Bot')
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
@@ -16,8 +16,8 @@ module Telegram
16
16
  # accessible via `Teletgram.bots[id]` in job worker. Or just use
17
17
  # `Telegram.bots_config=` for configuration.
18
18
  #
19
- # Being in async mode `#request` enqueues job instead to perform
20
- # http request instead of performing it directly.
19
+ # Being in async mode `#request` enqueues job to perform
20
+ # http request instead of performing it immediately.
21
21
  # Async behavior is controlled with `#async=` writer
22
22
  # and can be enabled/disabled for the block with `#async`:
23
23
  #
@@ -29,7 +29,7 @@ module Telegram
29
29
  # while `#async(val, &block)` is thread-safe.
30
30
  #
31
31
  # It can be set with custom job class or classname. By default it defines
32
- # job classes for every client class, inherited from ApplicationRecord, which
32
+ # job classes inherited from ApplicationJob, which
33
33
  # can be accessed via `.default_async_job`. You can integrate it with any
34
34
  # other job provider by defining a class with `.perform_later(bot_id, *args)`
35
35
  # method. See Async::Job for implemetation.
@@ -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
- URL_TEMPLATE = 'https://api.telegram.org/bot%<token>s/'.freeze
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 4.4
2
+ # Bot API 5.0
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
@@ -23,6 +26,7 @@ stopMessageLiveLocation
23
26
  sendVenue
24
27
  sendContact
25
28
  sendPoll
29
+ sendDice
26
30
  sendChatAction
27
31
  getUserProfilePhotos
28
32
  getFile
@@ -30,6 +34,7 @@ kickChatMember
30
34
  unbanChatMember
31
35
  restrictChatMember
32
36
  promoteChatMember
37
+ setChatAdministratorCustomTitle
33
38
  setChatPermissions
34
39
  exportChatInviteLink
35
40
  setChatPhoto
@@ -38,6 +43,7 @@ setChatTitle
38
43
  setChatDescription
39
44
  pinChatMessage
40
45
  unpinChatMessage
46
+ unpinAllChatMessages
41
47
  leaveChat
42
48
  getChat
43
49
  getChatAdministrators
@@ -46,6 +52,8 @@ getChatMember
46
52
  setChatStickerSet
47
53
  deleteChatStickerSet
48
54
  answerCallbackQuery
55
+ setMyCommands
56
+ getMyCommands
49
57
 
50
58
  editMessageText
51
59
  editMessageCaption
@@ -61,6 +69,7 @@ createNewStickerSet
61
69
  addStickerToSet
62
70
  setStickerPositionInSet
63
71
  deleteStickerFromSet
72
+ setStickerSetThumb
64
73
 
65
74
  answerInlineQuery
66
75
 
@@ -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
- # Replaces colon with underscore so rails don't treat it as
21
- # route parameter.
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
- def telegram_webhook(controller, bot = :default, **options)
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.escape_token bot.token}", params)
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
@@ -97,6 +97,8 @@ module Telegram
97
97
  callback_query
98
98
  shipping_query
99
99
  pre_checkout_query
100
+ poll
101
+ poll_answer
100
102
  ].freeze
101
103
 
102
104
  class << self
@@ -148,7 +150,7 @@ module Telegram
148
150
  # Accessor to `'from'` field of payload. Can be overriden with `from` option
149
151
  # for #initialize.
150
152
  def from
151
- @_from ||= payload && payload['from']
153
+ @_from ||= payload.is_a?(Hash) ? payload['from'] : payload.try(:from)
152
154
  end
153
155
 
154
156
  # Processes current update.
@@ -206,6 +208,10 @@ module Telegram
206
208
  [payload_type, [payload['data']]]
207
209
  end
208
210
 
211
+ def action_for_poll_answer
212
+ [payload_type, [payload['poll_id'], payload['option_ids']]]
213
+ end
214
+
209
215
  # Silently ignore unsupported messages to not fail when user crafts
210
216
  # an update with usupported command, callback query context, etc.
211
217
  def action_missing(action, *_args)
@@ -49,7 +49,7 @@ module Telegram
49
49
  private
50
50
 
51
51
  # A hook invoked every time a before callback is halted.
52
- def halted_callback_hook(filter)
52
+ def halted_callback_hook(filter, *)
53
53
  Instrumentation.instrument(:halted_callback, filter: filter)
54
54
  end
55
55
 
@@ -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
 
@@ -50,7 +50,7 @@ module Telegram
50
50
  ensure
51
51
  @running = false
52
52
  end
53
- log { 'Stoped polling bot updates.' }
53
+ log { 'Stopped polling bot updates.' }
54
54
  end
55
55
 
56
56
  def run
@@ -1,6 +1,6 @@
1
1
  module Telegram
2
2
  module Bot
3
- VERSION = '0.14.3'.freeze
3
+ VERSION = '0.15.3'.freeze
4
4
 
5
5
  def self.gem_version
6
6
  Gem::Version.new VERSION
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'
20
+ spec.required_ruby_version = '>= 2.4'
22
21
 
23
- spec.required_ruby_version = '~> 2.0'
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'
30
- spec.add_development_dependency 'rake', '~> 10.0'
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.14.3
4
+ version: 0.15.3
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: 2019-08-24 00:00:00.000000000 Z
11
+ date: 2021-02-15 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.1'
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.1'
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.1'
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.1'
52
+ version: '6.2'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: httpclient
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -84,15 +84,15 @@ dependencies:
84
84
  requirements:
85
85
  - - "~>"
86
86
  - !ruby/object:Gem::Version
87
- version: '10.0'
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: '10.0'
95
- description:
94
+ version: '13.0'
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: Breaking changes in v0.14! See upgrade guide at https://github.com/telegram-bot-rb/telegram-bot/wiki/Upgrading-to-0.14
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.0'
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.0.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