telegram-bot 0.7.4 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b21ff9c397fda79a83ef6ff4e2c67baaf2d49755
4
- data.tar.gz: 0bb03cd6e521d6ab7ad20b23b18da992e0f4464b
3
+ metadata.gz: cd93b336f2b1953328663119cc121ff43ff00fee
4
+ data.tar.gz: 7be5d289e11d1fb3c45ac1557923265fa23a35bf
5
5
  SHA512:
6
- metadata.gz: 9c6ccdf272c91d9a65a26beb1f31598c7294af91edc3d63268517d0da18fe3f61fa91ff31c7367094a00fe97a725027842bacd2bec848a3c7bc0fc5fbc7741b2
7
- data.tar.gz: 511a05ba78a2801a8e868f3e6ab6918a62e91bb9f0a734026189048164755533e6222a5d578456e86ca80100017085a4ccabd72e981a6dafdf244b612339130c
6
+ metadata.gz: 8a28a28b2650f95f1360d6d7e015ea959e6f5e79d9d93c809468db1319087dffd7c5c69294f2f06ef429246b5860267d047a16c6f9f779b583b44fcc5ef52b0a
7
+ data.tar.gz: 1af5cc258b0b0e453369b3a52bb3fb5231b568de23b0f132aac24a779c6c557dadbd37d6f487922062c740bc1cd1f285fb655b8837c63ddb391622d8e45436d4
data/.travis.yml CHANGED
@@ -2,5 +2,8 @@ language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
4
  - 2.2.3
5
+ env:
6
+ - RAILS=4
7
+ - RAILS=5
5
8
  notifications:
6
9
  email: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ # 0.8.0
2
+
3
+ - Fixed `#reply_with`, now it sets `reply_to_message_id` as it's supposed to.
4
+ Added `#respond_with` which works the same way, but doesn't set `reply_to_message_id`.
5
+ Please, replace all occurrences of `reply_with` to `respond_with` to
6
+ keep it working the old way.
7
+ - Fixes for Rails 5:
8
+ - Controller callbacks
9
+ - Middleware
10
+ - Setup travis builds
11
+
1
12
  # 0.7.4
2
13
 
