Skip to content

Commit 2840fd6

Browse files
slack: add config option to disable thread reply broadcasting (#4464)
Adds DisableBroadcastThreadReplies configuration option to control whether Slack alert status updates in threads are broadcast to the main channel. When disabled (set to true), thread replies appear only in the thread. When enabled (default: false), thread replies broadcast to both the thread and main channel, preserving current behavior. Changes: - Add DisableBroadcastThreadReplies field to Slack config - Conditionally include slack.MsgOptionBroadcast() based on config - Auto-generate GraphQL mapping for new config option - Add smoke test for disabled broadcast behavior Co-authored-by: Aditya Hebballe <adityahebballe@changejar.in>
1 parent 61ef89c commit 2840fd6

5 files changed

Lines changed: 57 additions & 3 deletions

File tree

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ type Config struct {
100100

101101
SigningSecret string `password:"true" info:"Signing secret to verify requests from slack."`
102102
InteractiveMessages bool `info:"Enable interactive messages (e.g. buttons)."`
103+
DisableBroadcastThreadReplies bool `info:"Disable broadcasting alert status updates in threads to the main channel." public:"true"`
103104
}
104105

105106
Twilio struct {

graphql2/mapconfig.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

notification/slack/channel.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,17 @@ func (s *ChannelSender) SendMessage(ctx context.Context, msg notification.Messag
457457
channelID, ts = chanTS(channelID, t.OriginalStatus.ProviderMessageID.ExternalID)
458458

459459
// Reply in thread if we already sent a message for this alert.
460-
opts = append(opts,
460+
threadOpts := []slack.MsgOption{
461461
slack.MsgOptionTS(ts),
462-
slack.MsgOptionBroadcast(),
463462
slack.MsgOptionText(alertLink(ctx, t.AlertID, t.Summary), false),
464-
)
463+
}
464+
465+
// Conditionally add broadcast based on config (default: enabled)
466+
if !cfg.Slack.DisableBroadcastThreadReplies {
467+
threadOpts = append(threadOpts, slack.MsgOptionBroadcast())
468+
}
469+
470+
opts = append(opts, threadOpts...)
465471
break
466472
}
467473

test/smoke/slacknotification_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,41 @@ func TestSlackNotification(t *testing.T) {
4242
// should broadcast reply to channel
4343
msg.ExpectBroadcastReply("Alert #1")
4444
}
45+
46+
// TestSlackNotification_NoBroadcast tests that thread replies don't broadcast when disabled.
47+
func TestSlackNotification_NoBroadcast(t *testing.T) {
48+
t.Parallel()
49+
50+
sql := `
51+
insert into escalation_policies (id, name, repeat)
52+
values
53+
({{uuid "eid"}}, 'esc policy', 1);
54+
insert into escalation_policy_steps (id, escalation_policy_id, delay)
55+
values
56+
({{uuid "esid"}}, {{uuid "eid"}}, 30);
57+
58+
insert into notification_channels (id, type, name, value)
59+
values
60+
({{uuid "chan"}}, 'SLACK', '#test', {{slackChannelID "test"}});
61+
62+
insert into escalation_policy_actions (escalation_policy_step_id, channel_id)
63+
values
64+
({{uuid "esid"}}, {{uuid "chan"}});
65+
66+
insert into services (id, escalation_policy_id, name)
67+
values
68+
({{uuid "sid"}}, {{uuid "eid"}}, 'service');
69+
`
70+
h := harness.NewHarness(t, sql, "slack-user-link")
71+
defer h.Close()
72+
73+
// Disable broadcast
74+
h.SetConfigValue("Slack.DisableBroadcastThreadReplies", "true")
75+
76+
h.CreateAlert(h.UUID("sid"), "testing")
77+
msg := h.Slack().Channel("test").ExpectMessage("testing")
78+
79+
h.FastForward(time.Hour)
80+
// Should reply in thread WITHOUT broadcast
81+
msg.ExpectThreadReply("Alert #1")
82+
}

web/src/schema.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,7 @@ type ConfigID =
16571657
| 'Slack.AccessToken'
16581658
| 'Slack.SigningSecret'
16591659
| 'Slack.InteractiveMessages'
1660+
| 'Slack.DisableBroadcastThreadReplies'
16601661
| 'Twilio.Enable'
16611662
| 'Twilio.VoiceName'
16621663
| 'Twilio.VoiceLanguage'

0 commit comments

Comments
 (0)