email_agent.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. module Agents
  2. class EmailAgent < Agent
  3. include EmailConcern
  4. cannot_be_scheduled!
  5. cannot_create_events!
  6. description <<-MD
  7. The EmailAgent sends any events it receives via email immediately.
  8. The email will be sent to your account's address and will have a `subject` and an optional `headline` before
  9. listing the Events. If the Events' payloads contain a `:message`, that will be highlighted, otherwise everything in
  10. their payloads will be shown.
  11. Set `expected_receive_period_in_days` to the maximum amount of time that you'd expect to pass between Events being received by this Agent.
  12. MD
  13. def default_options
  14. {
  15. 'subject' => "You have a notification!",
  16. 'headline' => "Your notification:",
  17. 'expected_receive_period_in_days' => "2"
  18. }
  19. end
  20. def receive(incoming_events)
  21. incoming_events.each do |event|
  22. log "Sending digest mail to #{user.email} with event #{event.id}"
  23. SystemMailer.delay.send_message(:to => user.email, :subject => interpolated(event.payload)['subject'], :headline => interpolated(event.payload)['headline'], :groups => [present(event.payload)])
  24. end
  25. end
  26. end
  27. end