3
14
  - Rails 5 support by @dreyks (#4).
data/Gemfile CHANGED
@@ -1,6 +1,13 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
+ case ENV['RAILS']
5
+ when '5'
6
+ gem 'actionpack', '5.0.0.rc1'
7
+ when '4'
8
+ gem 'actionpack', '~> 4.2'
9
+ end
10
+
4
11
  group :development do
5
12
  gem 'sdoc', '~> 0.4.1'
6
13
  gem 'pry', '~> 0.10.1'
data/README.md CHANGED
@@ -131,9 +131,10 @@ class Telegram::WebhookController < Telegram::Bot::UpdatesController
131
131
 
132
132
  # There are `chat` & `from` shortcut methods.
133
133
  response = from ? "Hello #{from['username']}!" : 'Hi there!'
134
- # There is `reply_with` helper to set basic fields
135
- # like `reply_to_message` & `chat_id`.
136
- reply_with :message, text: response
134
+ # There is `respond_with` helper to set `chat_id` from received message:
135
+ respond_with :message, text: response
136
+ # `reply_with` also sets `reply_to_message_id`:
137
+ reply_with :photo, photo: File.open('party.jpg')
137
138
  end
138
139
 
139
140
  private
@@ -188,7 +189,7 @@ class Telegram::WebhookController < Telegram::Bot::UpdatesController
188
189
  end
189
190
 
190
191
  def read
191
- reply_with :message, text: session[:text]
192
+ respond_with :message, text: session[:text]
192
193
  end
193
194
 
194
195
  private
@@ -214,23 +215,23 @@ class Telegram::WebhookController < Telegram::Bot::UpdatesController
214
215
  def rename(*)
215
216
  # set context for the next message
216
217
  save_context :rename
217
- reply_with :message, text: 'What name do you like?'
218
+ respond_with :message, text: 'What name do you like?'
218
219
  end
219
220
 
220
221
  # register context handlers to handle this context
221
222
  context_handler :rename do |*words|
222
223
  update_name words[0]
223
- reply_with :message, text: 'Renamed!'
224
+ respond_with :message, text: 'Renamed!'
224
225
  end
225
226
 
226
227
  # You can do it in other way:
227
228
  def rename(name = nil, *)
228
229
  if name
229
230
  update_name name
230
- reply_with :message, text: 'Renamed!'
231
+ respond_with :message, text: 'Renamed!'
231
232
  else
232
233
  save_context :rename
233
- reply_with :message, text: 'What name do you like?'
234
+ respond_with :message, text: 'What name do you like?'
234
235
  end
235
236
  end
236
237
 
@@ -383,6 +384,16 @@ To release a new version, update the version number in `version.rb`,
383
384
  and then run `bundle exec rake release`, which will create a git tag for the version,
384
385
  push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
385
386
 
387
+ ### Different Rails versions
388
+
389
+ To setup development for specific major Rails version use:
390
+
391
+ ```
392
+ RAILS=5 bundle install
393
+ # or
394
+ RAILS=5 bundle update
395
+ ```
396
+
386
397
  ## Contributing
387
398
 
388
399
  Bug reports and pull requests are welcome on GitHub at https://github.com/telegram-bot-rb/telegram-bot.
@@ -1,6 +1,8 @@
1
1
  require 'active_support/concern'
2
+ require 'active_support/core_ext/hash/indifferent_access'
3
+ require 'active_support/json'
2
4
  require 'action_dispatch/http/mime_type'
3
- require 'action_dispatch/middleware/params_parser'
5
+ require 'action_dispatch/http/request'
4
6
 
5
7
  module Telegram
6
8
  module Bot
@@ -13,7 +15,8 @@ module Telegram
13
15
  end
14
16
 
15
17
  def call(env)
16
- update = env['action_dispatch.request.request_parameters']
18
+ request = ActionDispatch::Request.new(env)
19
+ update = request.request_parameters
17
20
  controller.dispatch(bot, update)
18
21
  [200, {}, ['']]
19
22
  end
@@ -21,7 +21,7 @@ module Telegram
21
21
  # end
22
22
  #
23
23
  # def help(*)
24
- # reply_with :message, text:
24
+ # respond_with :message, text:
25
25
  # end
26
26
  #
27
27
  # To process plain text messages (without commands) or other updates just
@@ -29,7 +29,7 @@ module Telegram
29
29
  # as an argument.
30
30
  #
31
31
  # def message(message)
32
- # reply_with :message, text: "Echo: #{message['text']}"
32
+ # respond_with :message, text: "Echo: #{message['text']}"
33
33
  # end
34
34
  #
35
35
  # def inline_query(query)
@@ -63,7 +63,7 @@ module Telegram
63
63
 
64
64
  include AbstractController::Callbacks
65
65
  # Redefine callbacks with default terminator.
66
- if ActiveSupport.gem_version >= Gem::Version.new('5')
66
+ if ActiveSupport::VERSION::MAJOR >= 5
67
67
  define_callbacks :process_action,
68
68
  skip_after_callbacks_if_terminated: true
69
69
  else
@@ -35,13 +35,13 @@ module Telegram
35
35
  end
36
36
  end
37
37
 
38
- def reply_with(type, *)
39
- Instrumentation.instrument(:reply_with, type: type) { super }
38
+ def respond_with(type, *)
39
+ Instrumentation.instrument(:respond_with, type: type) { super }
40
40
  end
41
41
 
42
42
  %i(answer_callback_query answer_inline_query).each do |type|
43
43
  define_method(type) do |*args|
44
- Instrumentation.instrument(:reply_with, type: type) { super(*args) }
44
+ Instrumentation.instrument(:respond_with, type: type) { super(*args) }
45
45
  end
46
46
  end
47
47
 
@@ -22,8 +22,8 @@ module Telegram
22
22
  end
23
23
  end
24
24
 
25
- def reply_with(event)
26
- info { "Replied with #{event.payload[:type]}" }
25
+ def respond_with(event)
26
+ info { "Responded with #{event.payload[:type]}" }
27
27
  end
28
28
 
29
29
  def halted_callback(event)
@@ -2,21 +2,23 @@ module Telegram
2
2
  module Bot
3
3
  class UpdatesController
4
4
  module ReplyHelpers
5
- # Helper to call bot's `send_#{type}` method with already set `chat_id` and
6
- # `reply_to_message_id`:
5
+ # Helper to call bot's `send_#{type}` method with already set `chat_id`:
7
6
  #
8
- # reply_with :message, text: 'Hello!'
9
- # reply_with :message, text: '__Hello!__', parse_mode: :Markdown
10
- # reply_with :photo, photo: File.open(photo_to_send), caption: "It's incredible!"
11
- def reply_with(type, params)
12
- method = "send_#{type}"
7
+ # respond_with :message, text: 'Hello!'
8
+ # respond_with :message, text: '__Hello!__', parse_mode: :Markdown
9
+ # respond_with :photo, photo: File.open(photo_to_send), caption: "It's incredible!"
10
+ def respond_with(type, params)
13
11
  chat = self.chat
12
+ chat_id = chat && chat['id'] or raise 'Can not respond_with when chat is not present'
13
+ bot.public_send("send_#{type}", params.merge(chat_id: chat_id))
14
+ end
15
+
16
+ # Same as respond_with but also sets `reply_to_message_id`.
17
+ def reply_with(type, params)
14
18
  payload = self.payload
15
- params = params.merge(
16
- chat_id: (chat && chat['id'] or raise 'Can not reply_with when chat is not present'),
17
- reply_to_message: payload && payload['message_id'],
18
- )
19
- bot.public_send(method, params)
19
+ message_id = payload && payload['message_id']
20
+ params = params.merge(reply_to_message_id: message_id) if message_id
21
+ respond_with(type, params)
20
22
  end
21
23
 
22
24
  # Same as reply_with, but for inline queries.
@@ -1,6 +1,6 @@
1
1
  module Telegram
2
2
  module Bot
3
- VERSION = '0.7.4'.freeze
3
+ VERSION = '0.8.0'.freeze
4
4
 
5
5
  def self.gem_version
6
6
  Gem::Version.new VERSION
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telegram-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Melentiev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-31 00:00:00.000000000 Z
11
+ date: 2016-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport