bot 0.0.35 → 0.0.37

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
  SHA1:
3
- metadata.gz: 4bd5e8125f54000ad059876794098663a3a34aa3
4
- data.tar.gz: 31205394d2f3f2ce599831803f176d355785272e
3
+ metadata.gz: 381717efe3e79e2c030de08782b30420e077109e
4
+ data.tar.gz: 582e298ffd95f57c30c3ab07a47f6f1b434c6adf
5
5
  SHA512:
6
- metadata.gz: 714e4c41f49b239845a79a0b1a512b1b98758770d40be7d94c6cfe9d47ba24642f7027e7eb9ac5e9be69e100520512614e2fc8411ed6061eec21bffaf54cea33
7
- data.tar.gz: b8d69d30fad7aff51e97b4cbf5d90abcda17ff238e4bbe3abe1705a64ea566b064d1cb628e3285f4041c2f06322207e3fc0466a10736d757fbcca5cb5f39f72a
6
+ metadata.gz: fd976cc2e6a04693edb376c4a1350e7fc83cf937706eb8dd3d529070c8373c752fb1685cd26ab9bcd1ad6c6484c2203d117294a86b9aa9be40fdd9efaad95084
7
+ data.tar.gz: 19048aa8a5339e05144f5296e3cc767eb54bdd3b96444572b81ed0b0c27b6e67f4040ce42ce3fa4b86d9fca890a54e5e5bbd217c90b475720ed16286f77c0eeb
@@ -1,20 +1,30 @@
1
1
  class Bot::BotController < ActionController::Base
2
+ before_action :verify_signature
3
+
2
4
  def notify
3
5
  @responses = bot_handler.handle(messages).compact
4
-
5
- adapter.send_messages(@responses, params[:bot_username]) if @responses.present?
6
-
6
+ adapter.send_messages(@responses, bot_username) if @responses.present?
7
7
  render json: []
8
8
  end
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)
14
+ head :forbidden
15
+ end
16
+ end
17
+
12
18
  def messages
13
19
  Array.wrap(params[:messages]).map do |m|
14
- m.merge(to: params[:bot_username])
20
+ m.merge(to: bot_username)
15
21
  end
16
22
  end
17
23
 
24
+ def bot_username
25
+ request.headers["HTTP_X_KIK_USERNAME"]
26
+ end
27
+
18
28
  def adapter
19
29
  Bot.configuration.adapter
20
30
  end
@@ -12,6 +12,10 @@ module Bot
12
12
  def send_messages(messages, from)
13
13
  raise NotImplementedError
14
14
  end
15
+
16
+ def verify_signature(signature, body, from)
17
+ raise NotImplementedError
18
+ end
15
19
  end
16
20
  end
17
21
  end
@@ -33,6 +33,12 @@ module Bot
33
33
  profile['profilePicUrl'] || ''
34
34
  end
35
35
 
36
+ def verify_signature(signature, body, from)
37
+ digest = OpenSSL::Digest.new('sha1')
38
+ key = config(from)[:bot_token]
39
+ signature == OpenSSL::HMAC.hexdigest(digest, key, body).upcase
40
+ end
41
+
36
42
  protected
37
43
 
38
44
  def get_profile(username, from)
@@ -18,6 +18,10 @@ module Bot
18
18
  def self.empty_messages
19
19
  @@sent_messages = []
20
20
  end
21
+
22
+ def verify_signature(signature, body, from)
23
+ true
24
+ end
21
25
  end
22
26
  end
23
27
  end
@@ -1,3 +1,3 @@
1
1
  module Bot
2
- VERSION = "0.0.35"
2
+ VERSION = "0.0.37"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  module Responders
2
2
  class Default < ApplicationResponder
3
+ respond_to "scan-data", "text", "link", "picture", "video", "sticker"
3
4
  #
4
5
  # def can_handle?
5
6
  # true
Binary file
@@ -3248,5 +3248,91 @@ NavigationTest: test_notify_special_types
3248
3248
  Started POST "/bot/notify" for 127.0.0.1 at 2016-04-28 20:49:39 -0400
3249
3249
  Processing by Bot::BotController#notify as HTML
