telegram-bot-ruby 0.8.3 → 0.8.4

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
  SHA1:
3
- metadata.gz: c6f6cfeeb86c2fef83ec55beb9de0d3f72729e42
4
- data.tar.gz: 6be069ef2d2df8ff9ca36248d26353311c5a29c3
3
+ metadata.gz: f01d9b0fd236b5c87c09deccacdba46363e55148
4
+ data.tar.gz: bfa4dececda70c249f63ad9ff4bf5e09f766620d
5
5
  SHA512:
6
- metadata.gz: b51532587af460e2fbe1a04b4014b6583ebcb6841e7abe457ecd1e575550681ddaa8ad0d221ee852c9bed62b5064641ac7e2a78906285ab01daaf38e083fa769
7
- data.tar.gz: fa0df882d0c9c61726d8eccfb6cda2b746f7634ab50ec451ce34aeaf86ced773149c9bb69d91c3e3b8e73d421589d673edbfd0bb135fae21732f95e959e937ba
6
+ metadata.gz: 03f6f64efcd6ec0bf0b9c3dcd94c05f5a34d08dfaa5b22ede9e2d378afc236d1f9241c32167536324fcb26d7208f60e5953293dffb9801970931b24a9bbbc96b
7
+ data.tar.gz: c886b45e77283d3dc1bbbb078b07994a492e75f3a50799d0a07a00f2e7e2ed6a8412fb03b1d4a209145f6a5f150b85e9e13266b3ac0c623485a1c10b3a4c9734
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.4
4
+
5
+ - Implement [Bot API 3.3](https://core.telegram.org/bots/api#august-23-2017) (thx [@ivanovaleksey][])
6
+
3
7
  ## 0.8.3
4
8
 
5
9
  - Implement [Bot API 3.2](https://core.telegram.org/bots/api#july-21-2017) (thx [@ivanovaleksey][])
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`):
@@ -1,4 +1,5 @@
1
1
  require 'virtus'
2
+ require 'inflecto'
2
3
  require 'logger'
3
4
  require 'json'
4
5
  require 'faraday'
@@ -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 = extract_message(update)
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(
@@ -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 < Base
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
@@ -3,6 +3,7 @@ module Telegram
3
3
  module Types
4
4
  class User < Base
5
5
  attribute :id, Integer
6
+ attribute :is_bot, Boolean
6
7
  attribute :first_name, String
7
8
  attribute :last_name, String
8
9
  attribute :username, String
@@ -1,5 +1,5 @@
1
1
  module Telegram
2
2
  module Bot
3
- VERSION = '0.8.3'.freeze
3
+ VERSION = '0.8.4'.freeze
4
4
  end
5
5
  end
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_dependency 'faraday'
21
21
  spec.add_dependency 'virtus'
22
+ spec.add_dependency 'inflecto'
22
23
 
23
24
  spec.add_development_dependency 'bundler', '~> 1.9'
24
25
  spec.add_development_dependency 'rake', '~> 10.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.8.3
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-08-01 00:00:00.000000000 Z
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
@@ -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