telegram-bot-ruby 0.19.2 → 0.23.0

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: b9970580930d293b15526952759b73e37053fe951d6156dd59db5ea656e12b6e
4
- data.tar.gz: a3ef5ee45d4a99bfcd15c467dc578e102d0c7ed6889e7bd1e7babe5149c3fac5
3
+ metadata.gz: 7bca107deda1051398ddcbc2e07373d9391b1bd28ca076d7610d164bd80ff24b
4
+ data.tar.gz: 70d72be64d6706cedc45c125d439c15502c8b7f9d75821646455b0a30466fbc6
5
5
  SHA512:
6
- metadata.gz: fad84ade7546e3556266307630c4091d6f45f7aa6f9587db45e8cff9d924dc420d481832bee6b508499487e2f33693f72ddbb47b5610401aea85cf0bc8474c46
7
- data.tar.gz: 1d47cdfdaa414c72bb3d678ba780f59531d7a2c2248219fc6a94d36a5e99b25a91db23ec273222cb7affece8df73669edad71dead347b910f9b25367e6222500
6
+ metadata.gz: a436f947e37fdf9642e48208d0dadae058499c9b9b99994819459be7b2a6819139c4c8f1651eb50fc52e8bcbe601417e0f8f7d1929d5420c36d50a6f39879024
7
+ data.tar.gz: 2bee228283223aa1c6bdeb29ffe54e72c2c7fe39b43a3e60f158d20e1fdeace5e68a53a02cafde29b91fee3e622b7ca6a9d8587599f657925cf25912c26676a9
@@ -0,0 +1,47 @@
1
+ ---
2
+ name: CI
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+
9
+ jobs:
10
+ lint:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby:
15
+ - 2.7
16
+ - 3.1
17
+ steps:
18
+ - name: Checkout
19
+ uses: actions/checkout@v3
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ bundler-cache: true
25
+ - name: Run Rubocop
26
+ run: bundle exec rubocop
27
+
28
+ test:
29
+ runs-on: ubuntu-latest
30
+ strategy:
31
+ matrix:
32
+ ruby:
33
+ - 2.7
34
+ - 3.1
35
+ env:
36
+ BOT_API_ENV: test
37
+ BOT_API_TOKEN: ${{ secrets.BOT_API_TOKEN }}
38
+ steps:
39
+ - name: Checkout
40
+ uses: actions/checkout@v3
41
+ - name: Set up Ruby
42
+ uses: ruby/setup-ruby@v1
43
+ with:
44
+ ruby-version: ${{ matrix.ruby }}
45
+ bundler-cache: true
46
+ - name: Run specs
47
+ run: bundle exec rspec
data/.rubocop.yml CHANGED
@@ -5,10 +5,15 @@ require:
5
5
 
6
6
  AllCops:
7
7
  NewCops: enable
8
+ TargetRubyVersion: 2.7
8
9
 
9
10
  Style/Documentation:
10
11
  Enabled: false
11
12
 
13
+ Style/FrozenStringLiteralComment:
14
+ Exclude:
15
+ - bin/console
16
+
12
17
  Metrics/BlockLength:
13
18
  IgnoredMethods:
