nuntius 1.0.27 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +77 -18
  3. data/Rakefile +15 -42
  4. data/app/controllers/nuntius/admin/campaigns_controller.rb +12 -10
  5. data/app/controllers/nuntius/admin/layouts/attachments_controller.rb +2 -1
  6. data/app/controllers/nuntius/admin/layouts_controller.rb +1 -1
  7. data/app/controllers/nuntius/admin/lists/subscribers_controller.rb +1 -1
  8. data/app/controllers/nuntius/admin/lists_controller.rb +4 -4
  9. data/app/controllers/nuntius/admin/locales_controller.rb +3 -2
  10. data/app/controllers/nuntius/admin/messages_controller.rb +2 -2
  11. data/app/controllers/nuntius/admin/templates_controller.rb +1 -1
  12. data/app/controllers/nuntius/api/events_controller.rb +2 -2
  13. data/app/controllers/nuntius/application_admin_controller.rb +1 -1
  14. data/app/controllers/nuntius/callbacks_controller.rb +4 -4
  15. data/app/controllers/nuntius/dashboard_controller.rb +1 -1
  16. data/app/controllers/nuntius/feedback_controller.rb +1 -2
  17. data/app/controllers/nuntius/inbound_messages/twilio_inbound_smses_controller.rb +7 -7
  18. data/app/controllers/nuntius/messages_controller.rb +1 -1
  19. data/app/controllers/nuntius/subscribers_controller.rb +33 -0
  20. data/app/drops/nuntius/list_drop.rb +7 -0
  21. data/app/drops/nuntius/subscriber_drop.rb +7 -0
  22. data/app/exceptions/nuntius/base_exception.rb +2 -0
  23. data/app/exceptions/nuntius/missing_messenger_exception.rb +2 -0
  24. data/app/helpers/nuntius/application_helper.rb +6 -11
  25. data/app/jobs/nuntius/deliver_inbound_message_job.rb +1 -1
  26. data/app/jobs/nuntius/purge_message_job.rb +2 -2
  27. data/app/jobs/nuntius/retrieve_mail_job.rb +2 -2
  28. data/app/jobs/nuntius/transport_delivery_job.rb +2 -2
  29. data/app/message_boxes/nuntius/base_message_box.rb +46 -23
  30. data/app/messengers/nuntius/base_messenger.rb +13 -12
  31. data/app/models/nuntius/application_record.rb +1 -1
  32. data/app/models/nuntius/attachment.rb +4 -2
  33. data/app/models/nuntius/campaign.rb +4 -51
  34. data/app/models/nuntius/concerns/yamlify.rb +2 -2
  35. data/app/models/nuntius/inbound_message.rb +2 -0
  36. data/app/models/nuntius/list.rb +11 -1
  37. data/app/models/nuntius/message.rb +34 -29
  38. data/app/models/nuntius/subscriber.rb +21 -1
  39. data/app/models/nuntius/template.rb +20 -20
  40. data/app/presenters/application_presenter.rb +1 -1
  41. data/app/presenters/template_presenter.rb +3 -3
  42. data/app/providers/nuntius/apnotic_push_provider.rb +17 -17
  43. data/app/providers/nuntius/base_provider.rb +6 -6
  44. data/app/providers/nuntius/firebase_push_provider.rb +8 -8
  45. data/app/providers/nuntius/houston_push_provider.rb +15 -15
  46. data/app/providers/nuntius/message_bird_sms_provider.rb +7 -7
  47. data/app/providers/nuntius/slack_slack_provider.rb +7 -7
  48. data/app/providers/nuntius/smtp_mail_provider.rb +36 -28
  49. data/app/providers/nuntius/teams_teams_provider.rb +25 -0
  50. data/app/providers/nuntius/twilio_sms_provider.rb +4 -4
  51. data/app/providers/nuntius/twilio_voice_provider.rb +13 -13
  52. data/app/services/nuntius/aws_sns_processor_service.rb +11 -11
  53. data/app/services/nuntius/deliver_campaign_service.rb +65 -0
  54. data/app/services/nuntius/deliver_inbound_message_service.rb +3 -2
  55. data/app/services/nuntius/retrieve_inbound_mail_service.rb +23 -16
  56. data/app/tables/nuntius_campaigns_table.rb +10 -1
  57. data/app/tables/nuntius_layouts_table.rb +4 -4
  58. data/app/tables/nuntius_lists_table.rb +1 -1
  59. data/app/tables/nuntius_locales_table.rb +1 -1
  60. data/app/tables/nuntius_messages_table.rb +5 -5
  61. data/app/tables/nuntius_subscribers_table.rb +3 -2
  62. data/app/tables/nuntius_templates_table.rb +12 -5
  63. data/app/transports/nuntius/base_transport.rb +1 -1
  64. data/app/transports/nuntius/mail_transport.rb +1 -1
  65. data/app/transports/nuntius/push_transport.rb +1 -1
  66. data/app/transports/nuntius/teams_transport.rb +6 -0
  67. data/app/views/nuntius/admin/campaigns/edit.html.slim +12 -16
  68. data/app/views/nuntius/admin/campaigns/index.html.slim +2 -2
  69. data/app/views/nuntius/admin/layouts/attachments/create.json.jbuilder +3 -3
  70. data/app/views/nuntius/admin/layouts/edit.html.slim +18 -19
  71. data/app/views/nuntius/admin/layouts/index.html.slim +2 -2
  72. data/app/views/nuntius/admin/lists/edit.html.slim +19 -9
  73. data/app/views/nuntius/admin/lists/index.html.slim +2 -2
  74. data/app/views/nuntius/admin/lists/subscribers/edit.html.slim +2 -2
  75. data/app/views/nuntius/admin/locales/edit.html.slim +3 -3
  76. data/app/views/nuntius/admin/locales/index.html.slim +2 -2
  77. data/app/views/nuntius/admin/messages/index.html.slim +2 -2
  78. data/app/views/nuntius/admin/messages/show.html.slim +12 -12
  79. data/app/views/nuntius/admin/templates/edit.html.slim +62 -64
  80. data/app/views/nuntius/admin/templates/index.html.slim +2 -2
  81. data/app/views/nuntius/dashboard/show.html.slim +2 -6
  82. data/app/views/nuntius/subscribers/show.html.slim +9 -0
  83. data/config/locales/en.yml +97 -1
  84. data/config/routes.rb +18 -8
  85. data/db/migrate/20190301201541_create_nuntius_templates.rb +5 -5
  86. data/db/migrate/20190301202436_create_nuntius_messages.rb +4 -4
  87. data/db/migrate/20190322114340_create_nuntius_campaigns.rb +2 -2
  88. data/db/migrate/20190322121338_create_nuntius_subscribers.rb +1 -1
  89. data/db/migrate/20190327124407_create_nuntius_layouts.rb +5 -5
  90. data/db/migrate/20190327143921_add_campaign_to_message.rb +1 -1
  91. data/db/migrate/20190417125153_change_message_status_default.rb +2 -2
  92. data/db/migrate/20190825080757_update_nuntius_message_sending_to_sent.rb +2 -2
  93. data/db/migrate/20200220154927_change_nuntius_templates_payload_type.rb +1 -1
  94. data/db/migrate/20200318095339_create_nuntius_attachments.rb +2 -2
  95. data/db/migrate/20201121185718_create_nuntius_inbound_messages.rb +1 -1
  96. data/db/migrate/20240205204719_add_description_to_list.rb +5 -0
  97. data/db/migrate/20240206203019_add_slug_to_nuntius_list.rb +9 -0
  98. data/lib/nuntius/active_record_helpers.rb +6 -5
  99. data/lib/nuntius/configuration.rb +64 -27
  100. data/lib/nuntius/deprecator.rb +2 -0
  101. data/lib/nuntius/devise.rb +4 -3
  102. data/lib/nuntius/engine.rb +12 -27
  103. data/lib/nuntius/i18n_store.rb +6 -5
  104. data/lib/nuntius/life_cycle.rb +28 -0
  105. data/lib/nuntius/liquid/tags/attach_tag.rb +11 -11
  106. data/lib/nuntius/mail_allow_list.rb +2 -2
  107. data/lib/nuntius/nuntiable.rb +3 -1
  108. data/lib/nuntius/state_machine.rb +27 -5
  109. data/lib/nuntius/version.rb +1 -1
  110. data/lib/nuntius.rb +13 -27
  111. data/lib/preamble.rb +18 -18
  112. data/lib/tasks/nuntius_tasks.rake +4 -4
  113. metadata +58 -57
  114. data/app/jobs/nuntius/process_inbound_message_job.rb +0 -10
  115. data/app/reportlets/nuntius/application_reportlet.rb +0 -35
  116. data/app/reportlets/nuntius/daily_messages_per_template_reportlet.rb +0 -50
  117. data/config/webpack/development.js +0 -5
  118. data/config/webpack/environment.js +0 -4
  119. data/config/webpack/production.js +0 -5
  120. data/config/webpack/test.js +0 -5
  121. data/config/webpacker.yml +0 -119
  122. data/lib/nuntius/transactio.rb +0 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 736ed78b3a455b90aad20c47ba9bf6c3946cb7d45dc064c33d689a622ac40f18
