Using Slack Channel IDs vs Names in Notification Policies
Last updated: September 15, 2025
When setting up Slack notifications in Spacelift notification policies, you must use Slack channel IDs rather than human-readable channel names in the channel_id field.
Why Channel IDs Are Required
Slack's API expects the channel_id field to contain the actual Slack channel ID (for example, C0123456789), not the human-readable channel name (like my-team-alerts). When a channel name is provided instead of an ID, Slack cannot consistently resolve it, leading to intermittent "channel not found" errors.
Channel names are also mutable - they can change at any time, which would break your notification workflow. Channel IDs remain stable and provide reliable delivery.
Best Practice: Mapping Names to IDs
You can maintain human-readable stack labels while still using channel IDs in your policy. Here's the recommended approach:
Keep using readable channel names in your stack labels (e.g.,
slack:team-alerts)In your notification policy, maintain a mapping that converts these names to their corresponding Slack channel IDs
The policy automatically converts the label's name into the correct ID
This gives you the best of both worlds: clear, readable labels and stable, reliable Slack notifications.
Example Policy Structure
Here's how you might structure your policy to handle the name-to-ID conversion:
package spacelift
# Mapping of human-readable names to Slack channel IDs
channel_mapping := {
"team-alerts": "C0123456789",
"dev-notifications": "C9876543210",
"qa-updates": "C5555555555"
}
slack_channels[slack_channel_name] {
label := input.run_updated.stack.labels[_]
startswith(label, "slack:")
slack_channel_name := split(label, ":")[1]
}
slack[{"channel_id": channel_id}] {
run := input.run_updated.run
run.type == "TRACKED"
channel_name = slack_channels[_]
channel_id = channel_mapping[channel_name]
}
This approach ensures consistent notification delivery while keeping your stack labels human-readable and maintainable.