Class: CodeBuildNotifier::SlackSender

Inherits:
Object
  • Object
show all
Defined in:
lib/codebuild-notifier/slack_sender.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ SlackSender

Returns a new instance of SlackSender.



25
26
27
# File 'lib/codebuild-notifier/slack_sender.rb', line 25

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



23
24
25
# File 'lib/codebuild-notifier/slack_sender.rb', line 23

def config
  @config
end

Instance Method Details

#find_alias(email) ⇒ Object



79
80
81
82
83
84
# File 'lib/codebuild-notifier/slack_sender.rb', line 79

def find_alias(email)
  config.slack_alias_table && config.dynamo_client.get_item(
    table_name: config.slack_alias_table,
    key: { 'alternate_email' => email }
  ).item&.fetch('workspace_email')
end

#send(message) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/codebuild-notifier/slack_sender.rb', line 29

def send(message)
  Slack.configure { |slack_config| slack_config.token = app_token }
  channel = message.additional_channel
  if channel
    channel = "##{channel}" unless /\A#/.match?(channel)
    post_message(message, channel)
  end

  user_ids = message.recipients.map { |email| find_slack_user(email)&.id }
  user_ids.uniq.compact.each { |user_id| post_message(message, user_id) }
end