slack.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. class NotificationFactory::Slack
  2. =begin
  3. result = NotificationFactory::Slack.template(
  4. template: 'ticket_update',
  5. locale: 'en-us',
  6. objects: {
  7. recipient: User.find(2),
  8. ticket: Ticket.find(1)
  9. },
  10. )
  11. returns
  12. {
  13. subject: 'some subject',
  14. body: 'some body',
  15. }
  16. =end
  17. def self.template(data)
  18. if data[:templateInline]
  19. return NotificationFactory::Renderer.new(data[:objects], data[:locale], data[:templateInline]).render
  20. end
  21. template = NotificationFactory.template_read(
  22. locale: data[:locale] || 'en',
  23. template: data[:template],
  24. format: 'md',
  25. type: 'slack',
  26. )
  27. message_subject = NotificationFactory::Renderer.new(data[:objects], data[:locale], template[:subject], false).render
  28. message_body = NotificationFactory::Renderer.new(data[:objects], data[:locale], template[:body], false).render
  29. if !data[:raw]
  30. application_template = NotificationFactory.application_template_read(
  31. format: 'md',
  32. type: 'slack',
  33. )
  34. data[:objects][:message] = message_body
  35. data[:objects][:standalone] = data[:standalone]
  36. message_body = NotificationFactory::Renderer.new(data[:objects], data[:locale], application_template, false).render
  37. end
  38. {
  39. subject: message_subject.strip!,
  40. body: message_body.strip!,
  41. }
  42. end
  43. end