Nessuna descrizione http://j1x-huginn.herokuapp.com

email_agent.rb 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. module Agents
  2. class EmailAgent < Agent
  3. include EmailConcern
  4. cannot_be_scheduled!
  5. cannot_create_events!
  6. no_bulk_receive!
  7. description <<-MD
  8. The Email Agent sends any events it receives via email immediately.
  9. You can specify the email's subject line by providing a `subject` option, which can contain Liquid formatting. E.g.,
  10. you could provide `"Huginn email"` to set a simple subject, or `{{subject}}` to use the `subject` key from the incoming Event.
  11. By default, the email body will contain an optional `headline`, followed by a listing of the Events' keys.
  12. You can customize the email body by including the optional `body` param. Like the `subject`, the `body` can be a simple message
  13. or a Liquid template. You could send only the Event's `some_text` field with a `body` set to `{{ some_text }}`.
  14. The body can contain simple HTML and will be sanitized.
  15. You can specify one or more `recipients` for the email, or skip the option in order to send the email to your
  16. account's default email address.
  17. You can provide a `from` address for the email, or leave it blank to default to the value of `EMAIL_FROM_ADDRESS` (`#{ENV['EMAIL_FROM_ADDRESS']}`).
  18. 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.
  19. MD
  20. def default_options
  21. {
  22. 'subject' => "You have a notification!",
  23. 'headline' => "Your notification:",
  24. 'expected_receive_period_in_days' => "2"
  25. }
  26. end
  27. def receive(incoming_events)
  28. incoming_events.each do |event|
  29. recipients(event.payload).each do |recipient|
  30. log "Sending mail to #{recipient} with event #{event.id}"
  31. SystemMailer.send_message(
  32. to: recipient,
  33. from: interpolated(event)['from'],
  34. subject: interpolated(event)['subject'],
  35. headline: interpolated(event)['headline'],
  36. body: interpolated(event)['body'],
  37. groups: [present(event.payload)]
  38. ).deliver_later
  39. end
  40. end
  41. end
  42. end
  43. end