message_quickly 1.1.2 → 1.2.0

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/message_quickly/application_helper.rb +4 -0
  3. data/lib/generators/message_quickly/callbacks/templates/account_linking_callback.rb +14 -0
  4. data/lib/generators/message_quickly/callbacks/templates/message_read_callback.rb +14 -0
  5. data/lib/message_quickly.rb +1 -0
  6. data/lib/message_quickly/api/account_link.rb +41 -0
  7. data/lib/message_quickly/api/client.rb +9 -0
  8. data/lib/message_quickly/api/thread_settings.rb +74 -19
  9. data/lib/message_quickly/api/user_profile.rb +1 -1
  10. data/lib/message_quickly/callback_parser.rb +9 -1
  11. data/lib/message_quickly/messaging/account_link_button.rb +23 -0
  12. data/lib/message_quickly/messaging/account_link_event.rb +41 -0
  13. data/lib/message_quickly/messaging/account_unlink_button.rb +22 -0
  14. data/lib/message_quickly/messaging/audio_attachment.rb +41 -0
  15. data/lib/message_quickly/messaging/button_template_attachment.rb +2 -0
  16. data/lib/message_quickly/messaging/element.rb +2 -0
  17. data/lib/message_quickly/messaging/image_attachment.rb +1 -1
  18. data/lib/message_quickly/messaging/location_attachment.rb +30 -0
  19. data/lib/message_quickly/messaging/message.rb +16 -3
  20. data/lib/message_quickly/messaging/message_event.rb +28 -5
  21. data/lib/message_quickly/messaging/quick_reply.rb +34 -0
  22. data/lib/message_quickly/messaging/read_event.rb +49 -0
  23. data/lib/message_quickly/messaging/user.rb +1 -1
  24. data/lib/message_quickly/messaging/video_attachment.rb +41 -0
  25. data/lib/message_quickly/version.rb +2 -2
  26. data/spec/callback_parser_spec.rb +22 -0
  27. data/spec/controllers/webhooks_controller_spec.rb +35 -1
  28. data/spec/dummy/app/webhooks/account_linking_callback.rb +14 -0
  29. data/spec/dummy/app/webhooks/message_read_callback.rb +14 -0
  30. data/spec/dummy/log/test.log +7166 -0
  31. data/spec/fixtures/SampleVideo_1280x720_1mb.mp4 +0 -0
  32. data/spec/fixtures/account_link.json +24 -0
  33. data/spec/fixtures/jailhouse-rock-demo.mp3 +0 -0
  34. data/spec/fixtures/message_read.json +24 -0
  35. data/spec/fixtures/message_request_with_attachment.json +13 -1
  36. data/spec/message_quickly/api/account_link_spec.rb +49 -0
  37. data/spec/message_quickly/api/messages_spec.rb +70 -0
  38. data/spec/message_quickly/api/thread_settings_spec.rb +83 -7
  39. metadata +27 -2
@@ -0,0 +1,24 @@
1
+ {
2
+ "object":"page",
3
+ "entry":[
4
+ {
5
+ "id":"PAGE_ID",
6
+ "time":1458668856451,
7
+ "messaging":[
8
+ {
9
+ "sender":{
10
+ "id":"USER_ID"
11
+ },
12
+ "recipient":{
13
+ "id":"PAGE_ID"
14
+ },
15
+ "timestamp":1234567890,
16
+ "account_linking":{
17
+ "status":"linked",
18
+ "authorization_code":"PASS_THROUGH_AUTHORIZATION_CODE"
19
+ }
20
+ }
21
+ ]
22
+ }
23
+ ]
24
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "object":"page",
3
+ "entry":[
4
+ {
5
+ "id":"PAGE_ID",
6
+ "time":1458668856451,
7
+ "messaging":[
8
+ {
9
+ "sender":{
10
+ "id":"USER_ID"
11
+ },
12
+ "recipient":{
13
+ "id":"PAGE_ID"
14
+ },
15
+ "timestamp":1458668856463,
16
+ "read":{
17
+ "watermark":1458668856253,
18
+ "seq":38
19
+ }
20
+ }
21
+ ]
22
+ }
23
+ ]
24
+ }
@@ -22,8 +22,20 @@
22
22
  "payload":{
23
23
  "url":"IMAGE_URL"
24
24
  }
