Module: MessageSlack
Overview
Module for message interactions on Slack
Instance Method Summary
collapse
-
#add_reaction(icon, channel, thread) ⇒ Object
-
#attach_format(data, title, color = '#e93d94') ⇒ Object
-
#discern_end(data, ts = nil) ⇒ Object
-
#send_attachment(attachment, data, ts = nil) ⇒ Object
-
#send_direct_message(text, channel) ⇒ Object
-
#send_file(path, data, ts = nil) ⇒ Object
-
#send_message(text, data, ts = nil) ⇒ Object
#conversation_info, #conversation_list, #conversation_type, #get_user_id, #get_user_info, #get_user_list, #search_messages_on, #verify_type
Instance Method Details
#add_reaction(icon, channel, thread) ⇒ Object
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/modules/message_slack.rb', line 76
def add_reaction(icon, channel, thread)
@web_client.reactions_add channel: channel,
name: icon,
timestamp: thread,
icon_url: @bot_icon,
username: @bot_name
rescue Slack::Web::Api::Errors::SlackError => e
print e.message
false
end
|
22
23
24
25
26
27
28
29
30
|
# File 'lib/modules/message_slack.rb', line 22
def attach_format(data, title, color = '#e93d94')
text = ''
data.each { |v| text << "#{v}\n" }
[{
"pretext": title,
"color": color,
"text": text
}]
end
|
#discern_end(data, ts = nil) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/modules/message_slack.rb', line 9
def discern_end(data, ts = nil)
@thread = if data.respond_to? :thread_ts
data.ts
else
ts unless ts.nil?
end
@channel = if data.respond_to? :channel
data.channel
else
data
end
end
|
#send_attachment(attachment, data, ts = nil) ⇒ Object
50
51
52
53
54
55
56
57
58
|
# File 'lib/modules/message_slack.rb', line 50
def send_attachment(attachment, data, ts = nil)
discern_end(data, ts)
@web_client.chat_postMessage channel: @channel,
attachments: attachment,
icon_url: @bot_icon,
username: @bot_name,
thread_ts: @thread,
as_user: @bot_user
end
|
#send_direct_message(text, channel) ⇒ Object
45
46
47
48
|
# File 'lib/modules/message_slack.rb', line 45
def send_direct_message(text, channel)
dm = get_user_id(channel)
dm == false ? false : send_message(text, dm)
end
|
#send_file(path, data, ts = nil) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/modules/message_slack.rb', line 60
def send_file(path, data, ts = nil)
file = path
discern_end(data, ts)
@web_client.files_upload channels: @channel,
icon_url: @bot_icon,
username: @bot_name,
thread_ts: @thread,
as_user: @bot_user,
file: Faraday::UploadIO.new(file, 'text'),
title: File.basename(file),
filename: File.basename(file)
rescue Slack::Web::Api::Errors::SlackError => e
print e.message
false
end
|
#send_message(text, data, ts = nil) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/modules/message_slack.rb', line 32
def send_message(text, data, ts = nil)
discern_end(data, ts)
@web_client.chat_postMessage channel: @channel,
text: text,
icon_url: @bot_icon,
username: @bot_name,
thread_ts: @thread,
as_user: @bot_user
rescue Slack::Web::Api::Errors::SlackError => e
print e.message
false
end
|