Messages
Messages are the top-level objects you send to Slack. slackblocks provides several message types depending on the API surface you're targeting:
| Class | When to use it |
|---|---|
Message |
Posting a normal message via chat.postMessage (the most common case). |
WebhookMessage |
Sending to an Incoming Webhook URL. |
MessageResponse |
Replying to a slash command or an interaction response_url. |
All three implement __getitem__/keys(), so you can unpack them with **message straight into the Slack SDK. See Sending Messages for end-to-end examples.
Slack reference: https://api.slack.com/methods/chat.postMessage
Messages are the core unit of Slack messaging functionality. They can be built out using blocks, elements, objects, and rich text features.
See: https://api.slack.com/messaging
Message
A Slack message object that can be converted to a JSON string for use with the Slack message API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel
|
str
|
the Slack channel to send the message to, e.g. "#general". |
required |
text
|
str | None
|
markdown text to send in the message. If |
''
|
blocks
|
list[Block] | Block | None
|
a list of |
None
|
attachments
|
list[Attachment] | None
|
a list of
|
None
|
thread_ts
|
str | None
|
the timestamp ID of another unthreaded message that will become the parent message of this message (now a reply in a thread). |
None
|
mrkdwn
|
bool
|
if |
True
|
unfurl_links
|
bool | None
|
if |
None
|
unfurl_media
|
bool | None
|
if |
None
|
Throws:
InvalidUsageException: in the event that the items passed to blocks
are not valid Blocks.
Source code in slackblocks/messages.py
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 | |
MessageResponse
A required, immediate response that confirms your app received the payload.
Source code in slackblocks/messages.py
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 | |
ResponseType
Types of messages that can be sent via WebhookMessage.
Source code in slackblocks/messages.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
WebhookMessage
Messages sent via the Slack WebhookClient takes different arguments than
those sent via the regular WebClient.
See: https://github.com/slackapi/python-slack-sdk/blob/7e71b73/slack_sdk/webhook/client.py#L28
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str | None
|
markdown text to send in the message. If |
None
|
attachments
|
Attachment | list[Attachment] | None
|
a list of
|
None
|
blocks
|
Block | list[Block] | None
|
a list of |
None
|
response_type
|
ResponseType | str | None
|
one of |
None
|
replace_original
|
bool | None
|
when |
None
|
delete_original
|
bool | None
|
when |
None
|
unfurl_links
|
bool | None
|
if |
None
|
unfurl_media
|
bool | None
|
if |
None
|
metadata
|
dict[str, Any] | None
|
additional metadata to attach to the message. |
None
|
headers
|
dict[str, str] | None
|
HTTP request headers to include with the message. |
None
|
Throws
InvalidUsageError: when any of the passed fields fail validation.
Source code in slackblocks/messages.py
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 | |
_MessagePayloadMixin
Shared serialization helpers used by both BaseMessage and WebhookMessage.
Both expose the same interface (to_dict(), json(), __repr__,
__getitem__, keys()) so that **msg unpacking works with the
Slack Web/Webhook clients. Concrete subclasses must implement
_resolve.
Source code in slackblocks/messages.py
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 | |