action_bot 0.1.18 → 0.1.19
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 802cec2057aa409c4b36ec18635cda38a33bce66bcbfeba7fd3d6cb4f4f4a992
|
4
|
+
data.tar.gz: d78cffe09c272f262700ee7c21fd6dd9708584cebd7d375a5528fed166928a7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e6155339bfee95e3f73d282498d2089c975c8f0c444f572848645620bb48b39bdda40dff0cda32cfa68bdb5b6d8aead3a5f7260b26f9f1e6bdd37b9f62c34dc
|
7
|
+
data.tar.gz: a50600a07b806be3ff5c86ff64cf8edb412d9734466cffd46eef44c48178eeb5290aaa31d06f97278d0c578380390facdc9b2a84fa53bd9ded2c91ae81d4586e
|
data/lib/action_bot/base.rb
CHANGED
@@ -3,12 +3,16 @@ module ActionBot
|
|
3
3
|
include Configurable.with(:api, :bot)
|
4
4
|
|
5
5
|
def on(condition, **kwargs)
|
6
|
+
puts "#{Time.now}: Received:- #{kwargs}"
|
6
7
|
return unless condition
|
7
8
|
|
8
9
|
params = kwargs.delete(:params) || {}
|
9
10
|
controller, action = kwargs.first
|
10
11
|
controller_object = "#{controller.to_s.camelize}Controller".constantize.new
|
12
|
+
puts "controller: #{controller.to_s.camelize}Controller, action: #{action}"
|
11
13
|
raise "No such method: #{action} for #{controller}" unless controller_object.respond_to?(action)
|
14
|
+
|
15
|
+
puts "Receiving..."
|
12
16
|
controller_object.params = ActionController::Parameters.new params
|
13
17
|
controller_object.public_send(action)
|
14
18
|
throw(:done)
|
@@ -17,12 +17,17 @@ class ExampleLongPollingBot < ActionBot::Base
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def run
|
20
|
+
return unless message_legal?
|
21
|
+
|
20
22
|
on @message == 'hello_world', hello: :world, params: {
|
21
23
|
tg_chat_id: tg_chat_id
|
22
24
|
}
|
23
25
|
end
|
24
26
|
|
25
27
|
private
|
28
|
+
|
29
|
+
def message_legal?
|
30
|
+
@message.respond_to?(:text) && @message.text
|
26
31
|
|
27
32
|
def tg_chat_id
|
28
33
|
@message.chat.id
|