bot 0.0.38 → 0.0.39

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: 8aadd7727dd46fa03fdf37373bf78c7f4768d5d4
4
- data.tar.gz: 27a64c56e216f3bac1df35dfc1b85632370231c1
3
+ metadata.gz: 951e4e152862eee4b853af458c49cee8f475b47b
4
+ data.tar.gz: 6bce5bdbfac1ff26fbff658ccd3c3d510a463786
5
5
  SHA512:
6
- metadata.gz: a5757f2947ffa5d272a593e9b6a06c066a7a33667e2d2b67a86a3328c30d8d0bead3868f4f71cec5ddcdece6cc5c566b22a2e3966c35d2952d09ec4391eb46c1
7
- data.tar.gz: 55cee88000f96f1286d8ed617affd0a552c35fa3e1510437dcc70c071a77f382ee58081845446cdaaa74aaee9e21564e6ee2ba701bb4d72546e1e78bafe0edb0
6
+ metadata.gz: 162074b4e8b28f632f39c886c1cd38fcc7865fb2b0c7a505335535307ff780732086e9d867b55b4eede1ee373bcc7d68533cc4b30483add087f4e96a18e06494
7
+ data.tar.gz: 3fdc9cde3617f0dcc512aa6216381c982061bb326f1caf198e77dc6eeb4590c473dad0ac0837fbadbb9549d7338d4b7ab8b2553c27d6dcca05f35b526ba9401c
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/message"
8
9
  require "bot/responder_chain"
9
10
  require "bot/rspec.rb"
10
11
 
@@ -22,6 +22,7 @@ module Bot
22
22
  headers: { content_type: :json }
23
23
  })
24
24
  rescue Exception => e
25
+ binding.pry
25
26
  Rails.logger.error "\n\n\nError:\n"
26
27
  Rails.logger.error e.response
27
28
  Rails.logger.error "\n\n\n"
@@ -0,0 +1,9 @@
1
+ require "bot/messages/base"
2
+ require "bot/messages/text"
3
+ require "bot/messages/photo"
4
+ require "bot/messages/card"
5
+
6
+ module Bot
7
+ module Message
8
+ end
9
+ end
@@ -0,0 +1,52 @@
1
+ module Bot
2
+ module Message
3
+ class Base
4
+ attr_accessor :message
5
+
6
+ def initialize(to, options=false)
7
+ raise NotImplementedError
8
+ end
9
+
10
+ def as_json(options=nil)
11
+ self.message.to_h
12
+ end
13
+
14
+ def method_missing(m, *args, &block)
15
+ if m =~ /.+=/
16
+ args.each do |arg|
17
+ self.message[m.to_s.gsub('=', '')] = arg
18
+ end
19
+ else
20
+ self.message[m.to_s]
21
+ end
22
+ end
23
+
24
+ protected
25
+ def suggested_responses=(suggested_responses)
26
+ case suggested_responses
27
+ when Array
28
+ self.message['keyboards'] = [{
29
+ 'type' => 'suggested',
30
+ 'responses' => build_suggested_responses(suggested_responses)
31
+ }]
32
+ when Hash
33
+ self.message.merge!(suggested_responses)
34
+ end
35
+ end
36
+
37
+ def build_suggested_responses(suggested_responses)
38
+ suggested_responses.map do |response|
39
+ case response
40
+ when String
41
+ {
42
+ 'type' => 'text',
43
+ 'body' => response
44
+ }
45
+ when Hash
46
+ response
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,25 @@
1
+ module Bot
2
+ module Message
3
+ class Card < Base
4
+ def initialize(to, url, text, suggested_responses=false, options={})
5
+ icon = options.delete("icon")
6
+
7
+ self.message = {
8
+ 'type' => 'link',
9
+ 'to' => to,
10
+ 'url' => url,
11
+ 'title' => "", # Displays over the image
12
+ 'text' => text, # Displays under the image
13
+ 'attribution' => {
14
+ 'name' => text # Displays in bottom line
15
+ },
16
+ }.merge(options)
17
+
18
+ self.message['picUrl'] = icon if icon
19
+ self.message['attribution']['iconUrl'] = icon if icon
20
+
21
+ self.suggested_responses = suggested_responses
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ module Bot
2
+ module Message
3
+ class Photo < Base
4
+ def initialize(to, photo_url, suggested_responses=false, options={})
5
+ self.message = {
6
+ 'type' => 'gallery',
7
+ 'to' => to,
8
+ 'picUrl' => photo_url,
9
+ 'typeTime' => 0,
10
+ }.merge(options)
11
+
12
+ self.suggested_responses = suggested_responses
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ module Bot
2
+ module Message
3
+ class Text < Base
4
+ def initialize(to, body, suggested_responses=false, options={})
5
+ self.message = {
6
+ 'type' => 'text',
7
+ 'to' => to,
8
+ 'body' => body,
9
+ 'typeTime' => 0,
10
+ }.merge(options)
11
+
12
+ self.message['chatId'] = options['chatId'] if options['chatId']
13
+ self.suggested_responses = suggested_responses
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Bot
2
- VERSION = "0.0.38"
2
+ VERSION = "0.0.39"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  class ApplicationHandler < Bot::Handler
2
2
  use Responders::Default
