Module: SearchOnSlack

Included in:
EnergonNotify, MessageSlack
Defined in:
lib/modules/search_slack.rb

Overview

Module for searching content on Slack

Instance Method Summary collapse

Instance Method Details

#conversation_info(channel = @channel_id) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/modules/search_slack.rb', line 52

def conversation_info(channel = @channel_id)
  info = @web_client.conversations_info channel: channel
  @properties = info.channel
rescue Slack::Web::Api::Errors::SlackError => e
  print e.message
  false
end

#conversation_listObject



60
61
62
63
64
65
# File 'lib/modules/search_slack.rb', line 60

def conversation_list
  @web_client.conversations_list.channels
rescue Slack::Web::Api::Errors::SlackError => e
  print e.message
  false
end

#conversation_type(channel = @channel_id) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/modules/search_slack.rb', line 37

def conversation_type(channel = @channel_id)
  @channel_id = channel if @channel_id.nil?
  result = conversation_info
  if result == false
    print 'Check if IM'
    @channel_id = get_user_id
    conversation_info == false ? false : verify_type
  else
    verify_type
  end
rescue Slack::Web::Api::Errors::SlackError => e
  print e.message
  false
end

#get_user_id(channel = @channel_id) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/modules/search_slack.rb', line 3

def get_user_id(channel = @channel_id)
  dm = @web_client.conversations_open users: channel
  dm.channel.id
rescue Slack::Web::Api::Errors::SlackError => e
  print e.message
  false
end

#get_user_info(user) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/modules/search_slack.rb', line 11

def (user)
  c = @web_client.users_info user: user
  c.user
rescue Slack::Web::Api::Errors::SlackError => e
  print e.message
  false
end

#get_user_listObject



19
20
21
22
23
24
# File 'lib/modules/search_slack.rb', line 19

def get_user_list
  @web_client.users_list
rescue Slack::Web::Api::Errors::SlackError => e
  print e.message
  false
end

#search_messages_on(channel, quantity = 5) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/modules/search_slack.rb', line 67

def search_messages_on(channel, quantity = 5)
# type = conversation_type(channel)
@web_client.conversations_history channel: channel, count: quantity
  rescue Slack::Web::Api::Errors::SlackError => e
print e.message
"Channel not found #{channel}"
end

#verify_typeObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/modules/search_slack.rb', line 26

def verify_type
  properties = {
    'channel' => @properties.is_channel,
    'group' => @properties.is_group,
    'im' => @properties.is_im
  }
  check = ''
  properties.each { |k, v| check = k if v == true }
  check
end