immosquare-slack 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f225c081bd5414be15eb18de6283012de0a0763266aa7ad69df66bb42a09104
|
4
|
+
data.tar.gz: 576e4573f9cd77b62ee364231f21e1ba38e00367d7f2bd4da567fa36b1ffb4f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 180c9241ecb12c5784a9d287087f37ef22fc58f1126e48107d51dcbeb92dc17efe769fdab3d1fae19f083d1c6e88bc26bab4712d09e3650543933eb14adf0714
|
7
|
+
data.tar.gz: 6b3cbd7e068f7d0cc3575c3403104c739e18a167d02549be2c11c2f0a9daa770a4df218671b3f0edb527237ee49d2faee46cfd7892536ad42257fd90269743a9
|
@@ -7,15 +7,27 @@ module ImmosquareSlack
|
|
7
7
|
## Pour récupérer la liste des channels
|
8
8
|
##============================================================##
|
9
9
|
def list_channels
|
10
|
-
|
10
|
+
@list_channels ||= begin
|
11
|
+
extra_params = {
|
12
|
+
:types => ["public_channel", "private_channel"].join(","),
|
13
|
+
:exclude_archived => false
|
14
|
+
}
|
15
|
+
fetch_paginated_data("https://slack.com/api/conversations.list", "channels", extra_params)
|
16
|
+
end
|
11
17
|
end
|
12
18
|
|
13
19
|
##============================================================##
|
14
20
|
## Pour poster un message dans un channel
|
15
21
|
##============================================================##
|
16
|
-
def post_message(channel_name, text, notify: nil, notify_text: nil, bot_name: nil)
|
22
|
+
def post_message(channel_name, text, notify: nil, notify_text: nil, bot_name: nil, notify_general_if_invalid_channel: true)
|
17
23
|
channel_id = get_channel_id_by_name(channel_name)
|
18
|
-
|
24
|
+
|
25
|
+
if channel_id.nil?
|
26
|
+
text = "immosquare-slack missing channel *#{channel_name}*\nmessage:\n#{text}"
|
27
|
+
return post_message("general", text, :notify => :channel, :notify_text => "", :bot_name => bot_name, :notify_general_if_invalid_channel => false) if channel_name != "general" && notify_general_if_invalid_channel
|
28
|
+
|
29
|
+
raise("channel '#{channel_name}' not found on slack")
|
30
|
+
end
|
19
31
|
|
20
32
|
url = "https://slack.com/api/chat.postMessage"
|
21
33
|
notification_text = notify ? build_notification_text(channel_id, notify, *notify_text) : nil
|
@@ -40,8 +52,8 @@ module ImmosquareSlack
|
|
40
52
|
##============================================================##
|
41
53
|
def get_channel_id_by_name(channel_name)
|
42
54
|
channels = list_channels
|
43
|
-
channel
|
44
|
-
channel ? channel["id"] : nil
|
55
|
+
channel = channels.find {|c| channel_name == "general" ? c["is_general"] == true : (c["name"] == channel_name && c["is_archived"] == false) }
|
56
|
+
channel.present? ? channel["id"] : nil
|
45
57
|
end
|
46
58
|
|
47
59
|
##============================================================##
|
@@ -13,12 +13,11 @@ module ImmosquareSlack
|
|
13
13
|
cursor = nil
|
14
14
|
|
15
15
|
loop do
|
16
|
-
query
|
16
|
+
query = cursor ? {:cursor => cursor}.merge(extra_query) : extra_query
|
17
17
|
response = make_slack_api_call(url, :query => query)
|
18
|
-
|
18
|
+
cursor = response.dig("response_metadata", "next_cursor")
|
19
19
|
|
20
20
|
items.concat(response[data_key])
|
21
|
-
cursor = response.dig("response_metadata", "next_cursor")
|
22
21
|
break if cursor.nil? || cursor.empty?
|
23
22
|
end
|
24
23
|
items
|
@@ -40,7 +39,7 @@ module ImmosquareSlack
|
|
40
39
|
##============================================================##
|
41
40
|
## On crée les options en fonction du cas de figure
|
42
41
|
##============================================================##
|
43
|
-
options[:query] = query
|
42
|
+
options[:query] = query if query.any?
|
44
43
|
options[:body] = body.to_json if body
|
45
44
|
|
46
45
|
##============================================================##
|
@@ -48,7 +47,7 @@ module ImmosquareSlack
|
|
48
47
|
##============================================================##
|
49
48
|
response = HTTParty.send(method, url, options)
|
50
49
|
parsed_response = JSON.parse(response.body)
|
51
|
-
raise(parsed_response.to_json)
|
50
|
+
raise(parsed_response.to_json) if !parsed_response["ok"]
|
52
51
|
|
53
52
|
parsed_response
|
54
53
|
rescue JSON::ParserError
|