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 +4 -4
- data/app/controllers/bot/bot_controller.rb +3 -3
- data/lib/bot.rb +1 -0
- data/lib/bot/adapters/base.rb +1 -1
- data/lib/bot/adapters/kik.rb +3 -3
- data/lib/bot/adapters/test.rb +1 -1
- data/lib/bot/analytics.rb +16 -0
- data/lib/bot/configuration.rb +1 -1
- data/lib/bot/handler.rb +3 -1
- data/lib/bot/responder.rb +3 -2
- data/lib/bot/version.rb +1 -1
- data/test/dummy/log/test.log +43 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed6c59c83d14c69aa807260b2ba8eb2619b1aa1b
|
4
|
+
data.tar.gz: 466973cc8cba1858c98ce691ee38b91609b28521
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 320debce02c1194ae1ff072a581d0b315c7b92b3420caacb2d30f89d25ce1c7e8e994d5bed64bd3c4b2c6112f99b927e2edacf6c7653819d2a6579bf07a1265f
|
7
|
+
data.tar.gz: d9092f01535e0cc4549e113445a313199d5dec257625ba05778435d96eaa5c4023d9364145853854b0c9e1bd7267587e4370980ca1e5bf588b6ede77c519055b
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class Bot::BotController < ActionController::Base
|
2
|
-
before_action :
|
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
|
13
|
-
unless adapter.
|
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
data/lib/bot/adapters/base.rb
CHANGED
data/lib/bot/adapters/kik.rb
CHANGED
@@ -33,10 +33,10 @@ module Bot
|
|
33
33
|
profile['profilePicUrl'] || ''
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
36
|
+
def verify_request(request)
|
37
37
|
digest = OpenSSL::Digest.new('sha1')
|
38
|
-
key = config(
|
39
|
-
|
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
|
data/lib/bot/adapters/test.rb
CHANGED
@@ -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
|
data/lib/bot/configuration.rb
CHANGED
data/lib/bot/handler.rb
CHANGED
@@ -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
|
data/lib/bot/responder.rb
CHANGED
@@ -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)
|
data/lib/bot/version.rb
CHANGED
data/test/dummy/log/test.log
CHANGED
@@ -3549,5 +3549,48 @@ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
|
|
3549
3549
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
3550
3550
|
-------------------
|
3551
3551
|
BotTest: test_truth
|
3552
|
+
-------------------
|
3553
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
3554
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.4ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
3555
|
+
[1m[36m (1.0ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL) [0m
|
3556
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
3557
|
+
[1m[36m (1.0ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
3558
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
3559
|
+
[1m[36m (0.9ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
3560
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
3561
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
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
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
3574
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
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
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
3583
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
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
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
3592
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
3593
|
+
-------------------
|
3594
|
+
BotTest: test_truth
|
3552
3595
|
-------------------
|
3553
3596
|
[1m[35m (0.0ms)[0m 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.
|
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-
|
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
|