3
3
 
4
- # def user_for(message)
5
- # User.find_or_create_by(username: message["from"])
6
- # end
4
+ def user_for(message)
5
+ User.find_or_create_by(username: message["from"])
6
+ end
7
7
  end
@@ -3379,3 +3379,46 @@ Processing by Bot::BotController#notify as HTML
3379
3379
  Parameters: {"messages"=>[{"body"=>"multi", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
3380
3380
  Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
3381
3381
   (0.1ms) rollback transaction
3382
+ ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
3383
+  (1.0ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
3384
+  (0.1ms) select sqlite_version(*)
3385
+  (0.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
3386
+  (0.1ms) SELECT version FROM "schema_migrations"
3387
+  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
3388
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
3389
+  (0.1ms) begin transaction
3390
+ -------------------
3391
+ BotTest: test_truth
3392
+ -------------------
3393
+  (0.0ms) rollback transaction
3394
+  (0.0ms) begin transaction
3395
+ ---------------------------------------
3396
+ NavigationTest: test_notify_multi_types
3397
+ ---------------------------------------
3398
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-05-03 14:23:13 -0400
3399
+ Processing by Bot::BotController#notify as HTML
3400
+ Parameters: {"messages"=>[{"body"=>"multi", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
3401
+ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
3402
+  (0.1ms) rollback transaction
3403
+  (0.1ms) begin transaction
3404
+ -----------------------------------------
3405
+ NavigationTest: test_notify_special_types
3406
+ -----------------------------------------
3407
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-05-03 14:23:13 -0400
3408
+ Processing by Bot::BotController#notify as HTML
3409
+ Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
3410
+ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
3411
+  (0.1ms) rollback transaction
3412
+  (0.0ms) begin transaction
3413
+ ---------------------------
3414
+ NavigationTest: test_notify
3415
+ ---------------------------
3416
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-05-03 14:23:13 -0400
3417
+ Processing by Bot::BotController#notify as HTML
3418
+ Parameters: {"bot"=>ApplicationHandler}
3419
+ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
3420
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-05-03 14:23:13 -0400
3421
+ Processing by Bot::BotController#notify as HTML
3422
+ Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"text", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
3423
+ Completed 200 OK in 0ms (Views: 0.2ms | ActiveRecord: 0.0ms)
3424
+  (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.38
4
+ version: 0.0.39
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-02 00:00:00.000000000 Z
11
+ date: 2016-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -112,6 +112,11 @@ files:
112
112
  - lib/bot/context.rb
113
113
  - lib/bot/engine.rb
114
114
  - lib/bot/handler.rb
115
+ - lib/bot/message.rb
116
+ - lib/bot/messages/base.rb
117
+ - lib/bot/messages/card.rb
118
+ - lib/bot/messages/photo.rb
119
+ - lib/bot/messages/text.rb
115
120
  - lib/bot/responder.rb
116
121
  - lib/bot/responder_chain.rb
117
122
  - lib/bot/route_extensions.rb