4
- data.tar.gz: c2f9abeeffe69fe5f28df8af6b0ff1c72c3c73d743b9156f0a12ed6daca3d1a9
3
+ metadata.gz: aa439d75f1be61c5122338f9d0c2c74b68d016e91208756d9ad2be119845ad51
4
+ data.tar.gz: 164ff8b68eb4912eaabade99a3ee39e593d5c2274345211601dccf14d6bb11c1
5
5
  SHA512:
6
- metadata.gz: a6fe800fc712a05dc2a35166a28a6d3c0d41f248365ca1cdb3f529f1430e77ca11553342cc0681490b1aaad952de6f87b89412f8329501e79765c556efa3428f
7
- data.tar.gz: 4e79093e36ffeb8967aa5568a064b41828c33dcd3da32bf87ff0a5ed3504f5c3dc2794560c237254e63ed042a521442d3c51e57ca54690f209057e5bc29b73a5
6
+ metadata.gz: 3f40c494fc93610eee81a49f8b648b7cb3dafa8be578b051d24cfa8a052536ce69f6eb252df05eb98c5367bd28fe10c5109ad668b10efde3b015355282293e92
7
+ data.tar.gz: 65088baae2f8f957ac6dab1c14d9945d43e594149c9074d257d4a1db5f6f582a02801642c4348c3cd8b2a5c02c93ade63599d61d474869e30920a06e2d75cbd6
data/README.md CHANGED
@@ -159,14 +159,12 @@ Nuntius.event('packed', packing: {smurrefluts: 'hatseflats'})
159
159
 
