Slack Module
The slack module provides functions for Slack notification and alerting integration.
slack
Classes
SlackUtilMeta
Bases: type
Source code in src/mas/devops/slack.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
Attributes
client
property
Get or create the Slack WebClient instance.
Lazily initializes the Slack client using the SLACK_TOKEN environment variable.
Returns:
| Name | Type | Description |
|---|---|---|
WebClient |
WebClient
|
The Slack WebClient instance |
Raises:
| Type | Description |
|---|---|
Exception
|
If SLACK_TOKEN environment variable is not set |
Functions
postMessageBlocks(channelList, messageBlocks, threadId=None)
Post a message with block formatting to one or more Slack channels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channelList
|
str | list[str]
|
Single channel ID/name or list of channel IDs/names |
required |
messageBlocks
|
list
|
List of Slack block kit elements defining the message structure |
required |
threadId
|
str
|
Thread timestamp to post as a reply. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
SlackResponse | list[SlackResponse]
|
SlackResponse | list[SlackResponse]: Single response if one channel, list of responses if multiple channels |
Raises:
| Type | Description |
|---|---|
Exception
|
If message posting fails |
Source code in src/mas/devops/slack.py
postMessageText(channelList, message, attachments=None, threadId=None)
Post a plain text message to one or more Slack channels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channelList
|
str | list[str]
|
Single channel ID/name or list of channel IDs/names |
required |
message
|
str
|
The text message to post |
required |
attachments
|
list
|
List of message attachments. Defaults to None. |
None
|
threadId
|
str
|
Thread timestamp to post as a reply. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
SlackResponse | list[SlackResponse]
|
SlackResponse | list[SlackResponse]: Single response if one channel, list of responses if multiple channels |
Raises:
| Type | Description |
|---|---|
Exception
|
If message posting fails |
Source code in src/mas/devops/slack.py
createMessagePermalink(slackResponse=None, channelId=None, messageTimestamp=None, domain='ibm-mas')
Create a permanent link to a Slack message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slackResponse
|
SlackResponse
|
Slack response object containing channel and timestamp. Defaults to None. |
None
|
channelId
|
str
|
Channel ID if not using slackResponse. Defaults to None. |
None
|
messageTimestamp
|
str
|
Message timestamp if not using slackResponse. Defaults to None. |
None
|
domain
|
str
|
Slack workspace domain. Defaults to "ibm-mas". |
'ibm-mas'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Permanent URL to the Slack message |
Raises:
| Type | Description |
|---|---|
Exception
|
If neither slackResponse nor both channelId and messageTimestamp are provided |
Source code in src/mas/devops/slack.py
updateMessageBlocks(channelName, threadId, messageBlocks)
Update an existing Slack message with new block content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channelName
|
str
|
The channel ID or name containing the message |
required |
threadId
|
str
|
The timestamp of the message to update |
required |
messageBlocks
|
list
|
List of Slack block kit elements for the updated message |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SlackResponse |
SlackResponse
|
Response from the Slack API |
Raises:
| Type | Description |
|---|---|
Exception
|
If message update fails |
Source code in src/mas/devops/slack.py
buildHeader(title)
Build a header block for a Slack message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
The header text |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Slack block kit header element |
Source code in src/mas/devops/slack.py
buildSection(text)
Build a section block for a Slack message with markdown text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The section text (supports markdown formatting) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Slack block kit section element |
Source code in src/mas/devops/slack.py
buildContext(texts)
Build a context block for a Slack message with multiple text elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
list
|
List of text strings to include in the context |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Slack block kit context element |
Source code in src/mas/devops/slack.py
buildDivider()
Build a divider block for a Slack message.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Slack block kit divider element |