2018-08-10 02:45:01 -04:00
# frozen_string_literal: true
2016-12-20 16:14:33 -05:00
class SlackService < ChatNotificationService
2014-03-18 13:27:03 -04:00
def title
2016-11-25 14:36:37 -05:00
'Slack notifications'
2014-03-18 13:27:03 -04:00
end
def description
2016-11-25 14:36:37 -05:00
'Receive event notifications in Slack'
2014-03-18 13:27:03 -04:00
end
2016-12-27 07:44:24 -05:00
def self . to_param
2016-12-20 16:14:33 -05:00
'slack'
2014-03-18 13:27:03 -04:00
end
2015-09-15 14:46:11 -04:00
def help
2016-11-25 14:36:37 -05:00
' This service sends notifications about projects events to Slack channels . < br / >
2017-02-10 10:26:28 -05:00
To set up this service :
2016-11-25 14:36:37 -05:00
< ol >
2017-02-10 10:26:28 -05:00
< li > < a href = " https://slack.com/apps/A0F7XDUAZ-incoming-webhooks " > Add an incoming webhook < / a> in your Slack team. The default channel can be overridden for each event.< / li >
< li > Paste the < strong > Webhook URL < / strong> into the field below.< / li >
< li > Select events below to enable notifications . The < strong > Channel name < / strong> and <strong>Username< /s trong > fields are optional . < / li>
2016-11-25 14:36:37 -05:00
< / ol>'
2015-09-15 14:46:11 -04:00
end
2016-12-22 13:12:35 -05:00
def default_channel_placeholder
2017-02-10 10:26:28 -05:00
" Channel name (e.g. general) "
2016-07-29 12:59:54 -04:00
end
2017-03-22 15:54:17 -04:00
def webhook_placeholder
'https://hooks.slack.com/services/…'
end
2019-09-27 07:35:37 -04:00
module Notifier
private
def notify ( message , opts )
# See https://github.com/stevenosloan/slack-notifier#custom-http-client
notifier = Slack :: Notifier . new ( webhook , opts . merge ( http_client : HTTPClient ) )
notifier . ping (
message . pretext ,
attachments : message . attachments ,
fallback : message . fallback
)
end
class HTTPClient
def self . post ( uri , params = { } )
params . delete ( :http_options ) # these are internal to the client and we do not want them
Gitlab :: HTTP . post ( uri , body : params )
end
end
end
include Notifier
2014-03-18 13:27:03 -04:00
end