immosquare-slack 0.1.4 → 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: 106e9053feb1cdfe92a719e3be1346a9c98c28ae19a8d79819e0cc620537649d
4
- data.tar.gz: 9aba643342384868d859d7112dc4ff71d3179e0d9d3a5e7bc029c212229f137a
3
+ metadata.gz: 8f225c081bd5414be15eb18de6283012de0a0763266aa7ad69df66bb42a09104
4
+ data.tar.gz: 576e4573f9cd77b62ee364231f21e1ba38e00367d7f2bd4da567fa36b1ffb4f2
5
5
  SHA512:
6
- metadata.gz: 28261195cc6fb873c5998edede356390ed49f8415b7eabacf66c4df812d75a51e601930d762bde87e0402eb7eeb6d68a521a1ba37e193d01b8957e2d39ae1628
7
- data.tar.gz: 9a4a2a88aaa7d367cc5688fd92b6895ef7f25c14002be4faa66e07d17956ac15e88f26b39ed356af600903cedd9f95e4b46e5b2aa846a9aaba9b28f05143799e
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 not found") 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.4".freeze
2
+ VERSION = "0.1.6".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immosquare-slack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
- - IMMO SQUARE
7
+ - immosquare
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-12 00:00:00.000000000 Z
11
+ date: 2024-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -41,7 +41,7 @@ files:
41
41
  - lib/immosquare-slack/shared_methods.rb
42
42
  - lib/immosquare-slack/user.rb
43
43
  - lib/immosquare-slack/version.rb
44
- homepage: https://github.com/IMMOSQUARE/immosquare-slack
44
+ homepage: https://github.com/immosquare/immosquare-slack
45
45
  licenses:
46
46
  - MIT
47
47
  metadata: {}
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  requirements: []
63
- rubygems_version: 3.4.13
63
+ rubygems_version: 3.5.22
64
64
  signing_key:
65
65
  specification_version: 4
66
66
  summary: A Ruby gem for integrating with Slack API to perform various actions like