telegram-bot-ruby 0.21.1 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +47 -0
- data/.rubocop.yml +5 -0
- data/CHANGELOG.md +7 -0
- data/README.md +4 -1
- data/examples/bot.rb +10 -7
- data/lib/telegram/bot/api.rb +17 -10
- data/lib/telegram/bot/client.rb +4 -2
- data/lib/telegram/bot/configuration.rb +3 -3
- data/lib/telegram/bot/types/compactable.rb +2 -2
- data/lib/telegram/bot/version.rb +1 -1
- data/telegram-bot-ruby.gemspec +3 -0
- metadata +6 -5
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bca107deda1051398ddcbc2e07373d9391b1bd28ca076d7610d164bd80ff24b
|
4
|
+
data.tar.gz: 70d72be64d6706cedc45c125d439c15502c8b7f9d75821646455b0a30466fbc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
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
|
+
|
3
10
|
## 0.21.0
|
4
11
|
|
5
12
|
- Implement [Bot API 6.1](https://core.telegram.org/bots/api#june-20-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
|
[](http://badge.fury.io/rb/telegram-bot-ruby)
|
6
|
+
[](https://github.com/atipugin/telegram-bot-ruby/actions)
|
6
7
|
[](https://codeclimate.com/github/atipugin/telegram-bot-ruby/maintainability)
|
7
|
-
[](https://travis-ci.org/atipugin/telegram-bot-ruby)
|
8
8
|
[](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
|
11
|
-
when
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
data/lib/telegram/bot/api.rb
CHANGED
@@ -29,11 +29,12 @@ module Telegram
|
|
29
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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.
|
96
|
-
faraday.options.open_timeout = Telegram::Bot.configuration.
|
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
|
data/lib/telegram/bot/client.rb
CHANGED
@@ -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, :
|
6
|
+
attr_accessor :adapter, :connection_open_timeout, :connection_timeout
|
7
7
|
|
8
8
|
def initialize
|
9
9
|
@adapter = Faraday.default_adapter
|
10
|
-
@
|
11
|
-
@
|
10
|
+
@connection_open_timeout = 20
|
11
|
+
@connection_timeout = 20
|
12
12
|
end
|
13
13
|
end
|
14
14
|
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? }.
|
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
|
17
|
+
end
|
18
18
|
end
|
19
19
|
|
20
20
|
def to_json(*args)
|
data/lib/telegram/bot/version.rb
CHANGED
data/telegram-bot-ruby.gemspec
CHANGED
@@ -19,6 +19,9 @@ 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
26
|
spec.add_dependency 'faraday', '~> 2.0'
|
24
27
|
spec.add_dependency 'faraday-multipart', '~> 1.0'
|
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.
|
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-
|
11
|
+
date: 2022-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-inflector
|
@@ -157,10 +157,10 @@ executables: []
|
|
157
157
|
extensions: []
|
158
158
|
extra_rdoc_files: []
|
159
159
|
files:
|
160
|
+
- ".github/workflows/ci.yml"
|
160
161
|
- ".gitignore"
|
161
162
|
- ".rspec"
|
162
163
|
- ".rubocop.yml"
|
163
|
-
- ".travis.yml"
|
164
164
|
- CHANGELOG.md
|
165
165
|
- Gemfile
|
166
166
|
- LICENSE
|
@@ -304,7 +304,8 @@ files:
|
|
304
304
|
- telegram-bot-ruby.gemspec
|
305
305
|
homepage: https://github.com/atipugin/telegram-bot
|
306
306
|
licenses: []
|
307
|
-
metadata:
|
307
|
+
metadata:
|
308
|
+
rubygems_mfa_required: 'true'
|
308
309
|
post_install_message:
|
309
310
|
rdoc_options: []
|
310
311
|
require_paths:
|
@@ -313,7 +314,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
313
314
|
requirements:
|
314
315
|
- - ">="
|
315
316
|
- !ruby/object:Gem::Version
|
316
|
-
version: '
|
317
|
+
version: '2.7'
|
317
318
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
318
319
|
requirements:
|
319
320
|
- - ">="
|