25
+ },
26
+ {
27
+ "type":"location",
28
+ "payload":{
29
+ "coordinates":{
30
+ "lat": 1.3062306,
31
+ "long": 103.85575970000002
32
+ }
33
+ }
25
34
  }
26
- ]
35
+ ],
36
+ "quick_reply": {
37
+ "payload": "QUICK_REPLY_VALUE"
38
+ }
27
39
  }
28
40
  }
29
41
  ]
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe MessageQuickly::Api::AccountLink do
4
+
5
+ subject { MessageQuickly::Api::AccountLink }
6
+
7
+ describe '#page_scoped_id' do
8
+
9
+ let(:account_linking_token) { "token expires, so can't use it for testing" }
10
+
11
+ context 'with own client' do
12
+ let(:client) { MessageQuickly::Api::Client.new(page_access_token: ENV['FACEBOOK_MESSENGER_PAGE_ACCESS_TOKEN'], page_id: ENV['FACEBOOK_MESSENGER_PAGE_ID']) }
13
+ # it { expect(subject.new(client).page_scoped_id(account_linking_token)).to eq(true) }
14
+ it { expect { subject.page_scoped_id(account_linking_token) }.to raise_exception(MessageQuickly::Api::OauthException) }
15
+ end
16
+
17
+ context 'with valid params' do
18
+ # it { expect(subject.page_scoped_id(account_linking_token)).to eq(true) }
19
+ it { expect { subject.page_scoped_id(account_linking_token) }.to raise_exception(MessageQuickly::Api::OauthException) }
20
+ end
21
+
22
+ context 'with invalid params' do
23
+ before { stub_const('ENV', ENV.to_hash.merge('FACEBOOK_MESSENGER_PAGE_ID' => 'invalid')) }
24
+ it { expect { subject.page_scoped_id(account_linking_token) }.to raise_exception(MessageQuickly::Api::OauthException) }
25
+ end
26
+
27
+ end
28
+
29
+ describe '#unlink_account' do
30
+
31
+ let(:page_scoped_id) { ENV['FACEBOOK_MESSENGER_USER_ID'] }
32
+
33
+ context 'with own client' do
34
+ let(:client) { MessageQuickly::Api::Client.new(page_access_token: ENV['FACEBOOK_MESSENGER_PAGE_ACCESS_TOKEN'], page_id: ENV['FACEBOOK_MESSENGER_PAGE_ID']) }
35
+ it { expect(subject.new(client).unlink_account(page_scoped_id)).to eq(true) }
36
+ end
37
+
38
+ context 'with valid params' do
39
+ it { expect(subject.unlink_account(page_scoped_id)).to eq(true) }
40
+ end
41
+
42
+ context 'with invalid params' do
43
+ before { stub_const('ENV', ENV.to_hash.merge('FACEBOOK_MESSENGER_PAGE_ID' => 'invalid')) }
44
+ it { expect { subject.unlink_account('') }.to raise_exception(MessageQuickly::Api::OauthException) }
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -89,6 +89,40 @@ describe MessageQuickly::Api::Messages do
89
89
  expect(delivery.id).not_to be_nil
90
90
  end
91
91
 
