Skip to content

Commit 99898f3

Browse files
fix: wire mention resolver into bot and webhook senders
Generated by Codex Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 2e93e2c commit 99898f3

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/main/groovy/nextflow/slack/BotSlackSender.groovy

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class BotSlackSender implements SlackSender {
5252

5353
private final String botToken
5454
private final String channelId
55+
private final SlackMentionResolver mentionResolver
5556
private final Set<String> loggedErrors = Collections.synchronizedSet(new HashSet<String>())
5657
private String threadTs // Store the thread timestamp for threaded conversations
5758
private String resolvedChannelId // Channel ID resolved from Slack API response
@@ -65,6 +66,7 @@ class BotSlackSender implements SlackSender {
6566
BotSlackSender(String botToken, String channelId) {
6667
this.botToken = botToken
6768
this.channelId = channelId
69+
this.mentionResolver = new SlackMentionResolver(botToken)
6870
}
6971

7072
/**
@@ -75,8 +77,8 @@ class BotSlackSender implements SlackSender {
7577
@Override
7678
void sendMessage(String message) {
7779
try {
78-
// Message is already formatted by SlackMessageBuilder with channel ID
79-
postToSlack(message)
80+
def resolvedMessage = mentionResolver.resolveInJson(message)
81+
postToSlack(resolvedMessage)
8082

8183
} catch (Exception e) {
8284
def errorMsg = "Slack plugin: Error sending bot message: ${e.message}".toString()
@@ -419,7 +421,8 @@ class BotSlackSender implements SlackSender {
419421
@Override
420422
void updateMessage(String message, String messageTs) {
421423
try {
422-
postUpdate(message, messageTs)
424+
def resolvedMessage = mentionResolver.resolveInJson(message)
425+
postUpdate(resolvedMessage, messageTs)
423426
} catch (Exception e) {
424427
def errorMsg = "Slack plugin: Error updating message: ${e.message}".toString()
425428
if (loggedErrors.add(errorMsg)) {

src/main/groovy/nextflow/slack/WebhookSlackSender.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class WebhookSlackSender implements SlackSender {
3535

3636
private final String webhookUrl
3737
private final Set<String> loggedErrors = Collections.synchronizedSet(new HashSet<String>())
38+
private final Set<String> loggedWarnings = Collections.synchronizedSet(new HashSet<String>())
3839

3940
/**
4041
* Create a new WebhookSlackSender with the given webhook URL
@@ -51,6 +52,8 @@ class WebhookSlackSender implements SlackSender {
5152
@Override
5253
void sendMessage(String message) {
5354
try {
55+
warnIfUnresolvedMentions(message)
56+
5457
def url = new URL(webhookUrl)
5558
def connection = url.openConnection() as HttpURLConnection
5659
connection.requestMethod = 'POST'
@@ -103,4 +106,14 @@ class WebhookSlackSender implements SlackSender {
103106
void uploadFile(Path filePath, Map options) {
104107
log.warn "Slack plugin: File upload is not supported with webhooks. Please configure a bot token to upload files."
105108
}
109+
110+
private void warnIfUnresolvedMentions(String message) {
111+
if (!SlackMentionResolver.hasResolvableMentions(message)) {
112+
return
113+
}
114+
def warning = 'Slack plugin: Display-name @mentions require a bot token (users:read scope) and are not resolved with webhooks'
115+
if (loggedWarnings.add(warning)) {
116+
log.warn warning
117+
}
118+
}
106119
}

0 commit comments

Comments
 (0)