Module: SlackSearch

Includes:
SlackClient
Included in:
EnerbotSlack, SlackConsole, SlackMessage
Defined in:
lib/modules/slack_search.rb

Overview

Module for searching content on Slack

Instance Method Summary collapse

Methods included from SlackClient

#configure_client

Instance Method Details

#conversation_info(channel = @channel_id) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/modules/slack_search.rb', line 61

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

#conversation_listObject



79
80
81
82
83
84
85
# File 'lib/modules/slack_search.rb', line 79

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

#conversation_members(channel, limit = 60) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/modules/slack_search.rb', line 70

def conversation_members(channel, limit = 60)
  client = configure_client
  info = client.conversations_members channel: channel, limit: limit
  info.members
rescue Slack::Web::Api::Errors::SlackError => e
  print e.message
  false
end

#conversation_type(channel = @channel_id) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/modules/slack_search.rb', line 46

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



9
10
11
12
13
14
15
16
# File 'lib/modules/slack_search.rb', line 9

def get_user_id(channel = @channel_id)
  client = configure_client
  dm = 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



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

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

#get_user_listObject



27
28
29
30
31
32
33
# File 'lib/modules/slack_search.rb', line 27

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

#search_messages_on(channel, quantity = 5) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/modules/slack_search.rb', line 87

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

#verify_typeObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/modules/slack_search.rb', line 35

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