92
+ it 'should be able to send with an video url attachment' do
93
+ delivery = subject.create(recipient) do |message|
94
+ message.build_attachment(:video) { |attachment| attachment.url = 'http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4' }
95
+ end
96
+ expect(delivery.id).not_to be_nil
97
+ end
98
+
99
+ it 'should be able to send with an video file attachment' do
100
+ delivery = subject.create(recipient) do |message|
101
+ message.build_attachment(:video) do |attachment|
102
+ attachment.file = "spec/fixtures/SampleVideo_1280x720_1mb.mp4"
103
+ attachment.file_type = 'video/mp4'
104
+ end
105
+ end
106
+ expect(delivery.id).not_to be_nil
107
+ end
108
+
109
+ it 'should be able to send with an audio url attachment' do
110
+ delivery = subject.create(recipient) do |message|
111
+ message.build_attachment(:audio) { |attachment| attachment.url = 'http://www.stephaniequinn.com/Music/Commercial%20DEMO%20-%2010.mp3' }
112
+ end
113
+ expect(delivery.id).not_to be_nil
114
+ end
115
+
116
+ it 'should be able to send with an audio file attachment' do
117
+ delivery = subject.create(recipient) do |message|
118
+ message.build_attachment(:audio) do |attachment|
119
+ attachment.file = "spec/fixtures/jailhouse-rock-demo.mp3"
120
+ attachment.file_type = 'audio/png'
121
+ end
122
+ end
123
+ expect(delivery.id).not_to be_nil
124
+ end
125
+
92
126
  it 'should be able to send with a generic template attachment' do
93
127
  delivery = subject.create(recipient) do |message|
94
128
  message.build_attachment(:generic_template) do |template|
@@ -225,6 +259,42 @@ describe MessageQuickly::Api::Messages do
225
259
  expect(delivery.id).not_to be_nil
226
260
  end
227
261
 
262
+ it 'should be able to send quick replies' do
263
+ delivery = subject.create(recipient) do |message|
264
+
265
+ message.text = "Pick a color:"
266
+
267
+ message.build_quick_reply do |quick_reply|
268
+ quick_reply.title = 'Green'
269
+ quick_reply.payload = 'DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_GREEN'
270
+ end
271
+
272
+ message.build_quick_reply do |quick_reply|
273
+ quick_reply.title = 'Red'
274
+ quick_reply.payload = 'DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_RED'
275
+ end
276
+
277
+ end
278
+ expect(delivery.id).not_to be_nil
279
+ end
280
+
281
+ end
282
+
283
+ it 'should be able to send account link buttons' do
284
+ delivery = subject.create(recipient) do |message|
285
+
286
+ message.build_attachment(:button_template) do |template|
287
+
288
+ template.text = 'Please log in'
289
+
290
+ template.build_button(:account_link) do |button|
291
+ button.url = 'https://www.example.com/oauth/authorize'
292
+ end
293
+
294
+ end
295
+
296
+ end
297
+ expect(delivery.id).not_to be_nil
228
298
  end
229
299
 
230
300
  end
@@ -4,28 +4,104 @@ describe MessageQuickly::Api::ThreadSettings do
4
4
 
5
5
  subject { MessageQuickly::Api::ThreadSettings }
6
6
 
7
- describe '#create' do
7
+ describe '#greeting' do
8
8
 
9
- let(:message) { MessageQuickly::Messaging::Message.new(text: 'Hello') }
9
+ let(:text) { 'Hello' }
10
10
 
11
11
  context 'with own client' do
12
12
  let(:client) { MessageQuickly::Api::Client.new(page_access_token: ENV['FACEBOOK_MESSENGER_PAGE_ACCESS_TOKEN'], page_id: ENV['FACEBOOK_MESSENGER_PAGE_ID']) }
13
- it { expect(subject.new(client).create(message)).to eq(true) }
13
+ it { expect(subject.new(client).greeting(text)).to eq(true) }
14
14
  end
15
15
 
16
16
  context 'with valid params' do
17
- it { expect(subject.create(message)).to eq(true) }
17
+ it { expect(subject.greeting(text)).to eq(true) }
18
18
  end
19
19
 
20
20
  context 'with invalid params' do
21
21
  before { stub_const('ENV', ENV.to_hash.merge('FACEBOOK_MESSENGER_PAGE_ID' => 'invalid')) }
22
- it { expect { subject.create(message) }.to raise_exception(MessageQuickly::Api::OauthException) }
22
+ it { expect { subject.greeting(text) }.to raise_exception(MessageQuickly::Api::OauthException) }
23
23
  end
