class PeopleGroup::Connectors::Slack
Public Class Methods
new()
click to toggle source
# File lib/peoplegroup/connectors/slack.rb, line 8 def initialize ::Slack.configure do |config| config.token = ENV['SLACK_API_TOKEN'] end @client = ::Slack::Web::Client.new end
Public Instance Methods
bamboo_email_lookup_with_fallback(email)
click to toggle source
# File lib/peoplegroup/connectors/slack.rb, line 21 def bamboo_email_lookup_with_fallback(email) file_path = File.join(__dir__, '../../../data/email_mapper.yml') email_mapper = YAML.load_file(file_path) email_hit = email_mapper.find { |mapping| mapping['bamboo_email'] == email.delete_suffix('@gitlab.com') } email = "#{email_hit['slack_email']}@gitlab.com" if email_hit @client.users_lookupByEmail(email: email) rescue ::Slack::Web::Api::Errors::SlackError nil end
find_user(email)
click to toggle source
# File lib/peoplegroup/connectors/slack.rb, line 15 def find_user(email) @client.users_lookupByEmail(email: email) rescue ::Slack::Web::Api::Errors::SlackError nil end
find_user_by_id(id)
click to toggle source
# File lib/peoplegroup/connectors/slack.rb, line 32 def find_user_by_id(id) @client.users_info(user: id) rescue ::Slack::Web::Api::Errors::SlackError nil end
find_user_profile(id:, include_labels: false)
click to toggle source
# File lib/peoplegroup/connectors/slack.rb, line 38 def find_user_profile(id:, include_labels: false) @client.users_profile_get(user: id, include_labels: include_labels) rescue ::Slack::Web::Api::Errors::SlackError nil end
get_message(channel:, timestamp:)
click to toggle source
# File lib/peoplegroup/connectors/slack.rb, line 69 def get_message(channel:, timestamp:) @client.conversations_history(channel: channel, latest: timestamp, limit: 1, inclusive: true)&.messages&.first end
link_for_message(channel:, timestamp:)
click to toggle source
# File lib/peoplegroup/connectors/slack.rb, line 49 def link_for_message(channel:, timestamp:) @client.chat_getPermalink(channel: channel, message_ts: timestamp) end
list_public_channels()
click to toggle source
# File lib/peoplegroup/connectors/slack.rb, line 44 def list_public_channels channels = @client.channels_list(exclude_archived: true).channels channels.reject(&:is_private)&.map(:name) end
publish_view(user_id:, trigger:, view:)
click to toggle source
# File lib/peoplegroup/connectors/slack.rb, line 65 def publish_view(user_id:, trigger:, view:) @client.views_publish(user_id: user_id, trigger_id: trigger, view: view) end
send_message(channel:, text: '', as_user: true, attachments: [], thread_ts: nil, reply_broadcast: false, formatted_message: [])
click to toggle source
# File lib/peoplegroup/connectors/slack.rb, line 53 def send_message(channel:, text: '', as_user: true, attachments: [], thread_ts: nil, reply_broadcast: false, formatted_message: []) @client.chat_postMessage(channel: channel, text: text, as_user: true, attachments: attachments, unfurl_links: false, thread_ts: thread_ts, reply_broadcast: reply_broadcast, blocks: formatted_message) end
send_modal_message(trigger:, view:)
click to toggle source
# File lib/peoplegroup/connectors/slack.rb, line 61 def send_modal_message(trigger:, view:) @client.views_open(trigger_id: trigger, view: view) end
update_message(channel:, timestamp:, text: '', attachments: [], formatted_message: [])
click to toggle source
# File lib/peoplegroup/connectors/slack.rb, line 57 def update_message(channel:, timestamp:, text: '', attachments: [], formatted_message: []) @client.chat_update(channel: channel, text: text, ts: timestamp, as_user: true, attachments: attachments, blocks: formatted_message) end