bot 0.0.41 → 0.0.42

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
  SHA1:
3
- metadata.gz: 256f465a977ac0b8191f2de366c0069d88c4a422
4
- data.tar.gz: 71cbfa8bd5e3fb372b738619af833f6d5bd56e4c
3
+ metadata.gz: ed6c59c83d14c69aa807260b2ba8eb2619b1aa1b
4
+ data.tar.gz: 466973cc8cba1858c98ce691ee38b91609b28521
5
5
  SHA512:
6
- metadata.gz: 59501bb0d5e001597a84fcc8f904273966d0cc6c8f6ed5b9394adfaea45c404646187362e136fb48c41c38bb05be16dbd5ce2c62b40f6285661adf1a3f3e39be
7
- data.tar.gz: 6072f277f05bd5c6ce5e22c944553514e4f395a990c44eff238adb8d817fc25585f1785d7e3dcd0d6b774cee67871f1fffc80dea23dfbea2b4c5a3692f3cad5d
6
+ metadata.gz: 320debce02c1194ae1ff072a581d0b315c7b92b3420caacb2d30f89d25ce1c7e8e994d5bed64bd3c4b2c6112f99b927e2edacf6c7653819d2a6579bf07a1265f
7
+ data.tar.gz: d9092f01535e0cc4549e113445a313199d5dec257625ba05778435d96eaa5c4023d9364145853854b0c9e1bd7267587e4370980ca1e5bf588b6ede77c519055b
@@ -1,5 +1,5 @@
1
1
  class Bot::BotController < ActionController::Base
2
- before_action :verify_signature
2
+ before_action :verify_request
3
3
 
4
4
  def notify
5
5
  @responses = bot_handler.handle(messages).compact
@@ -9,8 +9,8 @@ class Bot::BotController < ActionController::Base
9
9
 
10
10
  private
11
11
 
12
- def verify_signature
13
- unless adapter.verify_signature(request.headers["HTTP_X_KIK_SIGNATURE"], request.raw_post, bot_username)
12
+ def verify_request
13
+ unless adapter.verify_request(request)
14
14
  head :forbidden
15
15
  end
16
16
  end
data/lib/bot.rb CHANGED
@@ -5,6 +5,7 @@ require "bot/route_extensions"
5
5
  require "bot/adapter"
6
6
  require "bot/configuration"
7
7
  require "bot/context"
8
+ require "bot/analytics"
8
9
  require "bot/message"
9
10
  require "bot/responder_chain"
10
11
  require "bot/rspec.rb"
@@ -13,7 +13,7 @@ module Bot
13
13
  raise NotImplementedError
14
14
  end
15
15
 
16
- def verify_signature(signature, body, from)
16
+ def verify_request(request)
17
17
  raise NotImplementedError
18
18
  end
19
19
  end
@@ -33,10 +33,10 @@ module Bot
33
33
  profile['profilePicUrl'] || ''
34
34
  end
35
35
 
36
- def verify_signature(signature, body, from)
36
+ def verify_request(request)
37
37
  digest = OpenSSL::Digest.new('sha1')
38
- key = config(from)[:bot_token]
39
- signature == OpenSSL::HMAC.hexdigest(digest, key, body).upcase
38
+ key = config(request.headers["HTTP_X_KIK_USERNAME"])[:bot_token]
39
+ request.headers["HTTP_X_KIK_SIGNATURE"] == OpenSSL::HMAC.hexdigest(digest, key, request.raw_post).upcase
40
40
  end
41
41
 
42
42
  protected
@@ -19,7 +19,7 @@ module Bot
19
19
  @@sent_messages = []
20
20
  end
21
21
 
22
- def verify_signature(signature, body, from)
22
+ def verify_request(request)
23
23
  true
24
24
  end
25
25
  end
@@ -0,0 +1,16 @@
1
+ require 'redis'
2
+
3
+ module Bot
4
+ class Analytics
5
+ attr_accessor :mixpanel, :user_key
6
+
7
+ def initialize(user_key, mixpanel=false)
8
+ @mixpanel = mixpanel
9
+ @user_key = user_key
10
+ end
11
+
12
+ def track(event, options={})
13
+ mixpanel.track(user_key, event, options) if mixpanel
14
+ end
15
+ end
16
+ end
@@ -16,6 +16,6 @@ module Bot
16
16
  end
17
17
 
18
18
  class Configuration
19
- attr_accessor :adapter, :redis
19
+ attr_accessor :adapter, :redis, :mixpanel
20
20
  end
21
21
  end