24
24
 
25
25
  end
26
26
 
27
- describe '#delete' do
28
- it { expect(subject.delete).to eq(true) }
27
+ describe '#get_started_button' do
28
+
29
+ let(:payload) { 'Payload 1' }
30
+
31
+ context 'with own client' do
32
+ let(:client) { MessageQuickly::Api::Client.new(page_access_token: ENV['FACEBOOK_MESSENGER_PAGE_ACCESS_TOKEN'], page_id: ENV['FACEBOOK_MESSENGER_PAGE_ID']) }
33
+ it { expect(subject.new(client).get_started_button(payload)).to eq(true) }
34
+ end
35
+
36
+ context 'with valid params' do
37
+ it { expect(subject.get_started_button(payload)).to eq(true) }
38
+ end
39
+
40
+ context 'with invalid params' do
41
+ before { stub_const('ENV', ENV.to_hash.merge('FACEBOOK_MESSENGER_PAGE_ID' => 'invalid')) }
42
+ it { expect { subject.get_started_button(payload) }.to raise_exception(MessageQuickly::Api::OauthException) }
43
+ end
44
+
45
+ end
46
+
47
+ describe '#remove_get_started_button' do
48
+
49
+ context 'with own client' do
50
+ let(:client) { MessageQuickly::Api::Client.new(page_access_token: ENV['FACEBOOK_MESSENGER_PAGE_ACCESS_TOKEN'], page_id: ENV['FACEBOOK_MESSENGER_PAGE_ID']) }
51
+ it { expect(subject.new(client).remove_get_started_button).to eq(true) }
52
+ end
53
+
54
+ context 'with valid params' do
55
+ it { expect(subject.remove_get_started_button).to eq(true) }
56
+ end
57
+
58
+ context 'with invalid params' do
59
+ before { stub_const('ENV', ENV.to_hash.merge('FACEBOOK_MESSENGER_PAGE_ID' => 'invalid')) }
60
+ it { expect { subject.remove_get_started_button }.to raise_exception(MessageQuickly::Api::OauthException) }
61
+ end
62
+
63
+ end
64
+
65
+ describe '#persistent_menu' do
66
+
67
+ let(:payloads) { [
68
+ { type: 'postback', title: 'Help', payload: 'DEVELOPER_DEFINED_PAYLOAD_FOR_HELP' },
69
+ { type: 'postback', title: 'Start a New Order', payload: 'DEVELOPER_DEFINED_PAYLOAD_FOR_START_ORDER' },
70
+ { type: 'web_url', title: 'View Website', url: 'http://petersapparel.parseapp.com/' }
71
+ ] }
72
+
73
+ context 'with own client' do
74
+ let(:client) { MessageQuickly::Api::Client.new(page_access_token: ENV['FACEBOOK_MESSENGER_PAGE_ACCESS_TOKEN'], page_id: ENV['FACEBOOK_MESSENGER_PAGE_ID']) }
75
+ it { expect(subject.new(client).persistent_menu(payloads)).to eq(true) }
76
+ end
77
+
78
+ context 'with valid params' do
79
+ it { expect(subject.persistent_menu(payloads)).to eq(true) }
80
+ end
81
+
82
+ context 'with invalid params' do
83
+ before { stub_const('ENV', ENV.to_hash.merge('FACEBOOK_MESSENGER_PAGE_ID' => 'invalid')) }
84
+ it { expect { subject.persistent_menu(payloads) }.to raise_exception(MessageQuickly::Api::OauthException) }
85
+ end
86
+
87
+ end
88
+
89
+ describe '#remove_persistent_menu' do
90
+
91
+ context 'with own client' do
92
+ let(:client) { MessageQuickly::Api::Client.new(page_access_token: ENV['FACEBOOK_MESSENGER_PAGE_ACCESS_TOKEN'], page_id: ENV['FACEBOOK_MESSENGER_PAGE_ID']) }
93
+ it { expect(subject.new(client).remove_persistent_menu).to eq(true) }
94
+ end
95
+
96
+ context 'with valid params' do
97
+ it { expect(subject.remove_persistent_menu).to eq(true) }
98
+ end
99
+
100
+ context 'with invalid params' do
101
+ before { stub_const('ENV', ENV.to_hash.merge('FACEBOOK_MESSENGER_PAGE_ID' => 'invalid')) }
102
+ it { expect { subject.remove_persistent_menu }.to raise_exception(MessageQuickly::Api::OauthException) }
103
+ end
104
+
29
105
  end
