immosquare-slack 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4eec84f4f9ca3ea1bb5fdbe1f5534fcc1b78ac8d0ba359079615fbbca500ae0
4
- data.tar.gz: 20e5313fa30c0ec42c2cbed9d40b0a96d674986d324096a4e8b92f8aed7cb0f3
3
+ metadata.gz: 8f225c081bd5414be15eb18de6283012de0a0763266aa7ad69df66bb42a09104
4
+ data.tar.gz: 576e4573f9cd77b62ee364231f21e1ba38e00367d7f2bd4da567fa36b1ffb4f2
5
5
  SHA512:
6
- metadata.gz: 703bd12a7ec32728c1dee2e67361925931d15826c0e560546b8006e8f3cd54c1fbd776f3350c3c2c59acadccd2bf880f3279c78ebad0a77df860813b1a1ae5d9
7
- data.tar.gz: 380f30822739cc1147d845be7795ea6596d6e53deec54c6dc7f88c64a5ff000296b7fd4c6a83c8c1eeaa650fe62cf166a7d961ceb63217913e8153f56f8f7858
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
- fetch_paginated_data("https://slack.com/api/conversations.list", "channels")
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
- raise("Channel #{channel_name} not found on slack") if channel_id.nil?
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 = channels.find {|c| c["name"] == channel_name }
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
  ##============================================================##
@@ -1,7 +1,7 @@
1
1
  module ImmosquareSlack
2
2
  class Configuration
3
3
 
4
- attr_accessor :slack_api_token_bot, :openai_model
4
+ attr_accessor :slack_api_token_bot
5
5
 
6
6
  def initialize
7
7
  @slack_api_token_bot = nil
@@ -13,12 +13,11 @@ module ImmosquareSlack
13
13
  cursor = nil
14
14
 
15
15
  loop do
16
- query = cursor ? {:cursor => cursor}.merge(extra_query) : extra_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 if query.any?
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) unless parsed_response["ok"]
50
+ raise(parsed_response.to_json) if !parsed_response["ok"]
52
51
 
53
52
  parsed_response
54
53
  rescue JSON::ParserError
@@ -1,3 +1,3 @@
1
1
  module ImmosquareSlack
2
- VERSION = "0.1.5".freeze
2
+ VERSION = "0.1.6".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immosquare-slack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - immosquare