github.com/argoproj/argo-cd/v2@v2.10.9/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 19 ## Configuration 20 21 1. Create Slack Application using https://api.slack.com/apps?new_app=1 22  23 1. Once application is created navigate to `Enter OAuth & Permissions` 24  25 1. Click `Permissions` under `Add features and functionality` section and add `chat:write` scope. To use the optional username and icon overrides in the Slack notification service also add the `chat:write.customize` scope. 26  27 1. Scroll back to the top, click 'Install App to Workspace' button and confirm the installation. 28  29 1. Once installation is completed copy the OAuth token. 30  31 32 1. Create a public or private channel, for this example `my_channel` 33 1. Invite your slack bot to this channel **otherwise slack bot won't be able to deliver notifications to this channel** 34 1. Store Oauth access token in `argocd-notifications-secret` secret 35 36 ```yaml 37 apiVersion: v1 38 kind: Secret 39 metadata: 40 name: <secret-name> 41 stringData: 42 slack-token: <Oauth-access-token> 43 ``` 44 45 1. Define service type slack in data section of `argocd-notifications-cm` configmap: 46 47 ```yaml 48 apiVersion: v1 49 kind: ConfigMap 50 metadata: 51 name: <config-map-name> 52 data: 53 service.slack: | 54 token: $slack-token 55 ``` 56 57 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): 58 59 ```yaml 60 apiVersion: argoproj.io/v1alpha1 61 kind: Application 62 metadata: 63 annotations: 64 notifications.argoproj.io/subscribe.on-sync-succeeded.slack: my_channel 65 ``` 66 67 1. Annotation with more than one [trigger](../catalog.md#triggers), with multiple destinations and recipients 68 69 ```yaml 70 apiVersion: argoproj.io/v1alpha1 71 kind: Application 72 metadata: 73 annotations: 74 notifications.argoproj.io/subscriptions: | 75 - trigger: [on-scaling-replica-set, on-rollout-updated, on-rollout-step-completed] 76 destinations: 77 - service: slack 78 recipients: [my-channel-1, my-channel-2] 79 - service: email 80 recipients: [recipient-1, recipient-2, recipient-3 ] 81 - trigger: [on-rollout-aborted, on-analysis-run-failed, on-analysis-run-error] 82 destinations: 83 - service: slack 84 recipients: [my-channel-21, my-channel-22] 85 ``` 86 87 ## Templates 88 89 [Notification templates](../templates.md) can be customized to leverage slack message blocks and attachments 90 [feature](https://api.slack.com/messaging/composing/layouts). 91 92  93 94 The message blocks and attachments can be specified in `blocks` and `attachments` string fields under `slack` field: 95 96 ```yaml 97 template.app-sync-status: | 98 message: | 99 Application {{.app.metadata.name}} sync is {{.app.status.sync.status}}. 100 Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}. 101 slack: 102 attachments: | 103 [{ 104 "title": "{{.app.metadata.name}}", 105 "title_link": "{{.context.argocdUrl}}/applications/{{.app.metadata.name}}", 106 "color": "#18be52", 107 "fields": [{ 108 "title": "Sync Status", 109 "value": "{{.app.status.sync.status}}", 110 "short": true 111 }, { 112 "title": "Repository", 113 "value": "{{.app.spec.source.repoURL}}", 114 "short": true 115 }] 116 }] 117 ``` 118 119 The messages can be aggregated to the slack threads by grouping key which can be specified in a `groupingKey` string field under `slack` field. 120 `groupingKey` is used across each template and works independently on each slack channel. 121 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. 122 Furthermore, the messages can be broadcast to the channel at the specific template by `notifyBroadcast` field. 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 attachments: | 131 [{ 132 "title": "{{.app.metadata.name}}", 133 "title_link": "{{.context.argocdUrl}}/applications/{{.app.metadata.name}}", 134 "color": "#18be52", 135 "fields": [{ 136 "title": "Sync Status", 137 "value": "{{.app.status.sync.status}}", 138 "short": true 139 }, { 140 "title": "Repository", 141 "value": "{{.app.spec.source.repoURL}}", 142 "short": true 143 }] 144 }] 145 # Aggregate the messages to the thread by git commit hash 146 groupingKey: "{{.app.status.sync.revision}}" 147 notifyBroadcast: false 148 template.app-sync-failed: | 149 message: | 150 Application {{.app.metadata.name}} sync is {{.app.status.sync.status}}. 151 Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}. 152 slack: 153 attachments: | 154 [{ 155 "title": "{{.app.metadata.name}}", 156 "title_link": "{{.context.argocdUrl}}/applications/{{.app.metadata.name}}", 157 "color": "#ff0000", 158 "fields": [{ 159 "title": "Sync Status", 160 "value": "{{.app.status.sync.status}}", 161 "short": true 162 }, { 163 "title": "Repository", 164 "value": "{{.app.spec.source.repoURL}}", 165 "short": true 166 }] 167 }] 168 # Aggregate the messages to the thread by git commit hash 169 groupingKey: "{{.app.status.sync.revision}}" 170 notifyBroadcast: true 171 ``` 172 173 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.