2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2016-04-15 21:56:10 +00:00
|
|
|
class NotificationFactory::Slack
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
result = NotificationFactory::Slack.template(
|
|
|
|
template: 'ticket_update',
|
|
|
|
locale: 'en-us',
|
2019-02-10 11:01:38 +00:00
|
|
|
timezone: 'Europe/Berlin',
|
2016-04-15 21:56:10 +00:00
|
|
|
objects: {
|
|
|
|
recipient: User.find(2),
|
|
|
|
ticket: Ticket.find(1)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
{
|
|
|
|
subject: 'some subject',
|
|
|
|
body: 'some body',
|
|
|
|
}
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.template(data)
|
|
|
|
|
|
|
|
if data[:templateInline]
|
2019-02-10 11:01:38 +00:00
|
|
|
return NotificationFactory::Renderer.new(
|
|
|
|
objects: data[:objects],
|
|
|
|
locale: data[:locale],
|
|
|
|
timezone: data[:timezone],
|
|
|
|
template: data[:templateInline]
|
|
|
|
).render
|
2016-04-15 21:56:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
template = NotificationFactory.template_read(
|
2020-01-27 09:28:17 +00:00
|
|
|
locale: data[:locale] || Locale.default,
|
2016-04-15 21:56:10 +00:00
|
|
|
template: data[:template],
|
2018-12-19 17:31:51 +00:00
|
|
|
format: 'md',
|
|
|
|
type: 'slack',
|
2016-04-15 21:56:10 +00:00
|
|
|
)
|
|
|
|
|
2019-02-10 11:01:38 +00:00
|
|
|
message_subject = NotificationFactory::Renderer.new(
|
|
|
|
objects: data[:objects],
|
|
|
|
locale: data[:locale],
|
|
|
|
timezone: data[:timezone],
|
|
|
|
template: template[:subject],
|
2021-09-23 10:04:18 +00:00
|
|
|
escape: false,
|
|
|
|
trusted: true
|
2019-02-10 11:01:38 +00:00
|
|
|
).render
|
|
|
|
message_body = NotificationFactory::Renderer.new(
|
|
|
|
objects: data[:objects],
|
|
|
|
locale: data[:locale],
|
|
|
|
timezone: data[:timezone],
|
|
|
|
template: template[:body],
|
2021-09-23 10:04:18 +00:00
|
|
|
escape: false,
|
|
|
|
trusted: true
|
2019-02-10 11:01:38 +00:00
|
|
|
).render
|
2016-04-15 21:56:10 +00:00
|
|
|
|
|
|
|
if !data[:raw]
|
|
|
|
application_template = NotificationFactory.application_template_read(
|
|
|
|
format: 'md',
|
2018-12-19 17:31:51 +00:00
|
|
|
type: 'slack',
|
2016-04-15 21:56:10 +00:00
|
|
|
)
|
|
|
|
data[:objects][:message] = message_body
|
|
|
|
data[:objects][:standalone] = data[:standalone]
|
2019-02-10 11:01:38 +00:00
|
|
|
message_body = NotificationFactory::Renderer.new(
|
|
|
|
objects: data[:objects],
|
|
|
|
locale: data[:locale],
|
|
|
|
timezone: data[:timezone],
|
|
|
|
template: application_template,
|
2021-09-23 10:04:18 +00:00
|
|
|
escape: false,
|
|
|
|
trusted: true
|
2019-02-10 11:01:38 +00:00
|
|
|
).render
|
2016-04-15 21:56:10 +00:00
|
|
|
end
|
|
|
|
{
|
|
|
|
subject: message_subject.strip!,
|
2018-12-19 17:31:51 +00:00
|
|
|
body: message_body.strip!,
|
2016-04-15 21:56:10 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|