Class: PeopleGroup::Connectors::Slack
- Inherits:
-
Object
- Object
- PeopleGroup::Connectors::Slack
- Defined in:
- lib/peoplegroup/connectors/slack.rb
Instance Method Summary collapse
- #bamboo_email_lookup(email) ⇒ Object (also: #bamboo_email_lookup_with_fallback, #find_user)
- #find_user_by_id(id) ⇒ Object
- #find_user_profile(id:, include_labels: false) ⇒ Object
- #get_message(channel:, timestamp:) ⇒ Object
-
#initialize ⇒ Slack
constructor
A new instance of Slack.
- #link_for_message(channel:, timestamp:) ⇒ Object
-
#list_public_channels ⇒ Object
www.rubydoc.info/gems/slack-ruby-client/0.17.0/Slack%2FWeb%2FApi%2FEndpoints%2FConversations:conversations_list Defaults to only show public channels.
- #publish_view(user_id:, view:, **options) ⇒ Object
- #send_message(channel:, text: '', as_user: true, attachments: [], thread_ts: nil, reply_broadcast: false, formatted_message: []) ⇒ Object
- #send_modal_message(trigger:, view:) ⇒ Object
- #update_message(channel:, timestamp:, text: '', attachments: [], formatted_message: []) ⇒ Object
Constructor Details
#initialize ⇒ Slack
Returns a new instance of Slack.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/peoplegroup/connectors/slack.rb', line 8 def initialize ::Slack::Web::Client.configure do |config| config.token = ENV['SLACK_API_TOKEN'] # configure certificate file # fixed in slack-ruby-client 2.x config.ca_file = ENV['SSL_CERT_FILE'] if ENV['SSL_CERT_FILE'] end @client = ::Slack::Web::Client.new end |
Instance Method Details
#bamboo_email_lookup(email) ⇒ Object Also known as: bamboo_email_lookup_with_fallback, find_user
19 20 21 22 23 |
# File 'lib/peoplegroup/connectors/slack.rb', line 19 def bamboo_email_lookup(email) @client.users_lookupByEmail(email: email) rescue ::Slack::Web::Api::Errors::SlackError nil end |
#find_user_by_id(id) ⇒ Object
27 28 29 30 31 |
# File 'lib/peoplegroup/connectors/slack.rb', line 27 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) ⇒ Object
33 34 35 36 37 |
# File 'lib/peoplegroup/connectors/slack.rb', line 33 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:) ⇒ Object
92 93 94 95 |
# File 'lib/peoplegroup/connectors/slack.rb', line 92 def (channel:, timestamp:) = { channel: channel, latest: , limit: 1, inclusive: true } @client.conversations_history()&.&.first end |
#link_for_message(channel:, timestamp:) ⇒ Object
47 48 49 |
# File 'lib/peoplegroup/connectors/slack.rb', line 47 def (channel:, timestamp:) @client.chat_getPermalink(channel: channel, message_ts: ) end |
#list_public_channels ⇒ Object
www.rubydoc.info/gems/slack-ruby-client/0.17.0/Slack%2FWeb%2FApi%2FEndpoints%2FConversations:conversations_list Defaults to only show public channels.
41 42 43 44 |
# File 'lib/peoplegroup/connectors/slack.rb', line 41 def list_public_channels response = @client.conversations_list(exclude_archived: true) response['channels'].map { |channel| channel['name'] } end |
#publish_view(user_id:, view:, **options) ⇒ Object
87 88 89 |
# File 'lib/peoplegroup/connectors/slack.rb', line 87 def publish_view(user_id:, view:, **) @client.views_publish(user_id: user_id, view: view, **) end |
#send_message(channel:, text: '', as_user: true, attachments: [], thread_ts: nil, reply_broadcast: false, formatted_message: []) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/peoplegroup/connectors/slack.rb', line 52 def (channel:, text: '', as_user: true, attachments: [], thread_ts: nil, reply_broadcast: false, formatted_message: []) = { channel: channel, text: text, as_user: as_user, attachments: , unfurl_links: false, thread_ts: thread_ts, reply_broadcast: reply_broadcast, blocks: } @client.chat_postMessage() end |
#send_modal_message(trigger:, view:) ⇒ Object
82 83 84 |
# File 'lib/peoplegroup/connectors/slack.rb', line 82 def (trigger:, view:) @client.views_open(trigger_id: trigger, view: view) end |
#update_message(channel:, timestamp:, text: '', attachments: [], formatted_message: []) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/peoplegroup/connectors/slack.rb', line 68 def (channel:, timestamp:, text: '', attachments: [], formatted_message: []) = { channel: channel, text: text, ts: , as_user: true, attachments: , blocks: } @client.chat_update() end |