3250
3250
  Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
3251
+ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
3252
+  (0.1ms) rollback transaction
3253
+ ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
3254
+  (1.8ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
3255
+  (0.1ms) select sqlite_version(*)
3256
+  (0.9ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
3257
+  (0.1ms) SELECT version FROM "schema_migrations"
3258
+  (0.9ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
3259
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
3260
+  (0.1ms) begin transaction
3261
+ -------------------
3262
+ BotTest: test_truth
3263
+ -------------------
3264
+  (0.1ms) rollback transaction
3265
+  (0.1ms) begin transaction
3266
+ -----------------------------------------
3267
+ NavigationTest: test_notify_special_types
3268
+ -----------------------------------------
3269
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-30 17:50:49 -0400
3270
+ Processing by Bot::BotController#notify as HTML
3271
+ Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
3272
+ Completed 200 OK in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms)
3273
+  (0.2ms) rollback transaction
3274
+  (0.1ms) begin transaction
3275
+ ---------------------------
3276
+ NavigationTest: test_notify
3277
+ ---------------------------
3278
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-30 17:50:49 -0400
3279
+ Processing by Bot::BotController#notify as HTML
3280
+ Parameters: {"bot"=>ApplicationHandler}
3281
+ Completed 200 OK in 0ms (Views: 0.2ms | ActiveRecord: 0.0ms)
3282
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-30 17:50:49 -0400
3283
+ Processing by Bot::BotController#notify as HTML
3284
+ Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"text", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
3285
+ Completed 200 OK in 1ms (Views: 0.3ms | ActiveRecord: 0.0ms)
3286
+  (0.1ms) rollback transaction
3287
+  (0.1ms) begin transaction
3288
+ ---------------------------------------
3289
+ NavigationTest: test_notify_multi_types
3290
+ ---------------------------------------
3291
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-30 17:50:49 -0400
3292
+ Processing by Bot::BotController#notify as HTML
3293
+ Parameters: {"messages"=>[{"body"=>"multi", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
3294
+ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
3295
+  (0.1ms) rollback transaction
3296
+ ActiveRecord::SchemaMigration Load (0.6ms) SELECT "schema_migrations".* FROM "schema_migrations"
3297
+  (0.9ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
3298
+  (0.4ms) select sqlite_version(*)
3299
+  (0.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
3300
+  (0.1ms) SELECT version FROM "schema_migrations"
3301
+  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
3302
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
3303
+  (0.1ms) begin transaction
3304
+ -------------------
3305
+ BotTest: test_truth
3306
+ -------------------
3307
+  (0.1ms) rollback transaction
3308
+  (0.0ms) begin transaction
3309
+ ---------------------------------------
3310
+ NavigationTest: test_notify_multi_types
3311
+ ---------------------------------------
3312
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-05-02 10:47:43 -0400
3313
+ Processing by Bot::BotController#notify as HTML
3314
+ Parameters: {"messages"=>[{"body"=>"multi", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
3315
+ Completed 200 OK in 1ms (Views: 0.3ms | ActiveRecord: 0.0ms)
3316
+  (0.1ms) rollback transaction
3317
+  (0.1ms) begin transaction
3318
+ -----------------------------------------
3319
+ NavigationTest: test_notify_special_types
3320
+ -----------------------------------------
3321
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-05-02 10:47:43 -0400
3322
+ Processing by Bot::BotController#notify as HTML
3323
+ Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
3324
+ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
3325
+  (0.1ms) rollback transaction
3326
+  (0.1ms) begin transaction
3327
+ ---------------------------
3328
+ NavigationTest: test_notify
3329
+ ---------------------------
3330
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-05-02 10:47:44 -0400
3331
+ Processing by Bot::BotController#notify as HTML
3332
+ Parameters: {"bot"=>ApplicationHandler}
3333
+ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
3334
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-05-02 10:47:44 -0400
3335
+ Processing by Bot::BotController#notify as HTML
3336
+ Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"text", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
3251
3337
  Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
3252
3338
   (0.1ms) 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.35
4
+ version: 0.0.37
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-04-29 00:00:00.000000000 Z
11
+ date: 2016-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails