action_bot 0.1.20 → 0.1.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/action_bot/base.rb +0 -4
- data/lib/action_bot/controller.rb +1 -1
- data/scaffolds/bots/example_long_polling_bot.rb +6 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47c36b9257696e78a0dc4f4ac529f6832d4a8c1135cbed2ba4cadb0871a57aa8
|
4
|
+
data.tar.gz: 003ef51876d760f47dbd0d728a5e334d4a3448a8cf881b548be55e759ce73cf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f2b46e3cfa96dfde707c39764f045f675d845913b374cea877c2edfc9006bdb4cdca59de118b94bf0692451798a04e9697d817238ddac85161a4341897f1490
|
7
|
+
data.tar.gz: 3cf2e11c6580db7abf50f77a929b07dbc38d544bd350079a8f8c860fc10eef8fb7afaef24e2ec190a948f5d0912b8529d1cbade4980ab86b97067a632980e735
|
data/lib/action_bot/base.rb
CHANGED
@@ -3,17 +3,13 @@ module ActionBot
|
|
3
3
|
include Configurable.with(:api, :bot)
|
4
4
|
|
5
5
|
def on(condition, **kwargs)
|
6
|
-
puts "#{Time.now}: Received:- #{kwargs}"
|
7
6
|
return unless condition
|
8
|
-
puts "Passed condition: #{condition}"
|
9
7
|
|
10
8
|
params = kwargs.delete(:params) || {}
|
11
9
|
controller, action = kwargs.first
|
12
10
|
controller_object = "#{controller.to_s.camelize}Controller".constantize.new
|
13
|
-
puts "controller: #{controller.to_s.camelize}Controller, action: #{action}"
|
14
11
|
raise "No such method: #{action} for #{controller}" unless controller_object.respond_to?(action)
|
15
12
|
|
16
|
-
puts "Receiving..."
|
17
13
|
controller_object.params = ActionController::Parameters.new params
|
18
14
|
controller_object.public_send(action)
|
19
15
|
throw(:done)
|
@@ -18,16 +18,18 @@ class ExampleLongPollingBot < ActionBot::Base
|
|
18
18
|
|
19
19
|
def run
|
20
20
|
return unless message_legal?
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
catch(:done) do
|
22
|
+
on @message.text == 'hello_world', hello: :world, params: {
|
23
|
+
tg_chat_id: tg_chat_id
|
24
|
+
}
|
25
|
+
end
|
25
26
|
end
|
26
27
|
|
27
28
|
private
|
28
29
|
|
29
30
|
def message_legal?
|
30
31
|
@message.respond_to?(:text) && @message.text
|
32
|
+
end
|
31
33
|
|
32
34
|
def tg_chat_id
|
33
35
|
@message.chat.id
|