2016-04-15 21:56:10 +00:00
|
|
|
class NotificationFactory::Slack
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
result = NotificationFactory::Slack.template(
|
|
|
|
template: 'ticket_update',
|
|
|
|
locale: 'en-us',
|
|
|
|
objects: {
|
|
|
|
recipient: User.find(2),
|
|
|
|
ticket: Ticket.find(1)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
{
|
|
|
|
subject: 'some subject',
|
|
|
|
body: 'some body',
|
|
|
|
}
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.template(data)
|
|
|
|
|
|
|
|
if data[:templateInline]
|
2016-11-11 15:57:25 +00:00
|
|
|
return NotificationFactory::Renderer.new(data[:objects], data[:locale], data[:templateInline]).render
|
2016-04-15 21:56:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
template = NotificationFactory.template_read(
|
2017-11-15 14:06:53 +00:00
|
|
|
locale: data[:locale] || Setting.get('locale_default') || 'en-us',
|
2016-04-15 21:56:10 +00:00
|
|
|
template: data[:template],
|
|
|
|
format: 'md',
|
|
|
|
type: 'slack',
|
|
|
|
)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
message_subject = NotificationFactory::Renderer.new(data[:objects], data[:locale], template[:subject], false).render
|
|
|
|
message_body = NotificationFactory::Renderer.new(data[:objects], data[:locale], template[:body], false).render
|
2016-04-15 21:56:10 +00:00
|
|
|
|
|
|
|
if !data[:raw]
|
|
|
|
application_template = NotificationFactory.application_template_read(
|
|
|
|
format: 'md',
|
|
|
|
type: 'slack',
|
|
|
|
)
|
|
|
|
data[:objects][:message] = message_body
|
|
|
|
data[:objects][:standalone] = data[:standalone]
|
2016-11-13 18:33:12 +00:00
|
|
|
message_body = NotificationFactory::Renderer.new(data[:objects], data[:locale], application_template, false).render
|
2016-04-15 21:56:10 +00:00
|
|
|
end
|
|
|
|
{
|
|
|
|
subject: message_subject.strip!,
|
|
|
|
body: message_body.strip!,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|