30
106
 
31
107
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: message_quickly
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaryl Sim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-29 00:00:00.000000000 Z
11
+ date: 2016-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -127,14 +127,17 @@ files:
127
127
  - config/routes.rb
128
128
  - lib/generators/message_quickly/callbacks/USAGE
129
129
  - lib/generators/message_quickly/callbacks/callbacks_generator.rb
130
+ - lib/generators/message_quickly/callbacks/templates/account_linking_callback.rb
130
131
  - lib/generators/message_quickly/callbacks/templates/authentication_callback.rb
131
132
  - lib/generators/message_quickly/callbacks/templates/message_delivered_callback.rb
133
+ - lib/generators/message_quickly/callbacks/templates/message_read_callback.rb
132
134
  - lib/generators/message_quickly/callbacks/templates/message_received_callback.rb
133
135
  - lib/generators/message_quickly/callbacks/templates/postback_callback.rb
134
136
  - lib/generators/message_quickly/callbacks/templates/process_messenger_callback_job.rb
135
137
  - lib/generators/message_quickly/callbacks/templates/send_messenger_delivery_job.rb
136
138
  - lib/generators/message_quickly/callbacks/templates/webhooks.rb
137
139
  - lib/message_quickly.rb
140
+ - lib/message_quickly/api/account_link.rb
138
141
  - lib/message_quickly/api/base.rb
139
142
  - lib/message_quickly/api/client.rb
140
143
  - lib/message_quickly/api/facebook_api_exception.rb
@@ -150,7 +153,11 @@ files:
150
153
  - lib/message_quickly/callback_parser.rb
151
154
  - lib/message_quickly/callback_registry.rb
152
155
  - lib/message_quickly/engine.rb
156
+ - lib/message_quickly/messaging/account_link_button.rb
157
+ - lib/message_quickly/messaging/account_link_event.rb
158
+ - lib/message_quickly/messaging/account_unlink_button.rb
153
159
  - lib/message_quickly/messaging/attachment.rb
160
+ - lib/message_quickly/messaging/audio_attachment.rb
154
161
  - lib/message_quickly/messaging/base.rb
155
162
  - lib/message_quickly/messaging/button.rb
156
163
  - lib/message_quickly/messaging/button_template_attachment.rb
@@ -161,11 +168,14 @@ files:
161
168
  - lib/message_quickly/messaging/event.rb
162
169
  - lib/message_quickly/messaging/generic_template_attachment.rb
163
170
  - lib/message_quickly/messaging/image_attachment.rb
171
+ - lib/message_quickly/messaging/location_attachment.rb
164
172
  - lib/message_quickly/messaging/message.rb
165
173
  - lib/message_quickly/messaging/message_event.rb
166
174
  - lib/message_quickly/messaging/optin_event.rb
167
175
  - lib/message_quickly/messaging/postback_button.rb
168
176
  - lib/message_quickly/messaging/postback_event.rb
177
+ - lib/message_quickly/messaging/quick_reply.rb
178
+ - lib/message_quickly/messaging/read_event.rb
169
179
  - lib/message_quickly/messaging/receipt/address.rb
170
180
  - lib/message_quickly/messaging/receipt/adjustment.rb
171
181
  - lib/message_quickly/messaging/receipt/element.rb
@@ -175,6 +185,7 @@ files:
175
185
  - lib/message_quickly/messaging/sender.rb
176
186
  - lib/message_quickly/messaging/template_attachment.rb
177
187
  - lib/message_quickly/messaging/user.rb
