telegram-bot 0.7.4 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +7 -0
- data/README.md +19 -8
- data/lib/telegram/bot/middleware.rb +5 -2
- data/lib/telegram/bot/updates_controller.rb +3 -3
- data/lib/telegram/bot/updates_controller/instrumentation.rb +3 -3
- data/lib/telegram/bot/updates_controller/log_subscriber.rb +2 -2
- data/lib/telegram/bot/updates_controller/reply_helpers.rb +14 -12
- data/lib/telegram/bot/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd93b336f2b1953328663119cc121ff43ff00fee
|
4
|
+
data.tar.gz: 7be5d289e11d1fb3c45ac1557923265fa23a35bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a28a28b2650f95f1360d6d7e015ea959e6f5e79d9d93c809468db1319087dffd7c5c69294f2f06ef429246b5860267d047a16c6f9f779b583b44fcc5ef52b0a
|
7
|
+
data.tar.gz: 1af5cc258b0b0e453369b3a52bb3fb5231b568de23b0f132aac24a779c6c557dadbd37d6f487922062c740bc1cd1f285fb655b8837c63ddb391622d8e45436d4
|
data/.travis.yml
CHANGED
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
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 `
|
135
|
-
|
136
|
-
reply_with
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
231
|
+
respond_with :message, text: 'Renamed!'
|
231
232
|
else
|
232
233
|
save_context :rename
|
233
|
-
|
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/
|
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
|
-
|
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
|
-
#
|
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
|
-
#
|
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
|
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
|
39
|
-
Instrumentation.instrument(:
|
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(:
|
44
|
+
Instrumentation.instrument(:respond_with, type: type) { super(*args) }
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -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
|
6
|
-
# `reply_to_message_id`:
|
5
|
+
# Helper to call bot's `send_#{type}` method with already set `chat_id`:
|
7
6
|
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
def
|
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
|
-
|
16
|
-
|
17
|
-
|
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.
|
data/lib/telegram/bot/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2016-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|