action_bot 0.1.18 → 0.1.19

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
  SHA256:
3
- metadata.gz: f267e3093741e98e9812f5a8e43871e3fe03a0634d58972cb86dd5cc3834230b
4
- data.tar.gz: 01767005c9771cf1395453ec27ae3f7cd6525a8db0a5413668bf3322e717de97
3
+ metadata.gz: 802cec2057aa409c4b36ec18635cda38a33bce66bcbfeba7fd3d6cb4f4f4a992
4
+ data.tar.gz: d78cffe09c272f262700ee7c21fd6dd9708584cebd7d375a5528fed166928a7a
5
5
  SHA512:
6
- metadata.gz: 8b403d696bc7d517a88137f65ebde2c11207eadc0b38296a1b35b3f4629a87134751806c75e2421f1df6df21b26c4399fef5f40b030e4f5cfbef5d6d7d273973
7
- data.tar.gz: fc9f146bbec3739c4c7f7967a797d50722e45acefca89dc73e6763f9ccf23ceaae41b86e5f0224a071190e32eb3f5d8fd04316f1af2ee0b7354214ed11429872
6
+ metadata.gz: 0e6155339bfee95e3f73d282498d2089c975c8f0c444f572848645620bb48b39bdda40dff0cda32cfa68bdb5b6d8aead3a5f7260b26f9f1e6bdd37b9f62c34dc
7
+ data.tar.gz: a50600a07b806be3ff5c86ff64cf8edb412d9734466cffd46eef44c48178eeb5290aaa31d06f97278d0c578380390facdc9b2a84fa53bd9ded2c91ae81d4586e
@@ -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
@@ -1,4 +1,4 @@
1
- class HelloController
1
+ class HelloController < BotsController
2
2
  def world
3
3
  notify(params[:tg_chat_id], t('hello_world'))
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Barseek