@@ -16,8 +16,10 @@ module Bot
16
16
 
17
17
  def execute_chain(message, responses, user)
18
18
  context = Bot::Context.new(user, Bot.configuration.redis)
19
+ analytics = Bot::Analytics.new(user.username, Bot.configuration.mixpanel)
20
+
19
21
  responder_chain.responders.each do |responder|
20
- responder = responder.new(message, user, responses, self, context)
22
+ responder = responder.new(message, user, responses, self, context, analytics)
21
23
  if responder.can_respond_to_type?(message['type']) && responder.can_handle?
22
24
  responses << responder.handle
23
25
  break
@@ -5,7 +5,7 @@ module Bot
5
5
 
6
6
  class_attribute :respond_to_types
7
7
 
8
- attr_reader :message, :user, :responses, :handler, :context
8
+ attr_reader :message, :user, :responses, :handler, :context, :analytics
9
9
 
10
10
  def self.respond_to(*types)
11
11
  new_types = (respond_to_types || []).dup
@@ -13,12 +13,13 @@ module Bot
13
13
  self.respond_to_types = new_types.freeze
14
14
  end
15
15
 
16
- def initialize(message, user, responses, handler, context)
16
+ def initialize(message, user, responses, handler, context, analytics)
17
17
  @message = message
18
18
  @user = user
19
19
  @responses = responses
20
20
  @handler = handler
21
21
  @context = context
22
+ @analytics = analytics
22
23
  end
23
24
 
24
25
  def can_respond_to_type?(type)
@@ -1,3 +1,3 @@
1
1
  module Bot
2
- VERSION = "0.0.41"
2
+ VERSION = "0.0.42"
3
3
  end
@@ -3549,5 +3549,48 @@ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
3549
3549
   (0.0ms) begin transaction
3550
3550
  -------------------
3551
3551
  BotTest: test_truth
3552
+ -------------------
3553
+  (0.0ms) rollback transaction
3554
+ ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
3555
+  (1.0ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
3556
+  (0.1ms) select sqlite_version(*)
3557
+  (1.0ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
3558
+  (0.1ms) SELECT version FROM "schema_migrations"
3559
+  (0.9ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
3560
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
3561
+  (0.1ms) begin transaction
3562
+ ---------------------------
3563
+ NavigationTest: test_notify
3564
+ ---------------------------
3565
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-05-04 15:20:52 -0400
3566
+ Processing by Bot::BotController#notify as HTML
3567
+ Parameters: {"bot"=>ApplicationHandler}
3568
+ Completed 200 OK in 0ms (Views: 0.2ms | ActiveRecord: 0.0ms)
3569
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-05-04 15:20:52 -0400
3570
+ Processing by Bot::BotController#notify as HTML
3571
+ Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"text", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
3572
+ Completed 500 Internal Server Error in 1ms (ActiveRecord: 0.0ms)
3573
+  (0.1ms) rollback transaction
3574
+  (0.0ms) begin transaction
3575
+ ---------------------------------------
3576
+ NavigationTest: test_notify_multi_types
3577
+ ---------------------------------------
3578
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-05-04 15:20:52 -0400
3579
+ Processing by Bot::BotController#notify as HTML
3580
+ Parameters: {"messages"=>[{"body"=>"multi", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
3581
+ Completed 500 Internal Server Error in 1ms (ActiveRecord: 0.0ms)
3582
+  (0.1ms) rollback transaction
3583
+  (0.0ms) begin transaction
3584
+ -----------------------------------------
3585
+ NavigationTest: test_notify_special_types
3586
+ -----------------------------------------
3587
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-05-04 15:20:52 -0400
3588
+ Processing by Bot::BotController#notify as HTML
3589
+ Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
3590
+ Completed 500 Internal Server Error in 1ms (ActiveRecord: 0.0ms)
3591
+  (0.1ms) rollback transaction
3592
+  (0.0ms) begin transaction
3593
+ -------------------
3594
+ BotTest: test_truth
3552
3595
  -------------------
3553
3596
   (0.0ms) rollback transaction
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.41
4
+ version: 0.0.42
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Morris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-03 00:00:00.000000000 Z
11
+ date: 2016-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -108,6 +108,7 @@ files:
108
108
  - lib/bot/adapters/base.rb
109
109
  - lib/bot/adapters/kik.rb
110
110
  - lib/bot/adapters/test.rb
111
+ - lib/bot/analytics.rb
111
112
  - lib/bot/configuration.rb
112
113
  - lib/bot/context.rb
113
114
  - lib/bot/engine.rb