Sending Messages
django_slack_tools.slack_messages.message
Handy APIs for sending Slack messages.
slack_message(body, *, channel, header=None, raise_exception=False, get_permalink=False, backend=app_settings.backend)
Send a simple text message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
body |
str | MessageBody | dict[str, Any]
|
Message content, simple message or full request body. |
required |
channel |
str
|
Channel to send message. |
required |
header |
MessageHeader | dict[str, Any] | None
|
Slack message control header. |
None
|
raise_exception |
bool
|
Whether to re-raise caught exception while sending messages. |
False
|
get_permalink |
bool
|
Try to get the message permalink via extraneous Slack API calls. |
False
|
backend |
BaseBackend
|
Messaging backend. If not set, use |
backend
|
Returns:
Type | Description |
---|---|
SlackMessage
|
Sent message instance or |
Source code in django_slack_tools/slack_messages/message.py
slack_message_via_policy(policy=app_settings.default_policy_code, *, header=None, raise_exception=False, lazy=False, get_permalink=False, context=None, backend=app_settings.backend)
Send a simple text message.
Some default context variables are populated and available for use in templates. See corresponding backend implementation for available context variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
policy |
str | SlackMessagingPolicy
|
Messaging policy code or policy instance. Defaults to app's default policy. |
default_policy_code
|
header |
MessageHeader | dict[str, Any] | None
|
Slack message control header. |
None
|
raise_exception |
bool
|
Whether to re-raise caught exception while sending messages. |
False
|
lazy |
bool
|
Decide whether try create policy with disabled, if not exists. |
False
|
get_permalink |
bool
|
Try to get the message permalink via extraneous Slack API calls. |
False
|
context |
dict[str, Any] | None
|
Dictionary to pass to template for rendering. |
None
|
backend |
BaseBackend
|
Messaging backend. If not set, use |
backend
|
Returns:
Type | Description |
---|---|
int
|
Count of messages sent successfully. |
Raises:
Type | Description |
---|---|
DoesNotExist
|
Policy for given code does not exists. |