The ability to receive an instant information from your application is extra important in our world. If you have a good instant channel from your code to your smartphone or laptop you can be quickly notified about contact form requests, new signups into your web app, some critical exceptions, or even receive daily usage logs.

In this post, we will share fast solution to implement notifications in several minutes using Slack. Slack is a chat application with a rich free plan which widely used by teams to communicate. The slack app could be launched from the browser (allowing to receive browser notifications), from desktop, or from a smartphone (allowing to receive push notifications on your phone).

To start, create a workspace in Slack or login into existing. Then go to https://app.slack.com/apps/manage/custom-integrations, click Bots, then click Add to Slack.

In the field Customize Name enter username of bot who will post notifications e.g. pybot, also save API integration token (xoxb-), and save the integration.

Now create a channel where you want to post notifications e.g. #pyapp and invite pybot into the channel using Details -> More -> Add App. Also, you can invite anybody from your team who should receive notifications.

Now install slackclient package from PyPI, e.g. using pip install or pipenv install:

pip3 install slackclient

add next code into your app:

import slack

SLACK_TOKEN='xoxb-xxxxx'
SLACK_CHANNEL='#pyapp'

message = 'Test message'
client = slack.WebClient(token=SLACK_TOKEN)
client.chat_postMessage(
      channel=SLACK_CHANNEL,
      text=message,
)

Now you can customize your messages by changing message variable. You can also apply formatting to your message using Slack markdown

Stay notified and keep things simple!