Messaging Backends
django_slack_tools.slack_messages.backends
BaseBackend
Bases: ABC
Abstract base class for messaging backends.
Source code in django_slack_tools/slack_messages/backends/base.py
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 |
|
prepare_message(*, policy=None, channel, header, body)
Prepare message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
policy |
SlackMessagingPolicy | None
|
Related policy instance. |
None
|
channel |
str
|
Channel to send message. |
required |
header |
MessageHeader
|
Slack message control header. |
required |
body |
MessageBody
|
Slack message body. |
required |
Returns:
Type | Description |
---|---|
SlackMessage
|
Prepared message. |
Source code in django_slack_tools/slack_messages/backends/base.py
prepare_messages_from_policy(policy, *, header, context)
Prepare messages from policy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
policy |
SlackMessagingPolicy
|
Policy to create messages from. |
required |
header |
MessageHeader
|
Common message header. |
required |
context |
dict[str, Any]
|
Message context. |
required |
Returns:
Type | Description |
---|---|
list[SlackMessage]
|
Prepared messages. |
Source code in django_slack_tools/slack_messages/backends/base.py
send_message(message, *, raise_exception, get_permalink)
Send message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message |
SlackMessage
|
Prepared message. |
required |
raise_exception |
bool
|
Whether to propagate exceptions. |
required |
get_permalink |
bool
|
Try to get the message permalink via additional Slack API call. |
required |
Returns:
Type | Description |
---|---|
SlackMessage
|
Message sent to Slack. |
Source code in django_slack_tools/slack_messages/backends/base.py
send_messages(*messages, raise_exception, get_permalink)
Shortcut to send multiple messages.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages |
SlackMessage
|
Messages to send. |
()
|
raise_exception |
bool
|
Whether to propagate exceptions. |
required |
get_permalink |
bool
|
Try to get the message permalink via additional Slack API call. |
required |
Returns:
Type | Description |
---|---|
int
|
Count of messages sent successfully. |
Source code in django_slack_tools/slack_messages/backends/base.py
DummyBackend
Bases: BaseBackend
An dummy backend that does nothing with message.
Source code in django_slack_tools/slack_messages/backends/dummy.py
LoggingBackend
Bases: DummyBackend
Backend that log the message rather than sending it.
Source code in django_slack_tools/slack_messages/backends/logging.py
SlackBackend
Bases: BaseBackend
Backend actually sending the messages.
Source code in django_slack_tools/slack_messages/backends/slack.py
__init__(*, slack_app)
Initialize backend.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slack_app |
App | Callable[[], App] | str
|
Slack app instance or import string. |
required |
Source code in django_slack_tools/slack_messages/backends/slack.py
SlackRedirectBackend
Bases: SlackBackend
Inherited Slack backend with redirection to specific channels.
Source code in django_slack_tools/slack_messages/backends/slack.py
__init__(*, slack_app, redirect_channel, inform_redirect=True)
Initialize backend.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slack_app |
App | str
|
Slack app instance or import string. |
required |
redirect_channel |
str
|
Slack channel to redirect. |
required |
inform_redirect |
bool
|
Whether to append an attachment informing that the message has been redirected.
Defaults to |
True
|
Source code in django_slack_tools/slack_messages/backends/slack.py
prepare_message(*args, channel, body, **kwargs)
Prepare message to send, with modified for redirection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
Any
|
Positional arguments to pass to super method. |
()
|
channel |
str
|
Original channel to send message. |
required |
body |
MessageBody
|
Message content. |
required |
kwargs |
Any
|
Keyword arguments to pass to super method. |
{}
|
Returns:
Type | Description |
---|---|
SlackMessage
|
Prepared message instance. |