160
160
  The main key of the hash passed will also be the liquid variable.
161
161
 
162
- ### Inbound
163
-
164
- Inbound messages are also possible, currently mail/IMAP and Twilio inbound SMS are supported.
165
-
166
162
  ## Transports
167
163
 
168
164
  ### Mail
169
165
 
166
+ Outbound mail is handled through SMTP. We've only exposed the HTML of mail, we can create text-versions based on sanitized HTML. HTML allows for [Foundation for Emails](https://get.foundation/emails/docs/index.html). You will have to include the CSS in the layouts.
167
+
170
168
  #### AWS SES
171
169
 
172
170
  In case you use AWS SES, you can use the SNS Feedback Notifications to automatically mark messages as read, or deal with complaints and bounces. Create a AWS SNS topic, with a HTTPS subscription with the following URL (pattern):
@@ -179,27 +177,47 @@ The subscription will automatically be confirmed.
179
177
 
180
178
  Next in AWS SES, configure the SNS topic to receive feedback notifications for Bounce, Complaint and Delivery and include original headers.
181
179
 
180
+ ### Slack
181
+
182
+ Slack uses the [postMessage](https://api.slack.com/methods/chat.postMessage) method to send messages. It will also upload any attachment the message has prior to sending the message itself.
183
+
184
+ The message body is specified using `text` and additionally supports the `payload` parameter.
185
+
186
+ The payload is merged with the `text`, `to` (channel or user) and `from`.
187
+
188
+ ### Teams
189
+
190
+ For Microsoft Teams you need to have the webhook URL for a channel. You right-click the channel (not the team) and click "Manage channel".
191
+ Then on the settings click "Edit" under "Manage the connectors that post to this channel", then search for "Incoming Webhook" and add it and configure it.
192
+ You can give it a name and an image.
193
+
194
+ See [Create Incoming Webhooks](https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook?tabs=newteams%2Cdotnet) for details.
195
+
182
196
  ### SMS
183
197
 
184
- ### Push
198
+ SMS just support the `from` (name or phone number), `to` (the phone) and `text` attribute.
199
+
200
+ Only MessageBird allows for names when sending SMS messages. Messagebird does not support a hypen in the name, just alphabetical characters (A-Za-z).
185
201
 
186
202
  ### Voice
187
203
 
188
- #### Twilio
204
+ Currently only Twilio voice is supported in the voice transport.
205
+
206
+ Information on voice TWIML is here: https://www.twilio.com/docs/voice/twiml
207
+ You can try voices here: https://www.twilio.com/docs/voice/twiml/say/text-speech
189
208
 
190
- Information on voice TWIML is here: https://www.twilio.com/docs/voice/twiml/gather
191
- You can try voices here: https://www.twilio.com/console/voice/twiml/text-to-speech
209
+ The Voice transport is particularly nice, because you can define whole paths in the message body, for example:
192
210
 
193
211
  ```
194
212
  <?xml version="1.0" encoding="UTF-8"?>
195
213
  <Response>
196
- <Say language="nl-NL">
197
- Hallo, dit is een bericht van Boxture!
214
+ <Say language="en-US">
215
+ Hello Earthling, this is a message from your Robot Overlords!
198
216
  <break strength="x-weak" time="100ms"/>
199
- <p>We geven je zo je wachtwoord-herstel-code, dus pak een pen en schrijf mee.</p>
217
+ <p>We will soon give you your escape-hatch-code, so grab a pen and write it down.</p>
200
218
  </Say>
201
219
  <Gather input="dtmf" numDigits="1" action="{%raw%}{{url}}{%endraw%}/code">
202
- <Say language="nl-NL">Druk een toets om verder te gaan.</Say>
220
+ <Say language="en-US">Press any key to continue.</Say>
203
221
  </Gather>
204
222
  <Redirect>{%raw%}{{url}}{%endraw%}/code</Redirect>
205
223
  </Response>
@@ -210,20 +228,61 @@ path: /code
210
228
  <?xml version="1.0" encoding="UTF-8"?>
211
229
  <Response>
212
230
  <Gather input="dtmf" numDigits="1">
213
- <Say language="nl-NL">
214
- <s>Je code is:</s>
231
+ <Say language="en-US">
232
+ <s>Your code is:</s>
215
233
  <break strength="x-weak" time="100ms"/>
216
- <prosody rate="x-slow"><say-as interpret-as="character">1 n a x d 8 b</say-as></prosody>
234
+ <prosody rate="x-slow"><say-as interpret-as="character">s e n d h e l p</say-as></prosody>
217
235
  <break strength="x-weak" time="1s"/>
218
- Druk een toets om te herhalen, of hang op.
236
+ Press any key to continue, or just hang up.
219
237
  </Say>
220
238
  </Gather>
221
239
  <Redirect>{%raw%}{{url}}{%endraw%}/code</Redirect>
222
240
  </Response>
223
241
  ```
224
242
 
225
- ## Testing
243
+ ### Inbound
244
+
245
+ Inbound messages are also possible, currently mail/IMAP and Twilio inbound SMS are supported.
246
+ This is done using message-boxes, for this to work you need to add a `message_boxes` folder to your `app` folder.
247
+
248
+ #### SMS
249
+
250
+ Twilio is currently the only supported inbound SMS provider.
251
+ Point Twilio to you nuntius mount path (/messaging/inbound_messages/twilio_inbound_smses)
252
+
253
+ ```ruby
254
+ class FooMessageBox < Nuntius::BaseMessageBox
255
+ transport :sms
256
+ provider :twilio
226
257
 
258
+ route /\+31.+/, to: :dutchies
259
+ end
227
260
  ```
228
- bundle exec sidekiq -C test/dummy/config/sidekiq.yml -r test/dummy
261
+
262
+ #### Mail
263
+ Nuntius will look at a mailbox and for each of the mails will check whether it can find a route for it in any of the message-boxes.
264
+ After delivery, on the next round of fetching mail, nuntius will move processed message to the Archive folder
265
+
266
+ ```ruby
267
+ class BarMessageBox < Nuntius::BaseMessageBox
268
+ transport :mail
269
+ provider :imap
270
+
271
+ settings({
272
+ address: 'imap.gmail.com',
273
+ port: 993,
274
+ user_name: '',
275
+ password: '',
276
+ authentication: '',
277
+ enable_ssl: false,
278
+ enable_starttls: false
279
+ })
280
+
281
+ route to: :process
282
+
283
+ def process
284
+ puts message.status # Message is Nuntius's inbound message.
285
+ puts mail.to
286
+ end
287
+ end
229
288
  ```
data/Rakefile CHANGED
@@ -1,62 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  begin
4
- require 'bundler/setup'
4
+ require "bundler/setup"
5
5
  rescue LoadError
6
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
7
7
  end
8
8
 
9
- require 'rdoc/task'
9
+ require "rdoc/task"
10
10
 
11
11
  RDoc::Task.new(:rdoc) do |rdoc|
12
- rdoc.rdoc_dir = 'rdoc'
13
- rdoc.title = 'Nuntius'
14
- rdoc.options << '--line-numbers'
15
- rdoc.rdoc_files.include('README.md')
16
- rdoc.rdoc_files.include('lib/**/*.rb')
12
+ rdoc.rdoc_dir = "rdoc"
13
+ rdoc.title = "Nuntius"
14
+ rdoc.options << "--line-numbers"
15
+ rdoc.rdoc_files.include("README.md")
16
+ rdoc.rdoc_files.include("lib/**/*.rb")
17
17
  end
18
18
 
19
- APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
20
- load 'rails/tasks/engine.rake'
19
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
20
+ load "rails/tasks/engine.rake"
21
21
 
22
- load 'rails/tasks/statistics.rake'
22
+ load "rails/tasks/statistics.rake"
23
23
 
24
- require 'bundler/gem_tasks'
24
+ require "bundler/gem_tasks"
25
25
 
26
- require 'rake/testtask'
26
+ require "rake/testtask"
27
27
 
28
28
  Rake::TestTask.new(:test) do |t|
29
- t.libs << 'test'
30
- t.pattern = 'test/**/*_test.rb'
29
+ t.libs << "test"
30
+ t.pattern = "test/**/*_test.rb"
31
31
  t.verbose = false
32
32
  t.warning = false
33
33
  end
34
34
 
35
35
  task default: :test
36
-
37
- # Adds the Auxilium semver task
38
- spec = Gem::Specification.find_by_name 'auxilium'
39
- load "#{spec.gem_dir}/lib/tasks/semver.rake"
40
-
41
- namespace :nuntius do
42
- namespace :webpacker do
43
- desc 'Install deps with yarn'
44
- task :yarn_install do
45
- Dir.chdir(File.join(__dir__, '../..')) do
46
- system 'yarn install --no-progress --production'
47
- end
48
- end
49
-
50
- desc 'Compile JavaScript packs using webpack for production with digests'
51
- task compile: %i[yarn_install environment] do
52
- Webpacker.with_node_env('production') do
53
- if Nuntius.webpacker.commands.compile
54
- # Successful compilation!
55
- else
56
- # Failed compilation
57
- exit!
58
- end
59
- end
60
- end
61
- end
62
- end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_dependency 'nuntius/application_admin_controller'
3
+ require_dependency "nuntius/application_admin_controller"
4
4
 
5
5
  module Nuntius
6
6
  module Admin
@@ -24,17 +24,19 @@ module Nuntius
24
24
  redirect_to :edit_admin_campaign, status: :see_other
25
25
  end
26
26
 
27
- def edit; end
27
+ def edit
28
+ end
28
29
 
29
30
  def update
30
- saved = @campaign.update(campaign_params)
31
-
32
- if saved && params[:commit] == 'send'
33
- @campaign.publish! if @campaign.can_publish?
34
- redirect_to :edit_admin_campaign, status: :see_other
35
- else
36
- respond_with :admin, @campaign
37
- end
31
+ @campaign.update(campaign_params)
32
+
33
+ respond_with :admin, @campaign
34
+ end
35
+
36
+ def publish
37
+ @campaign.publish! if @campaign.can_publish?
38
+
39
+ redirect_to :admin_campaigns, status: :see_other
38
40
  end
39
41
 
40
42
  private
@@ -6,7 +6,8 @@ module Nuntius
6
6
  class AttachmentsController < ApplicationController
7
7
  before_action :set_objects
8
8
 
9
- def index; end
9
+ def index
10
+ end
10
11
 
11
12
  def create
12
13
  params[:attachments].each do |file|
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_dependency 'nuntius/application_admin_controller'
3
+ require_dependency "nuntius/application_admin_controller"
4
4
 
5
5
  module Nuntius
6
6
  module Admin
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_dependency 'nuntius/application_admin_controller'
3
+ require_dependency "nuntius/application_admin_controller"
4
4
 
5
5
  module Nuntius
6
6
  module Admin
@@ -1,11 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_dependency 'nuntius/application_admin_controller'
3
+ require_dependency "nuntius/application_admin_controller"
4
4
 
5
5
  module Nuntius
6
6
  module Admin
7
7
  class ListsController < ApplicationAdminController
8
-
9
8
  def index
10
9
  @lists = Nuntius::List.visible.order(:name)
11
10
  end
@@ -36,10 +35,11 @@ module Nuntius
36
35
 
37
36
  private
38
37
 
39
- def set_objects; end
38
+ def set_objects
39
+ end
40
40
 
41
41
  def list_params
42
- params.require(:list).permit(:name)
42
+ params.require(:list).permit(:name, :slug, :allow_unsubscribe, :description, :metadata_yaml)
43
43
  end
44
44
  end
45
45
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_dependency 'nuntius/application_admin_controller'
3
+ require_dependency "nuntius/application_admin_controller"
4
4
 
5
5
  module Nuntius
6
6
  module Admin
@@ -36,7 +36,8 @@ module Nuntius
36
36
 
37
37
  private
38
38
 
39
- def set_objects; end
39
+ def set_objects
40
+ end
40
41
 
41
42
  def locale_params
42
43
  params.require(:locale).permit(:key, :data, :metadata_yaml, :data_yaml)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_dependency 'nuntius/application_admin_controller'
3
+ require_dependency "nuntius/application_admin_controller"
4
4
 
5
5
  module Nuntius
6
6
  module Admin
@@ -17,7 +17,7 @@ module Nuntius
17
17
  def resend
18
18
  @message = Nuntius::Message.visible.find(params[:id])
19
19
  @message.resend
20
- respond_with @message, success: t('.resend_success'), error: t('.resend_error')
20
+ respond_with @message, success: t(".resend_success"), error: t(".resend_error")
21
21
  end
22
22
  end
23
23
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_dependency 'nuntius/application_admin_controller'
3
+ require_dependency "nuntius/application_admin_controller"
4
4
 
5
5
  module Nuntius
6
6
  module Admin
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_dependency 'nuntius/application_controller'
3
+ require_dependency "nuntius/application_controller"
4
4
 
5
5
  module Nuntius
6
6
  class Api::EventsController < ApplicationController
@@ -10,7 +10,7 @@ module Nuntius
10
10
 
11
11
  def create
12
12
  nuntius_params = params.except(:scope, :event, :context, :controller, :action).permit!.to_h
13
- Nuntius.event(params[:event], { params[:scope] => params[:context].permit!.to_h }, nuntius_params)
13
+ Nuntius.event(params[:event], {params[:scope] => params[:context].permit!.to_h}, nuntius_params)
14
14
  end
15
15
  end
16
16
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_dependency 'nuntius/application_controller'
3
+ require_dependency "nuntius/application_controller"
4
4
 
5
5
  module Nuntius
6
6
  class ApplicationAdminController < ApplicationController
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_dependency 'nuntius/application_controller'
4
- require 'preamble'
3
+ require_dependency "nuntius/application_controller"
4
+ require "preamble"
5
5
 
6
6
  module Nuntius
7
7
  class CallbacksController < ApplicationController
@@ -14,8 +14,8 @@ module Nuntius
14
14
  response = message.nuntius_provider(message).callback(params)
15
15
 
16
16
  render body: response[2].first,
17
- content_type: response[1]['Content-Type'],
18
- layout: false
17
+ content_type: response[1]["Content-Type"],
18
+ layout: false
19
19
  end
20
20
  end
21
21
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_dependency 'nuntius/application_admin_controller'
3
+ require_dependency "nuntius/application_admin_controller"
4
4
 
5
5
  module Nuntius
6
6
  class DashboardController < ApplicationAdminController
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_dependency 'nuntius/application_controller'
4
- require 'httpclient'
3
+ require_dependency "nuntius/application_controller"
5
4
 
6
5
  module Nuntius
7
6
  class FeedbackController < ApplicationController
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_dependency 'nuntius/application_controller'
4
- require 'twilio-ruby'
3
+ require_dependency "nuntius/application_controller"
4
+ require "twilio-ruby"
5
5
 
6
6
  module Nuntius
7
7
  module InboundMessages
@@ -29,27 +29,27 @@ module Nuntius
29
29
  # 'NumSegments' => '1',
30
30
  # 'MessageSid' => 'SMb711289e438f577f230f5837e9c74a08',
31
31
  # 'AccountSid' => 'ACf54dd7a47a8011d65b54d472a7190549',
32
- # 'From' => '+31641085630',
32
+ # 'From' => '+31612345678',
33
33
  # 'ApiVersion' => '2010-04-01',
34
34
  # 'controller' => 'nuntius/inbound_messages/twilio_inbound_smses',
35
35
  # 'action' => 'create' }
36
36
  def create
37
- inbound_message = Nuntius::InboundMessage.find_or_create_by!(transport: 'sms', provider: 'twilio', provider_id: params[:SmsSid])
37
+ inbound_message = Nuntius::InboundMessage.find_or_create_by!(transport: "sms", provider: "twilio", provider_id: params[:SmsSid])
38
38
  inbound_message.from = params[:From]
39
39
  inbound_message.to = params[:To]
40
40
  inbound_message.text = params[:Body]
41
41
  inbound_message.metadata = params
42
42
  inbound_message.save!
43
43
 
44
- twiml = Nuntius::DeliverInboundMessageService.new(inbound_message).call
44
+ twiml = Nuntius::DeliverInboundMessageService.perform(inbound_message: inbound_message)
45
45
 
46
46
  # twiml = Twilio::TwiML::MessagingResponse.new do |resp|
47
47
  # resp.message body: 'The Robots are coming! Head for the hills!'
48
48
  # end
49
49
 
50
50
  render body: twiml.to_s,
51
- content_type: 'text/xml',
52
- layout: false
51
+ content_type: "text/xml",
52
+ layout: false
53
53
  end
54
54
  end
55
55
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_dependency 'nuntius/application_controller'
3
+ require_dependency "nuntius/application_controller"
4
4
 
5
5
  module Nuntius
6
6
  class MessagesController < ApplicationController
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_dependency "nuntius/application_controller"
4
+
5
+ module Nuntius
6
+ class SubscribersController < ApplicationController
7
+ # skip_before_action :authenticate_user!, only: %i[show destroy]
8
+
9
+ def show
10
+ @subscriber = Nuntius::Subscriber.find_by(id: params[:id])
11
+ if @subscriber
12
+ @list = @subscriber.list
13
+ else
14
+ flash[:notice] = "Subscription not found."
15
+ redirect_to root_path, status: :see_other
16
+ end
17
+ end
18
+
19
+ def subscribe
20
+ @subscriber = Nuntius::Subscriber.find(params[:id])
21
+ @subscriber.update(unsubscribed_at: nil)
22
+ flash[:notice] = "Subscription has been restored."
23
+ redirect_to nuntius.subscriber_path(@subscriber), status: :see_other
24
+ end
25
+
26
+ def unsubscribe
27
+ @subscriber = Nuntius::Subscriber.find(params[:id])
28
+ @subscriber.touch(:unsubscribed_at)
29
+ flash[:notice] = "Subscription has been removed."
30
+ redirect_to nuntius.subscriber_path(@subscriber), status: :see_other
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nuntius
4
+ class ListDrop < ApplicationDrop
5
+ delegate :id, :name, :allow_unsubscribe, to: :@object
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nuntius
4
+ class SubscriberDrop < ApplicationDrop
5
+ delegate :id, :first_name, :last_name, :name, :list, to: :@object
6
+ end
7
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nuntius
2
4
  class BaseException < StandardError
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nuntius
2
4
  class MissingMessengerException < BaseException
3
5
  end
@@ -4,11 +4,12 @@ module Nuntius
4
4
  module ApplicationHelper
5
5
  def nuntius_dashboard_menu
6
6
  Satis::Menus::Builder.build(:dashboard) do |m|
7
- m.item :templates, link: nuntius.admin_templates_path, icon: 'fal fa-file'
8
- m.item :layouts, link: nuntius.admin_layouts_path, icon: 'fal fa-table-layout'
9
- m.item :locales, link: nuntius.admin_locales_path, icon: 'fal fa-language'
10
- m.item :campaigns, link: nuntius.admin_campaigns_path, icon: 'fal fa-megaphone'
11
- m.item :lists, link: nuntius.admin_lists_path, icon: 'fal fa-address-book'
7
+ m.item :messages, link: nuntius.admin_messages_path, icon: "fal fa-envelope"
8
+ m.item :templates, link: nuntius.admin_templates_path, icon: "fal fa-file"
9
+ m.item :layouts, link: nuntius.admin_layouts_path, icon: "fal fa-table-layout"
10
+ m.item :locales, link: nuntius.admin_locales_path, icon: "fal fa-language"
11
+ m.item :campaigns, link: nuntius.admin_campaigns_path, icon: "fal fa-megaphone"
12
+ m.item :lists, link: nuntius.admin_lists_path, icon: "fal fa-address-book"
12
13
  end
13
14
  end
14
15
 
@@ -18,12 +19,6 @@ module Nuntius
18
19
  end
19
20
  end
20
21
 
21
- def nuntius_messages_menu
22
- Satis::Menus::Builder.build(:messages) do |m|
23
- m.item :new, link: nuntius.new_admin_message_path
24
- end
25
- end
26
-
27
22
  def nuntius_layouts_menu
28
23
  Satis::Menus::Builder.build(:layouts) do |m|
29
24
  m.item :new, link: nuntius.new_admin_layout_path
@@ -4,7 +4,7 @@
4
4
  module Nuntius
5
5
  class DeliverInboundMessageJob < ApplicationJob
6
6
  def perform(inbound_message)
7
- Nuntius::DeliverInboundMessageService.new(inbound_message).call
7
+ Nuntius::DeliverInboundMessageService.perform(inbound_message: inbound_message)
8
8
  end
9
9
  end
10
10
  end
@@ -2,8 +2,8 @@ module Nuntius
2
2
  class PurgeMessageJob < ApplicationJob
3
3
  def perform(account_id, months)
4
4
  messages = Nuntius::Message.distinct.select(:id).where("metadata ->> 'account_id' = :account", account: account_id)
5
- .where(created_at: ..months.months.ago.beginning_of_day)
6
- .where.not(status: %w[complaint bounced])
5
+ .where(created_at: ..months.months.ago.beginning_of_day)
6
+ .where.not(status: %w[complaint bounced])
7
7
 
8
8
  Nuntius::Message.where(parent_message_id: messages.pluck(:id)).in_batches.update_all(parent_message_id: nil)
9
9
 
@@ -7,10 +7,10 @@ module Nuntius
7
7
  klasses = Nuntius::BaseMessageBox.message_box_for(transport: :mail)
8
8
 
9
9
  klasses.each do |klass|
10
- RetrieveInboundMailService.new(klass.settings).call
10
+ RetrieveInboundMailService.perform(settings: klass.settings)
11
11
  end
12
12
 
13
- Nuntius::InboundMessage.where(status: 'pending').each do |message|
13
+ Nuntius::InboundMessage.where(status: "pending").each do |message|
14
14
  Nuntius::DeliverInboundMessageJob.perform_later(message)
15
15
  end
16
16
  end
@@ -11,8 +11,8 @@ module Nuntius
11
11
  original_message = message
12
12
  message = message.dup
13
13
  message.parent_message = original_message
14
- message.status = 'pending'
15
- message.provider_id = ''
14
+ message.status = "pending"
15
+ message.provider_id = ""
16
16
  end
17
17
  message.provider = provider_name
18
18
  message.save!