188
+ - lib/message_quickly/messaging/video_attachment.rb
178
189
  - lib/message_quickly/messaging/web_url_button.rb
179
190
  - lib/message_quickly/version.rb
180
191
  - spec/callback_parser_spec.rb
@@ -188,8 +199,10 @@ files:
188
199
  - spec/dummy/app/helpers/application_helper.rb
189
200
  - spec/dummy/app/jobs/process_messenger_callback_job.rb
190
201
  - spec/dummy/app/views/layouts/application.html.erb
202
+ - spec/dummy/app/webhooks/account_linking_callback.rb
191
203
  - spec/dummy/app/webhooks/authentication_callback.rb
192
204
  - spec/dummy/app/webhooks/message_delivered_callback.rb
205
+ - spec/dummy/app/webhooks/message_read_callback.rb
193
206
  - spec/dummy/app/webhooks/message_received_callback.rb
194
207
  - spec/dummy/app/webhooks/postback_callback.rb
195
208
  - spec/dummy/bin/bundle
@@ -223,12 +236,17 @@ files:
223
236
  - spec/dummy/public/500.html
224
237
  - spec/dummy/public/favicon.ico
225
238
  - spec/fixtures/12057251_909506139117248_2059695706_n.png
239
+ - spec/fixtures/SampleVideo_1280x720_1mb.mp4
240
+ - spec/fixtures/account_link.json
226
241
  - spec/fixtures/delivery_request.json
242
+ - spec/fixtures/jailhouse-rock-demo.mp3
243
+ - spec/fixtures/message_read.json
227
244
  - spec/fixtures/message_request.json
228
245
  - spec/fixtures/message_request_with_attachment.json
229
246
  - spec/fixtures/optin_request.json
230
247
  - spec/fixtures/postback_request.json
231
248
  - spec/helpers/application_helper_spec.rb
249
+ - spec/message_quickly/api/account_link_spec.rb
232
250
  - spec/message_quickly/api/messages_spec.rb
233
251
  - spec/message_quickly/api/thread_settings_spec.rb
234
252
  - spec/message_quickly/api/user_profile_spec.rb
@@ -268,8 +286,10 @@ test_files:
268
286
  - spec/dummy/app/helpers/application_helper.rb
269
287
  - spec/dummy/app/jobs/process_messenger_callback_job.rb
270
288
  - spec/dummy/app/views/layouts/application.html.erb
289
+ - spec/dummy/app/webhooks/account_linking_callback.rb
271
290
  - spec/dummy/app/webhooks/authentication_callback.rb
272
291
  - spec/dummy/app/webhooks/message_delivered_callback.rb
292
+ - spec/dummy/app/webhooks/message_read_callback.rb
273
293
  - spec/dummy/app/webhooks/message_received_callback.rb
274
294
  - spec/dummy/app/webhooks/postback_callback.rb
275
295
  - spec/dummy/bin/bundle
@@ -305,12 +325,17 @@ test_files:
305
325
  - spec/dummy/Rakefile
306
326
  - spec/dummy/README.rdoc
307
327
  - spec/fixtures/12057251_909506139117248_2059695706_n.png
328
+ - spec/fixtures/account_link.json
308
329
  - spec/fixtures/delivery_request.json
330
+ - spec/fixtures/jailhouse-rock-demo.mp3
331
+ - spec/fixtures/message_read.json
309
332
  - spec/fixtures/message_request.json
310
333
  - spec/fixtures/message_request_with_attachment.json
311
334
  - spec/fixtures/optin_request.json
312
335
  - spec/fixtures/postback_request.json
336
+ - spec/fixtures/SampleVideo_1280x720_1mb.mp4
313
337
  - spec/helpers/application_helper_spec.rb
338
+ - spec/message_quickly/api/account_link_spec.rb
314
339
  - spec/message_quickly/api/messages_spec.rb
315
340
  - spec/message_quickly/api/thread_settings_spec.rb
316
341
  - spec/message_quickly/api/user_profile_spec.rb