github.com/argoproj/argo-cd/v3@v3.2.1/docs/operator-manual/notifications/services/slack.md (about) 1 # Slack 2 3 If you want to send message using incoming webhook, you can use [webhook](./webhook.md#send-slack). 4 5 ## Parameters 6 7 The Slack notification service configuration includes following settings: 8 9 | **Option** | **Required** | **Type** | **Description** | **Example** | 10 | -------------------- | ------------ | -------------- | --------------- | ----------- | 11 | `apiURL` | False | `string` | The server URL. | `https://example.com/api` | 12 | `channels` | False | `list[string]` | | `["my-channel-1", "my-channel-2"]` | 13 | `icon` | False | `string` | The app icon. | `:robot_face:` or `https://example.com/image.png` | 14 | `insecureSkipVerify` | False | `bool` | | `true` | 15 | `signingSecret` | False | `string` | | `8f742231b10e8888abcd99yyyzzz85a5` | 16 | `token` | **True** | `string` | The app's OAuth access token. | `xoxb-1234567890-1234567890123-5n38u5ed63fgzqlvuyxvxcx6` | 17 | `username` | False | `string` | The app username. | `argocd` | 18 | `disableUnfurl` | False | `bool` | Disable slack unfurling links in messages | `true` | 19 20 ## Configuration 21 22 1. Create Slack Application using https://api.slack.com/apps?new_app=1 23  24 1. Once application is created navigate to `OAuth & Permissions` 25  26 1. Go to `Scopes` > `Bot Token Scopes` > `Add an OAuth Scope`. Add `chat:write` scope. To use the optional username and icon overrides in the Slack notification service also add the `chat:write.customize` scope. 27  28 1. `OAuth & Permission` > `OAuth Tokens for Your Workspace` > `Install to Workspace` 29  30 1. Once installation is completed copy the OAuth token. 31  32 33 1. Create a public or private channel, for this example `my_channel` 34 1. Invite your slack bot to this channel **otherwise slack bot won't be able to deliver notifications to this channel** 35 1. Store Oauth access token in `argocd-notifications-secret` secret 36 37 ```yaml 38 apiVersion: v1 39 kind: Secret 40 metadata: 41 name: <secret-name> 42 stringData: 43 slack-token: <Oauth-access-token> 44 ``` 45 46 1. Define service type slack in data section of `argocd-notifications-cm` configmap: 47 48 ```yaml 49 apiVersion: v1 50 kind: ConfigMap 51 metadata: 52 name: argocd-notifications-cm 53 data: 54 service.slack: | 55 token: $slack-token 56 ``` 57 58 1. Add annotation in application yaml file to enable notifications for specific argocd app. The following example uses the [on-sync-succeeded trigger](../catalog.md#triggers): 59 60 ```yaml 61 apiVersion: argoproj.io/v1alpha1 62 kind: Application 63 metadata: 64 annotations: 65 notifications.argoproj.io/subscribe.on-sync-succeeded.slack: my_channel 66 ``` 67 68 1. Annotation with more than one [trigger](../catalog.md#triggers), with multiple destinations and recipients 69 70 ```yaml 71 apiVersion: argoproj.io/v1alpha1 72 kind: Application 73 metadata: 74 annotations: 75 notifications.argoproj.io/subscriptions: | 76 - trigger: [on-scaling-replica-set, on-rollout-updated, on-rollout-step-completed] 77 destinations: 78 - service: slack 79 recipients: [my-channel-1, my-channel-2] 80 - service: email 81 recipients: [recipient-1, recipient-2, recipient-3 ] 82 - trigger: [on-rollout-aborted, on-analysis-run-failed, on-analysis-run-error] 83 destinations: 84 - service: slack 85 recipients: [my-channel-21, my-channel-22] 86 ``` 87 88 ## Templates 89 90 [Notification templates](../templates.md) can be customized to leverage slack message blocks and attachments 91 [feature](https://api.slack.com/messaging/composing/layouts). 92 93  94 95 The message blocks and attachments can be specified in `blocks` and `attachments` string fields under `slack` field: 96 97 ```yaml 98 template.app-sync-status: | 99 message: | 100 Application {{.app.metadata.name}} sync is {{.app.status.sync.status}}. 101 Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}. 102 slack: 103 attachments: | 104 [{ 105 "title": "{{.app.metadata.name}}", 106 "title_link": "{{.context.argocdUrl}}/applications/{{.app.metadata.name}}", 107 "color": "#18be52", 108 "fields": [{ 109 "title": "Sync Status", 110 "value": "{{.app.status.sync.status}}", 111 "short": true 112 }, { 113 "title": "Repository", 114 "value": "{{.app.spec.source.repoURL}}", 115 "short": true 116 }] 117 }] 118 ``` 119 120 If you want to specify an icon and username for each message, you can specify values for `username` and `icon` in the `slack` field. 121 For icon you can specify emoji and image URL, just like in the service definition. 122 If you set `username` and `icon` in template, the values set in template will be used even if values are specified in the service definition. 123 124 ```yaml 125 template.app-sync-status: | 126 message: | 127 Application {{.app.metadata.name}} sync is {{.app.status.sync.status}}. 128 Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}. 129 slack: 130 username: "testbot" 131 icon: https://example.com/image.png 132 attachments: | 133 [{ 134 "title": "{{.app.metadata.name}}", 135 "title_link": "{{.context.argocdUrl}}/applications/{{.app.metadata.name}}", 136 "color": "#18be52", 137 "fields": [{ 138 "title": "Sync Status", 139 "value": "{{.app.status.sync.status}}", 140 "short": true 141 }, { 142 "title": "Repository", 143 "value": "{{.app.spec.source.repoURL}}", 144 "short": true 145 }] 146 }] 147 ``` 148 149 The messages can be aggregated to the slack threads by grouping key which can be specified in a `groupingKey` string field under `slack` field. 150 `groupingKey` is used across each template and works independently on each slack channel. 151 When multiple applications will be updated at the same time or frequently, the messages in slack channel can be easily read by aggregating with git commit hash, application name, etc. 152 Furthermore, the messages can be broadcast to the channel at the specific template by `notifyBroadcast` field. 153 154 ```yaml 155 template.app-sync-status: | 156 message: | 157 Application {{.app.metadata.name}} sync is {{.app.status.sync.status}}. 158 Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}. 159 slack: 160 attachments: | 161 [{ 162 "title": "{{.app.metadata.name}}", 163 "title_link": "{{.context.argocdUrl}}/applications/{{.app.metadata.name}}", 164 "color": "#18be52", 165 "fields": [{ 166 "title": "Sync Status", 167 "value": "{{.app.status.sync.status}}", 168 "short": true 169 }, { 170 "title": "Repository", 171 "value": "{{.app.spec.source.repoURL}}", 172 "short": true 173 }] 174 }] 175 # Aggregate the messages to the thread by git commit hash 176 groupingKey: "{{.app.status.sync.revision}}" 177 notifyBroadcast: false 178 template.app-sync-failed: | 179 message: | 180 Application {{.app.metadata.name}} sync is {{.app.status.sync.status}}. 181 Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}. 182 slack: 183 attachments: | 184 [{ 185 "title": "{{.app.metadata.name}}", 186 "title_link": "{{.context.argocdUrl}}/applications/{{.app.metadata.name}}", 187 "color": "#ff0000", 188 "fields": [{ 189 "title": "Sync Status", 190 "value": "{{.app.status.sync.status}}", 191 "short": true 192 }, { 193 "title": "Repository", 194 "value": "{{.app.spec.source.repoURL}}", 195 "short": true 196 }] 197 }] 198 # Aggregate the messages to the thread by git commit hash 199 groupingKey: "{{.app.status.sync.revision}}" 200 notifyBroadcast: true 201 ``` 202 203 The message is sent according to the `deliveryPolicy` string field under the `slack` field. The available modes are `Post` (default), `PostAndUpdate`, and `Update`. The `PostAndUpdate` and `Update` settings require `groupingKey` to be set.