telegram-bot-ruby 0.21.0 → 0.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +47 -0
- data/.rubocop.yml +5 -0
- data/README.md +4 -1
- data/examples/bot.rb +10 -7
- data/lib/telegram/bot/api.rb +15 -8
- data/lib/telegram/bot/client.rb +3 -2
- data/lib/telegram/bot/types/compactable.rb +2 -2
- data/lib/telegram/bot/types.rb +1 -1
- 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: f8030abc5a162f5722c34de4e39f57dfd7f772799b52c6c9f343222bd096ba13
|
4
|
+
data.tar.gz: 1b76a2b67b4843d2441ffed6f2b464fafee7dda4ebe2479517574bc6bd58779e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be56c3408f95d8767939d973fd1b91c0cd990ec4c7119c5d868e3af5e6662a5f884109006713f0eabf231fa7e0816c85b221574bf12f9439a06c368dabc96943
|
7
|
+
data.tar.gz: 2737d5f9fb49fbb08343b632eaab7a7e61f25c27665424c25d4a4e54e1986ddc82b627a7018565da35a65968bc42e2b7098da0b5c7702db2fc10b8f459a233ed
|
@@ -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/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
|
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
|
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
|
|
@@ -53,7 +53,8 @@ module Telegram
|
|
53
53
|
{
|
54
54
|
offset: 0,
|
55
55
|
logger: NullLogger.new,
|
56
|
-
url: 'https://api.telegram.org'
|
56
|
+
url: 'https://api.telegram.org',
|
57
|
+
environment: :production
|
57
58
|
}
|
58
59
|
end
|
59
60
|
|
@@ -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/types.rb
CHANGED
@@ -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'
|
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.22.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-19 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
|
- - ">="
|