collavre_slack 0.2.9 → 0.2.11
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 +4 -4
- data/app/javascript/collavre_slack.js +6 -23
- data/app/jobs/collavre_slack/slack_inbound_message_job.rb +2 -2
- data/app/services/collavre_slack/slack_bot_message.rb +42 -0
- data/app/services/collavre_slack/slack_client.rb +4 -0
- data/app/services/collavre_slack/slack_event_handler.rb +29 -18
- data/lib/collavre_slack/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9f7029a532471760a97235402e179cd60bcc7d5f0324187f63f4eced0cbcb040
|
|
4
|
+
data.tar.gz: 057a384f973872bf15b52091585ca3e165f313b39c4a59f4e6b2eba06951ba65
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: af3c5a1434cac3403c33512dfbeac1595c376359f15f74533d62e4c4f3f4746ebfc2caf498ef0b487bae209f2a8b13c544c53095bba8e9b20095b07a212cd76b
|
|
7
|
+
data.tar.gz: 7f3743d14d9b15b3c20eea38add13a97413aeb83ef59e8038593f650a1ba63e88190ec910c30d0dcae2c6701a4df4eddcb6ddf7b2614228265c6fe0446efcdb9
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { filterChannels, reconcileSelection, buildChannelViewModels } from './slack_channel_list.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { showError, clearError, updateStepVisibility, openOAuthPopup, fetchWithCsrf, setupModalClose, requireCreativeId, resetConnectView, showSuccessAndClose } from 'collavre/modules/integration_wizard';
|
|
3
|
+
import { confirmDialog } from 'collavre/lib/utils/dialog';
|
|
4
4
|
|
|
5
5
|
let slackIntegrationInitialized = false;
|
|
6
6
|
|
|
@@ -48,19 +48,10 @@ if (!slackIntegrationInitialized) {
|
|
|
48
48
|
if (connectedStatus) {
|
|
49
49
|
connectedStatus.style.display = 'none';
|
|
50
50
|
}
|
|
51
|
-
if (existingContainer) {
|
|
52
|
-
existingContainer.style.display = 'none';
|
|
53
|
-
}
|
|
54
|
-
if (existingList) {
|
|
55
|
-
existingList.innerHTML = '';
|
|
56
|
-
}
|
|
57
51
|
if (addChannelSection) {
|
|
58
52
|
addChannelSection.style.display = 'none';
|
|
59
53
|
}
|
|
60
|
-
|
|
61
|
-
connectMessage.style.display = '';
|
|
62
|
-
}
|
|
63
|
-
if (loginBtn) loginBtn.style.display = 'inline-block';
|
|
54
|
+
resetConnectView({ existingContainer, existingList, connectMessage, loginBtn });
|
|
64
55
|
if (channelListEl) channelListEl.innerHTML = '';
|
|
65
56
|
updateStep();
|
|
66
57
|
}
|
|
@@ -310,12 +301,7 @@ if (!slackIntegrationInitialized) {
|
|
|
310
301
|
.then(response => response.json())
|
|
311
302
|
.then(data => {
|
|
312
303
|
if (data.success) {
|
|
313
|
-
statusEl
|
|
314
|
-
statusEl.style.color = 'green';
|
|
315
|
-
setTimeout(() => {
|
|
316
|
-
modal.style.display = 'none';
|
|
317
|
-
resetWizard();
|
|
318
|
-
}, 2000);
|
|
304
|
+
showSuccessAndClose(modal, statusEl, modal.dataset.successMessage || 'Channel linked successfully', resetWizard);
|
|
319
305
|
} else {
|
|
320
306
|
showError(errorEl, data.message || data.error || 'Failed to link channel');
|
|
321
307
|
}
|
|
@@ -332,11 +318,8 @@ if (!slackIntegrationInitialized) {
|
|
|
332
318
|
|
|
333
319
|
// Event listeners
|
|
334
320
|
openBtn.addEventListener('click', function () {
|
|
335
|
-
creativeId = this
|
|
336
|
-
if (!creativeId)
|
|
337
|
-
alertDialog(modal.dataset.noCreative);
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
321
|
+
creativeId = requireCreativeId(this, modal);
|
|
322
|
+
if (!creativeId) return;
|
|
340
323
|
modal.style.display = 'flex';
|
|
341
324
|
resetWizard();
|
|
342
325
|
loadIntegrationStatus();
|
|
@@ -4,7 +4,7 @@ module CollavreSlack
|
|
|
4
4
|
|
|
5
5
|
# Slack is acked (200) the instant this job is enqueued, so a lost job means a
|
|
6
6
|
# lost message. We can't use a job-level `retry_on`: re-running `perform` would
|
|
7
|
-
# re-run CommandProcessor's non-idempotent commands (/calendar,
|
|
7
|
+
# re-run CommandProcessor's non-idempotent commands (/calendar, MCP). So
|
|
8
8
|
# CommandProcessor runs exactly once and each DB write around it is retried in
|
|
9
9
|
# place via #with_transient_retry.
|
|
10
10
|
|
|
@@ -50,7 +50,7 @@ module CollavreSlack
|
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
# Exactly-once guard, claimed here: after the idempotent writes above, immediately
|
|
53
|
-
# before the non-idempotent CommandProcessor (/calendar,
|
|
53
|
+
# before the non-idempotent CommandProcessor (/calendar, MCP). Slack is acked
|
|
54
54
|
# before this job runs, so a message can arrive twice (sequentially or concurrently);
|
|
55
55
|
# a read-only "already applied?" check can't cover concurrency — both jobs read "not
|
|
56
56
|
# applied" and both run the commands. We atomically claim (channel_link, message_ts)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require "digest"
|
|
2
|
+
|
|
3
|
+
module CollavreSlack
|
|
4
|
+
class SlackBotMessage
|
|
5
|
+
def initialize(account:, message:)
|
|
6
|
+
@account = account
|
|
7
|
+
@message = message
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def bot?
|
|
11
|
+
@message[:bot_id].present? || @message[:subtype] == "bot_message"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def own?
|
|
15
|
+
return false unless bot?
|
|
16
|
+
|
|
17
|
+
identity = bot_identity
|
|
18
|
+
@message[:bot_id] == identity[:bot_id] ||
|
|
19
|
+
(@message[:user].present? && @message[:user] == identity[:user_id])
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def sender
|
|
23
|
+
# Bots must not be auto-mapped to a person by email or queried with a nil user ID.
|
|
24
|
+
name = @message[:username].presence || @message.dig(:bot_profile, :name).presence || @message[:bot_id]
|
|
25
|
+
{ user: nil, slack_display_name: name, slack_email: nil, slack_user_id: @message[:user] }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def bot_identity
|
|
31
|
+
token_digest = Digest::SHA256.hexdigest(@account.access_token)
|
|
32
|
+
Rails.cache.fetch([ "slack_bot_identity", @account.id, token_digest ], expires_in: 1.hour) do
|
|
33
|
+
response = SlackClient.new(access_token: @account.access_token).auth_test
|
|
34
|
+
# Raise before the webhook is acknowledged so Slack can retry; never cache failures.
|
|
35
|
+
unless response[:ok] && response[:bot_id].present? && response[:user_id].present?
|
|
36
|
+
raise "Unable to resolve Slack bot identity"
|
|
37
|
+
end
|
|
38
|
+
response.slice(:bot_id, :user_id)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -13,25 +13,17 @@ module CollavreSlack
|
|
|
13
13
|
slack_account = SlackAccount.find_by(team_id: team_id)
|
|
14
14
|
return unless slack_account
|
|
15
15
|
|
|
16
|
-
channel_link =
|
|
17
|
-
slack_account: slack_account,
|
|
18
|
-
channel_id: channel_id
|
|
19
|
-
)
|
|
16
|
+
channel_link = linked_channel(slack_account)
|
|
20
17
|
return unless channel_link
|
|
21
18
|
|
|
22
|
-
user_result =
|
|
19
|
+
user_result = message_sender(slack_account)
|
|
20
|
+
return unless user_result
|
|
23
21
|
user = user_result[:user] || channel_link.created_by
|
|
24
22
|
slack_display_name = user_result[:slack_display_name]
|
|
25
23
|
slack_email = user_result[:slack_email]
|
|
26
24
|
slack_user_id = user_result[:slack_user_id]
|
|
27
25
|
|
|
28
|
-
normalized_content =
|
|
29
|
-
|
|
30
|
-
# Prepend Slack username if user is not mapped
|
|
31
|
-
if user_result[:user].nil? && slack_display_name.present?
|
|
32
|
-
prefix = I18n.t("collavre_slack.messages.slack_user_prefix", name: slack_display_name)
|
|
33
|
-
normalized_content = "#{prefix} #{normalized_content}"
|
|
34
|
-
end
|
|
26
|
+
normalized_content = normalize_content(formatted_content, slack_account, user_result)
|
|
35
27
|
|
|
36
28
|
{
|
|
37
29
|
type: :message,
|
|
@@ -55,8 +47,9 @@ module CollavreSlack
|
|
|
55
47
|
message_ts = message[:ts]
|
|
56
48
|
return unless message_ts
|
|
57
49
|
|
|
58
|
-
#
|
|
59
|
-
|
|
50
|
+
# Ignore our own edits to prevent synchronization loops.
|
|
51
|
+
bot_message = SlackBotMessage.new(account: slack_account, message: message)
|
|
52
|
+
return if bot_message.own?
|
|
60
53
|
|
|
61
54
|
# Find the comment link by Slack message
|
|
62
55
|
comment_link = SlackCommentLink.find_by_slack_message(
|
|
@@ -67,7 +60,8 @@ module CollavreSlack
|
|
|
67
60
|
return unless comment_link
|
|
68
61
|
|
|
69
62
|
new_text = message[:text].to_s
|
|
70
|
-
|
|
63
|
+
sender = bot_message.sender if bot_message.bot?
|
|
64
|
+
normalized_content = normalize_content(new_text, slack_account, sender)
|
|
71
65
|
|
|
72
66
|
{
|
|
73
67
|
type: :message_updated,
|
|
@@ -135,12 +129,29 @@ module CollavreSlack
|
|
|
135
129
|
|
|
136
130
|
attr_reader :payload
|
|
137
131
|
|
|
132
|
+
def linked_channel(slack_account)
|
|
133
|
+
SlackChannelLink.find_by(slack_account: slack_account, channel_id: channel_id)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def normalize_content(text, slack_account, sender)
|
|
137
|
+
content = MentionMapping.from_slack(text, slack_account)
|
|
138
|
+
return content unless sender && sender[:user].nil? && sender[:slack_display_name].present?
|
|
139
|
+
|
|
140
|
+
prefix = I18n.t("collavre_slack.messages.slack_user_prefix", name: sender[:slack_display_name])
|
|
141
|
+
"#{prefix} #{content}"
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def message_sender(slack_account)
|
|
145
|
+
bot_message = SlackBotMessage.new(account: slack_account, message: event_payload)
|
|
146
|
+
return if bot_message.own?
|
|
147
|
+
|
|
148
|
+
bot_message.bot? ? bot_message.sender : find_or_map_user(slack_account, event_user_id)
|
|
149
|
+
end
|
|
150
|
+
|
|
138
151
|
def message_event?
|
|
139
152
|
return false unless event_type == "event_callback"
|
|
140
153
|
return false unless event_payload[:type] == "message"
|
|
141
|
-
return false if event_payload[:subtype].present?
|
|
142
|
-
# Skip bot messages to prevent loops
|
|
143
|
-
return false if event_payload[:bot_id].present?
|
|
154
|
+
return false if event_payload[:subtype].present? && event_payload[:subtype] != "bot_message"
|
|
144
155
|
true
|
|
145
156
|
end
|
|
146
157
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: collavre_slack
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Collavre
|
|
@@ -106,6 +106,7 @@ files:
|
|
|
106
106
|
- app/models/concerns/collavre_slack/slack_reaction_dispatchable.rb
|
|
107
107
|
- app/services/collavre_slack/emoji_mapping.rb
|
|
108
108
|
- app/services/collavre_slack/mention_mapping.rb
|
|
109
|
+
- app/services/collavre_slack/slack_bot_message.rb
|
|
109
110
|
- app/services/collavre_slack/slack_client.rb
|
|
110
111
|
- app/services/collavre_slack/slack_event_handler.rb
|
|
111
112
|
- app/services/collavre_slack/slack_integration_service.rb
|
|
@@ -151,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
151
152
|
- !ruby/object:Gem::Version
|
|
152
153
|
version: '0'
|
|
153
154
|
requirements: []
|
|
154
|
-
rubygems_version: 3.6.
|
|
155
|
+
rubygems_version: 3.6.9
|
|
155
156
|
specification_version: 4
|
|
156
157
|
summary: Slack integration for Collavre
|
|
157
158
|
test_files: []
|