Skip to content

Commit 6ade1f6

Browse files
authored
fix: slack webhook (#3672)
1 parent f486e7d commit 6ade1f6

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

pnpm-lock.yaml

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

services/archetypes/worker/src/activities/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ async function telemetryIncrement(
2020
telemetry.increment(name, value, tags)
2121
}
2222

23-
async function slackNotify(message: string, persona: SlackPersona) {
24-
await sendSlackNotificationAsync(SlackChannel.ALERTS, persona, 'Temporal Alert', message)
23+
async function slackNotify(message: string, persona: SlackPersona | string) {
24+
// Accept string to allow workflow code to pass string literals without importing enum
25+
await sendSlackNotificationAsync(
26+
SlackChannel.ALERTS,
27+
persona as SlackPersona,
28+
'Temporal Alert',
29+
message,
30+
)
2531
log.info('Slack notification sent from Temporal activity')
2632
}
2733

services/archetypes/worker/src/interceptors.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import {
88
workflowInfo,
99
} from '@temporalio/workflow'
1010

11-
import { SlackPersona } from '@crowd/slack'
12-
1311
import * as activities from './activities'
1412

13+
// Use string literal instead of enum to avoid bundling @slack/webhook in workflow code
14+
// The activity will handle the type conversion
15+
const SLACK_PERSONA_ERROR_REPORTER = 'ERROR_REPORTER' as const
16+
1517
const activity = proxyActivities<typeof activities>({
1618
startToCloseTimeout: '10 seconds',
1719
})
@@ -72,12 +74,12 @@ export class WorkflowMonitoringInterceptor implements WorkflowInboundCallsInterc
7274
const errorDetails = getActivityRetryLimitDetails(err)
7375
const message = `*Workflow Failed: Activity Retry Limit Reached*\n\n*Workflow:* \`${info.workflowType}\`\n*Workflow ID:* \`${info.workflowId}\`\n*Run ID:* \`${info.runId}\`\n\n${errorDetails}`
7476

75-
await activity.slackNotify(message, SlackPersona.ERROR_REPORTER)
77+
await activity.slackNotify(message, SLACK_PERSONA_ERROR_REPORTER)
7678
} else {
7779
// For other errors, send a simpler notification
7880
const message = `*Workflow Failed*\n\n*Workflow:* \`${info.workflowType}\`\n*Workflow ID:* \`${info.workflowId}\`\n*Run ID:* \`${info.runId}\`\n*Error:* ${err.message}`
7981

80-
await activity.slackNotify(message, SlackPersona.ERROR_REPORTER)
82+
await activity.slackNotify(message, SLACK_PERSONA_ERROR_REPORTER)
8183
}
8284
}
8385

services/libs/slack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
"dependencies": {
1515
"@crowd/common": "workspace:*",
1616
"@crowd/logging": "workspace:*",
17-
"@slack/webhook": "^7.0.2"
17+
"@slack/webhook": "^6.1.0"
1818
}
1919
}

0 commit comments

Comments
 (0)