14
19
  - context
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.23.0
4
+
5
+ - Rename `Telegram::Bot.configuration` options:
6
+ - `timeout` to `connection_timeout`
7
+ - `open_timeout` to `connection_open_timeout`
8
+ - Fix issue with missing default value for long-polling timeout
9
+
10
+ ## 0.21.0
11
+
12
+ - Implement [Bot API 6.1](https://core.telegram.org/bots/api#june-20-2022)
13
+ - Implement [Bot API 6.2](https://core.telegram.org/bots/api#august-12-2022)
14
+
15
+ ## 0.20.0
16
+
17
+ - Update `faraday` up to `2.0`
18
+
3
19
  ## 0.19.0
4
20
 
5
21
  - Implement [Bot API 6.0](https://core.telegram.org/bots/api-changelog#april-16-2022)
data/README.md CHANGED
@@ -3,8 +3,8 @@
3
3
  Ruby wrapper for [Telegram's Bot API](https://core.telegram.org/bots/api).
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/telegram-bot-ruby.svg)](http://badge.fury.io/rb/telegram-bot-ruby)
6
+ [![Build Status](https://github.com/atipugin/telegram-bot-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/atipugin/telegram-bot-ruby/actions)
6
7
  [![Maintainability](https://api.codeclimate.com/v1/badges/7e61fbf5bec86e118fb1/maintainability)](https://codeclimate.com/github/atipugin/telegram-bot-ruby/maintainability)
7
- [![Build Status](https://travis-ci.org/atipugin/telegram-bot-ruby.svg?branch=master)](https://travis-ci.org/atipugin/telegram-bot-ruby)
8
8
  [![Say Thanks!](https://img.shields.io/badge/Say%20Thanks!-🦉-1EAEDB.svg)](https://saythanks.io/to/atipugin)
9
9
 
10
10
  ## Installation
@@ -50,6 +50,9 @@ end
50
50
 
51
51
  Note that `bot.api` object implements [Telegram Bot API methods](https://core.telegram.org/bots/api#available-methods) as is. So you can invoke any method inside the block without any problems. All methods are available in both *snake_case* and *camelCase* notations.
52
52
 
53
+ If you need to start a bot on development mode you have to pass `enviroment: :test` <br>
54
+ example: `Telegram::Bot::Client.run(token, enviroment: :test)`
55
+
53
56
  Same thing about `message` object - it implements [Message](https://core.telegram.org/bots/api#message) spec, so you always know what to expect from it.
54
57
 
55
58
  ## Webhooks
data/examples/bot.rb CHANGED
@@ -7,13 +7,16 @@ token = 'replace-me-with-your-real-token'
7
7
 
8
8
  Telegram::Bot::Client.run(token) do |bot|
9
9
  bot.listen do |message|
10
- case message.text
11
- when '/start'
12
- bot.api.send_message(chat_id: message.chat.id, text: "Hello, #{message.from.first_name}!")
13
- when '/end'
14
- bot.api.send_message(chat_id: message.chat.id, text: "Bye, #{message.from.first_name}!")
15
- else
16
- bot.api.send_message(chat_id: message.chat.id, text: "I don't understand you :(")
10
+ case message
11
+ when Telegram::Bot::Types::Message
12
+ case message.text
13
+ when '/start'
14
+ bot.api.send_message(chat_id: message.chat.id, text: "Hello, #{message.from.first_name}!")
15
+ when '/end'
16
+ bot.api.send_message(chat_id: message.chat.id, text: "Bye, #{message.from.first_name}!")
17
+ else
18
+ bot.api.send_message(chat_id: message.chat.id, text: "I don't understand you :(")
19
+ end
17
20
  end
18
21
  end
19
22
  end
@@ -26,14 +26,15 @@ module Telegram
26
26
  approveChatJoinRequest declineChatJoinRequest banChatSenderChat
27
27
  unbanChatSenderChat answerWebAppQuery setChatMenuButton
28
28
  getChatMenuButton setMyDefaultAdministratorRights
29
- getMyDefaultAdministratorRights
29
+ getMyDefaultAdministratorRights createInvoiceLink
30
30
  ].freeze
31
31
 
32
- attr_reader :token, :url
32
+ attr_reader :token, :url, :environment
33
33
 
34
- def initialize(token, url: 'https://api.telegram.org')
34
+ def initialize(token, url: 'https://api.telegram.org', environment: :production)
35
35
  @token = token
36
36
  @url = url
37
+ @environment = environment.downcase.to_sym
37
38
  end
38
39
 
39
40
  def method_missing(method_name, *args, &block)
@@ -52,13 +53,13 @@ module Telegram
52
53
 
53
54
  def call(endpoint, raw_params = {})
54
55
  params = build_params(raw_params)
55
- response = conn.post("/bot#{token}/#{endpoint}", params)
56
- if response.status == 200
57
- JSON.parse(response.body)
58
- else
59
- raise Exceptions::ResponseError.new(response),
60
- 'Telegram API has returned the error.'
56
+ path = build_path(endpoint)
57
+ response = conn.post(path, params)
58
+ unless response.status == 200
59
+ raise Exceptions::ResponseError.new(response), 'Telegram API has returned the error.'
61
60
  end
61
+
62
+ JSON.parse(response.body)
62
63
  end
63
64
 
64
65
  private
@@ -69,6 +70,12 @@ module Telegram
69
70
  end
70
71
  end
71
72
 
73
+ def build_path(endpoint)
74
+ path = "/bot#{token}/"
75
+ path += 'test/' if environment == :test
76
+ path + endpoint
77
+ end
78
+
72
79
  def sanitize_value(value)
73
80
  jsonify_value(value)
74
81
  end
@@ -92,8 +99,8 @@ module Telegram
92
99
  faraday.request :multipart
93
100
  faraday.request :url_encoded
94
101
  faraday.adapter Telegram::Bot.configuration.adapter
95
- faraday.options.timeout = Telegram::Bot.configuration.timeout
96
- faraday.options.open_timeout = Telegram::Bot.configuration.open_timeout
102
+ faraday.options.timeout = Telegram::Bot.configuration.connection_timeout
103
+ faraday.options.open_timeout = Telegram::Bot.configuration.connection_open_timeout
97
104
  end
98
105
  end
99
106
  end
@@ -12,7 +12,7 @@ module Telegram
12
12
 
13
13
  def initialize(token, hash = {})
14
14
  @options = default_options.merge(hash)
15
- @api = Api.new(token, url: options.delete(:url))
15
+ @api = Api.new(token, url: options.delete(:url), environment: options.delete(:environment))
16
16
  @logger = options.delete(:logger)
17
17
  end
18
18
 
@@ -52,8 +52,10 @@ module Telegram
52
52
  def default_options
53
53
  {
54
54
  offset: 0,
55
+ timeout: 20,
55
56
  logger: NullLogger.new,
56
- url: 'https://api.telegram.org'
57
+ url: 'https://api.telegram.org',
58
+ environment: :production
57
59
  }
58
60
  end
59
61
 
@@ -3,12 +3,12 @@
3
3
  module Telegram
4
4
  module Bot
5
5
  class Configuration
6
- attr_accessor :adapter, :open_timeout, :timeout
6
+ attr_accessor :adapter, :connection_open_timeout, :connection_timeout
7
7
 
8
8
  def initialize
9
9
  @adapter = Faraday.default_adapter
10
- @open_timeout = 20
11
- @timeout = 20
10
+ @connection_open_timeout = 20
11
+ @connection_timeout = 20
12
12
  end
13
13
  end
14
14
  end
@@ -17,6 +17,9 @@ module Telegram
17
17
  attribute :photo, ChatPhoto
18
18
  attribute :bio, String
19
19
  attribute :has_private_forwards, Boolean
20
+ attribute :has_restricted_voice_and_video_messages, Boolean
21
+ attribute :join_to_send_messages, Boolean
22
+ attribute :join_by_request, Boolean
20
23
  attribute :description, String
21
24
  attribute :invite_link, String
22
25
  attribute :pinned_message, 'Telegram::Bot::Types::Message'
@@ -26,7 +29,6 @@ module Telegram
26
29
  attribute :has_protected_content, Boolean
27
30
  attribute :sticker_set_name, String
28
31
  attribute :can_set_sticker_set, Boolean
29
- attribute :all_members_are_administrators, Boolean
30
32
  attribute :linked_chat_id, Integer
31
33
  attribute :location, ChatLocation
32
34
  end
@@ -5,7 +5,7 @@ module Telegram
5
5
  module Types
6
6
  module Compactable
7
7
  def to_compact_hash
8
- attributes.dup.delete_if { |_, v| v.nil? }.map do |key, value|
8
+ attributes.dup.delete_if { |_, v| v.nil? }.to_h do |key, value|
9
9
  value =
10
10
  if value.respond_to?(:to_compact_hash)
11
11
  value.to_compact_hash
@@ -14,7 +14,7 @@ module Telegram
14
14
  end
15
15
 
16
16
  [key, value]
17
- end.to_h
17
+ end
18
18
  end
19
19
 
20
20
  def to_json(*args)
@@ -10,6 +10,7 @@ module Telegram
10
10
  attribute :url, String
11
11
  attribute :user, User
12
12
  attribute :language, String
13
+ attribute :custom_emoji_id, String
13
14
  end
14
15
  end
15
16
  end
@@ -6,6 +6,7 @@ module Telegram
6
6
  class Sticker < Base
7
7
  attribute :file_id, String
8
8
  attribute :file_unique_id, String
9
+ attribute :type, String
9
10
  attribute :width, Integer
10
11
  attribute :height, Integer
11
12
  attribute :is_animated, Boolean
@@ -13,7 +14,9 @@ module Telegram
13
14
  attribute :thumb, PhotoSize
14
15
  attribute :emoji, String
15
16
  attribute :set_name, String
17
+ attribute :premium_animation, File
16
18
  attribute :mask_position, MaskPosition
19
+ attribute :custom_emoji_id, String
17
20
  attribute :file_size, Integer
18
21
  end
19
22
  end
@@ -6,6 +6,7 @@ module Telegram
6
6
  class StickerSet < Base
7
7
  attribute :name, String
8
8
  attribute :title, String
9
+ attribute :sticker_type, String
9
10
  attribute :is_animated, Boolean
10
11
  attribute :is_video, Boolean
11
12
  attribute :contains_masks, Boolean
@@ -10,6 +10,8 @@ module Telegram
10
10
  attribute :last_name, String
11
11
  attribute :username, String
12
12
  attribute :language_code, String
13
+ attribute :is_premium, Boolean
14
+ attribute :added_to_attachment_menu, Boolean
13
15
  attribute :can_join_groups, Boolean
14
16
  attribute :can_read_all_group_messages, Boolean
15
17
  attribute :supports_inline_queries, Boolean
@@ -3,6 +3,7 @@
3
3
  require 'telegram/bot/types/compactable'
4
4
  require 'telegram/bot/types/pattern_matching'
5
5
  require 'telegram/bot/types/base'
6
+ require 'telegram/bot/types/file'
6
7
  require 'telegram/bot/types/user'
7
8
  require 'telegram/bot/types/photo_size'
8
9
  require 'telegram/bot/types/audio'
@@ -95,7 +96,6 @@ require 'telegram/bot/types/keyboard_button'
95
96
  require 'telegram/bot/types/reply_keyboard_markup'
96
97
  require 'telegram/bot/types/reply_keyboard_remove'
97
98
  require 'telegram/bot/types/force_reply'
98
- require 'telegram/bot/types/file'
99
99
  require 'telegram/bot/types/shipping_option'
100
100
  require 'telegram/bot/types/chat_invite_link'
101
101
  require 'telegram/bot/types/chat_member'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Telegram
4
4
  module Bot
5
- VERSION = '0.19.2'
5
+ VERSION = '0.23.0'
6
6
  end
7
7
  end
data/lib/telegram/bot.rb CHANGED
@@ -4,6 +4,7 @@ require 'virtus'
4
4
  require 'logger'
5
5
  require 'json'
6
6
  require 'faraday'
7
+ require 'faraday/multipart'
7
8
 
8
9
  require 'telegram/bot/types'
9
10
  require 'telegram/bot/exceptions'
@@ -19,8 +19,12 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ['lib']
21
21
 
22
+ spec.required_ruby_version = '>= 2.7'
23
+ spec.metadata['rubygems_mfa_required'] = 'true'
24
+
22
25
  spec.add_dependency 'dry-inflector'
23
- spec.add_dependency 'faraday', '~> 1.0'
26
+ spec.add_dependency 'faraday', '~> 2.0'
27
+ spec.add_dependency 'faraday-multipart', '~> 1.0'
24
28
  spec.add_dependency 'virtus', '~> 2.0'
25
29
 
26
30
  spec.add_development_dependency 'pry'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telegram-bot-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.2
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Tipugin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-19 00:00:00.000000000 Z
11
+ date: 2022-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-inflector
@@ -26,6 +26,20 @@ dependencies:
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday-multipart
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
@@ -143,10 +157,10 @@ executables: []
143
157
  extensions: []
144
158
  extra_rdoc_files: []
145
159
  files:
160
+ - ".github/workflows/ci.yml"
146
161
  - ".gitignore"
147
162
  - ".rspec"
148
163
  - ".rubocop.yml"
149
- - ".travis.yml"
150
164
  - CHANGELOG.md
151
165
  - Gemfile
152
166
  - LICENSE
@@ -290,7 +304,8 @@ files:
290
304
  - telegram-bot-ruby.gemspec
291
305
  homepage: https://github.com/atipugin/telegram-bot
292
306
  licenses: []
293
- metadata: {}
307
+ metadata:
308
+ rubygems_mfa_required: 'true'
294
309
  post_install_message:
295
310
  rdoc_options: []
296
311
  require_paths:
@@ -299,14 +314,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
299
314
  requirements:
300
315
  - - ">="
301
316
  - !ruby/object:Gem::Version
302
- version: '0'
317
+ version: '2.7'
303
318
  required_rubygems_version: !ruby/object:Gem::Requirement
304
319
  requirements:
305
320
  - - ">="
306
321
  - !ruby/object:Gem::Version
307
322
  version: '0'
308
323
  requirements: []
309
- rubygems_version: 3.3.3
324
+ rubygems_version: 3.3.7
310
325
  signing_key:
311
326
  specification_version: 4
312
327
  summary: Ruby wrapper for Telegram's Bot API
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.6.6
4
- - 2.7.2
5
- script:
6
- - bundle exec rubocop
7
- - bundle exec rspec