telegram-bot-ruby 0.8.3 → 0.8.4
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/CHANGELOG.md +4 -0
- data/README.md +0 -27
- data/lib/telegram/bot.rb +1 -0
- data/lib/telegram/bot/client.rb +1 -12
- data/lib/telegram/bot/types.rb +3 -0
- data/lib/telegram/bot/types/base.rb +1 -13
- data/lib/telegram/bot/types/chat.rb +5 -1
- data/lib/telegram/bot/types/compactable.rb +20 -0
- data/lib/telegram/bot/types/message.rb +2 -0
- data/lib/telegram/bot/types/update.rb +5 -0
- data/lib/telegram/bot/types/user.rb +1 -0
- data/lib/telegram/bot/version.rb +1 -1
- data/telegram-bot-ruby.gemspec +1 -0
- metadata +17 -4
- data/lib/telegram/bot/botan.rb +0 -21
- data/lib/telegram/bot/botan/api.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f01d9b0fd236b5c87c09deccacdba46363e55148
|
4
|
+
data.tar.gz: bfa4dececda70c249f63ad9ff4bf5e09f766620d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03f6f64efcd6ec0bf0b9c3dcd94c05f5a34d08dfaa5b22ede9e2d378afc236d1f9241c32167536324fcb26d7208f60e5953293dffb9801970931b24a9bbbc96b
|
7
|
+
data.tar.gz: c886b45e77283d3dc1bbbb078b07994a492e75f3a50799d0a07a00f2e7e2ed6a8412fb03b1d4a209145f6a5f150b85e9e13266b3ac0c623485a1c10b3a4c9734
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -171,33 +171,6 @@ Telegram::Bot::Client.run(token, logger: Logger.new($stderr)) do |bot|
|
|
171
171
|
end
|
172
172
|
```
|
173
173
|
|
174
|
-
## Botan.io support
|
175
|
-
|
176
|
-
Gem provides support of [Botan.io](http://botan.io/) analytics out of box. All you need is to obtain a token (follow the instructions from https://github.com/botanio/sdk). To track events you're interested in just call `#track` method. See example below:
|
177
|
-
|
178
|
-
```ruby
|
179
|
-
require 'telegram/bot'
|
180
|
-
require 'telegram/bot/botan' # Botan.io extension isn't loaded by default, so make sure you required it.
|
181
|
-
|
182
|
-
token = 'YOUR_TELEGRAM_BOT_API_TOKEN'
|
183
|
-
|
184
|
-
Telegram::Bot::Client.run(token) do |bot|
|
185
|
-
bot.enable_botan!('YOUR_BOTAN_TOKEN')
|
186
|
-
bot.listen do |message|
|
187
|
-
case message.text
|
188
|
-
when '/start'
|
189
|
-
bot.track('Started', message.from.id, type_of_chat: message.chat.class.name)
|
190
|
-
# ...
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
```
|
195
|
-
|
196
|
-
`#track` method accepts 3 arguments:
|
197
|
-
- name of event (required)
|
198
|
-
- Telegram's user id (required)
|
199
|
-
- hash of additional properties (optional)
|
200
|
-
|
201
174
|
## Connection adapters
|
202
175
|
|
203
176
|
Since version `0.5.0` we rely on [faraday](https://github.com/lostisland/faraday) under the hood. You can use any of supported adapters (for example, `net/http/persistent`):
|
data/lib/telegram/bot.rb
CHANGED
data/lib/telegram/bot/client.rb
CHANGED
@@ -33,7 +33,7 @@ module Telegram
|
|
33
33
|
response['result'].each do |data|
|
34
34
|
update = Types::Update.new(data)
|
35
35
|
@options[:offset] = update.update_id.next
|
36
|
-
message =
|
36
|
+
message = update.current_message
|
37
37
|
log_incoming_message(message)
|
38
38
|
yield message
|
39
39
|
end
|
@@ -47,17 +47,6 @@ module Telegram
|
|
47
47
|
{ offset: 0, timeout: 20, logger: NullLogger.new }
|
48
48
|
end
|
49
49
|
|
50
|
-
def extract_message(update)
|
51
|
-
types = %w(inline_query
|
52
|
-
chosen_inline_result
|
53
|
-
callback_query
|
54
|
-
edited_message
|
55
|
-
message
|
56
|
-
channel_post
|
57
|
-
edited_channel_post)
|
58
|
-
types.inject(nil) { |acc, elem| acc || update.public_send(elem) }
|
59
|
-
end
|
60
|
-
|
61
50
|
def log_incoming_message(message)
|
62
51
|
uid = message.from ? message.from.id : nil
|
63
52
|
logger.info(
|
data/lib/telegram/bot/types.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'telegram/bot/types/compactable'
|
1
2
|
require 'telegram/bot/types/base'
|
2
3
|
require 'telegram/bot/types/user'
|
3
4
|
require 'telegram/bot/types/audio'
|
@@ -66,3 +67,5 @@ require 'telegram/bot/types/labeled_price'
|
|
66
67
|
require 'telegram/bot/types/shipping_option'
|
67
68
|
require 'telegram/bot/types/chat_member'
|
68
69
|
require 'telegram/bot/types/user_profile_photos'
|
70
|
+
|
71
|
+
Virtus.finalize
|
@@ -3,19 +3,7 @@ module Telegram
|
|
3
3
|
module Types
|
4
4
|
class Base
|
5
5
|
include Virtus.model
|
6
|
-
|
7
|
-
def to_compact_hash
|
8
|
-
Hash[attributes.dup.delete_if { |_, v| v.nil? }.map do |key, value|
|
9
|
-
value =
|
10
|
-
if value.class.ancestors.include?(Telegram::Bot::Types::Base)
|
11
|
-
value.to_compact_hash
|
12
|
-
else
|
13
|
-
value
|
14
|
-
end
|
15
|
-
|
16
|
-
[key, value]
|
17
|
-
end]
|
18
|
-
end
|
6
|
+
include Compactable
|
19
7
|
end
|
20
8
|
end
|
21
9
|
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
module Telegram
|
2
2
|
module Bot
|
3
3
|
module Types
|
4
|
-
class Chat
|
4
|
+
class Chat
|
5
|
+
include Virtus.model(finalize: false)
|
6
|
+
include Compactable
|
7
|
+
|
5
8
|
attribute :id, Integer
|
6
9
|
attribute :type, String
|
7
10
|
attribute :title, String
|
@@ -12,6 +15,7 @@ module Telegram
|
|
12
15
|
attribute :photo, ChatPhoto
|
13
16
|
attribute :description, String
|
14
17
|
attribute :invite_link, String
|
18
|
+
attribute :pinned_message, 'Telegram::Bot::Types::Message'
|
15
19
|
end
|
16
20
|
end
|
17
21
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Telegram
|
2
|
+
module Bot
|
3
|
+
module Types
|
4
|
+
module Compactable
|
5
|
+
def to_compact_hash
|
6
|
+
Hash[attributes.dup.delete_if { |_, v| v.nil? }.map do |key, value|
|
7
|
+
value =
|
8
|
+
if value.class.ancestors.include?(Telegram::Bot::Types::Base)
|
9
|
+
value.to_compact_hash
|
10
|
+
else
|
11
|
+
value
|
12
|
+
end
|
13
|
+
|
14
|
+
[key, value]
|
15
|
+
end]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -9,9 +9,11 @@ module Telegram
|
|
9
9
|
attribute :forward_from, User
|
10
10
|
attribute :forward_from_chat, Chat
|
11
11
|
attribute :forward_from_message_id, Integer
|
12
|
+
attribute :forward_signature, String
|
12
13
|
attribute :forward_date, Integer
|
13
14
|
attribute :reply_to_message, Message
|
14
15
|
attribute :edit_date, Integer
|
16
|
+
attribute :author_signature, String
|
15
17
|
attribute :text, String
|
16
18
|
attribute :entities, Array[MessageEntity]
|
17
19
|
attribute :audio, Audio
|
@@ -12,6 +12,11 @@ module Telegram
|
|
12
12
|
attribute :callback_query, CallbackQuery
|
13
13
|
attribute :shipping_query, ShippingQuery
|
14
14
|
attribute :pre_checkout_query, PreCheckoutQuery
|
15
|
+
|
16
|
+
def current_message
|
17
|
+
@current_message ||=
|
18
|
+
Hash[*attributes.find { |k, v| k != :update_id && v }].values.first
|
19
|
+
end
|
15
20
|
end
|
16
21
|
end
|
17
22
|
end
|
data/lib/telegram/bot/version.rb
CHANGED
data/telegram-bot-ruby.gemspec
CHANGED
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.8.
|
4
|
+
version: 0.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Tipugin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: inflecto
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,8 +157,6 @@ files:
|
|
143
157
|
- examples/bot.rb
|
144
158
|
- lib/telegram/bot.rb
|
145
159
|
- lib/telegram/bot/api.rb
|
146
|
-
- lib/telegram/bot/botan.rb
|
147
|
-
- lib/telegram/bot/botan/api.rb
|
148
160
|
- lib/telegram/bot/client.rb
|
149
161
|
- lib/telegram/bot/configuration.rb
|
150
162
|
- lib/telegram/bot/exceptions.rb
|
@@ -161,6 +173,7 @@ files:
|
|
161
173
|
- lib/telegram/bot/types/chat_member.rb
|
162
174
|
- lib/telegram/bot/types/chat_photo.rb
|
163
175
|
- lib/telegram/bot/types/chosen_inline_result.rb
|
176
|
+
- lib/telegram/bot/types/compactable.rb
|
164
177
|
- lib/telegram/bot/types/contact.rb
|
165
178
|
- lib/telegram/bot/types/document.rb
|
166
179
|
- lib/telegram/bot/types/file.rb
|
data/lib/telegram/bot/botan.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'telegram/bot/botan/api'
|
2
|
-
|
3
|
-
module Telegram
|
4
|
-
module Bot
|
5
|
-
module Botan
|
6
|
-
attr_reader :botan
|
7
|
-
|
8
|
-
def enable_botan!(token)
|
9
|
-
@botan ||= Botan::Api.new(token)
|
10
|
-
end
|
11
|
-
|
12
|
-
def track(*args)
|
13
|
-
botan.track(*args) if defined?(botan)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
if defined?(Telegram::Bot::Client)
|
20
|
-
Telegram::Bot::Client.send(:include, Telegram::Bot::Botan)
|
21
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Telegram
|
2
|
-
module Bot
|
3
|
-
module Botan
|
4
|
-
class Api
|
5
|
-
attr_reader :token
|
6
|
-
|
7
|
-
def initialize(token)
|
8
|
-
@token = token
|
9
|
-
end
|
10
|
-
|
11
|
-
def track(event, uid, properties = {})
|
12
|
-
query_str = URI.encode_www_form(token: token, name: event, uid: uid)
|
13
|
-
conn.post("/track?#{query_str}", properties.to_json)
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def conn
|
19
|
-
@conn ||= Faraday.new(url: 'https://api.botan.io') do |faraday|
|
20
|
-
faraday.request :url_encoded
|
21
|
-
faraday.adapter Telegram::Bot.configuration.adapter
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|