# Reporting
# kortical.reporting.slack
This library is used to send notification messages to Slack.
# Example usage
from kortical.reporting import slack
BOT_TOKEN = 'xoxb-sekhfvbq9247bqbvq974jb2pvi0ouvb'
slack.init(slack_bot_token=BOT_TOKEN)
slack.post_simple_message_to_slack(channels='<channel-name>',
title='New notification from Darth Vader!',
message='I am your father.')
If using this library in an app, here is a more realistic example of configuring Slack with environment config and a default test channel:
from kortical.environment import get_environment_config, get_environment_name
from kortical.reporting import slack
from kortical.secret import secret
environment_config = get_environment_config(format='yaml')
BOT_TOKEN = secret.get('slack_bot_token')
slack.init(slack_bot_token=BOT_TOKEN,
notify_slack=environment_config.get('notify_slack', False),
slack_test_channel='test_channel')
# Surround a message with tick marks to make it a code snippet
slack.post_simple_message_to_slack(
channels=['<channel-1-name>', '<channel-2-name>'],
title=f':boom: ERROR - There is a problem with your app ({get_environment_name()}) :BOOM:',
message=f'```<stack-trace>```')
# init
This function must be run to set up and configure slack reporting.
Inputs
slack_bot_token
- A unique identifier (starting"xoxb-"
) that represents a bot associated with your Slack app.notify_slack
(= True
) - Set this toFalse
to disable notifications; you might want to set this via config if you have an app that needs to alert in Production but nowhere else.slack_test_channel
(= None
) - If set up, this is a backup channel that will be alerted; even ifnotify_slack
is False.
Returns
None
# post_simple_message_to_slack
This function sends a message to Slack; for more granular control, see post_message_to_slack
.
Inputs
channels
- Slack channels you wish to notify (instr
or[str, ...]
format).title
- The title of the notification.message
- The body of the notification.
Returns
None
# post_message_to_slack
This function sends a message to Slack.
Inputs
channels
- Slack channels you wish to notify (instr
or[str, ...]
format).**kwargs
- any key word arguments; Slack usually requires notifications to be defined as a list calledblocks
.
Returns
None
← Platform API Datasets →