Sign inGet started

Slack

Integrate Deepnote with Slack

Slack is the collaboration hub that brings the right people, information, and tools together to get work done. In Deepnote, you can use the built-in integration for Slack to report on your scheduled notebook runs and keep you and your stakeholders up-to-date with the recent work. Deepnote lets you execute your notebooks on daily, weekly, or hourly basis. This is useful if you would like to process data or update a dashboard at a regular frequency.

Slack notifications workflow

How to schedule a notebook and get notified in Slack

You can find the integration for Slack inside the Scheduling modal in each notebook.

  1. Click the Scheduling button next to the Run notebook button at the top of your notebook
  2. Configure the frequency at which you would like the notebook to run
  3. Enable the Send notification via Slack after run
  4. Slack authentication window will pop up, choose the right workspace and allow access for the Deepnote app.
  5. Choose the channels or users you'd like to get notified about success or failure runs
  6. Click Save schedule

Note that by default you will only see public channels of your workspace. If you'd like to send the messages to a private channel, add the Deepnote app inside Slack to the private channel, and you'll be able to send messages there as well.

If you wish to remove the auth pairing of your Slack and Deepnote workspaces, you can do it either from the Slack app directory, or you can navigate to Settings & members -> Project settings in your Deepnote workspace, and deselect the Slack notifications toggle.

If you have trouble using our application for Slack - contact our support by sending an email to help@deepnote.com.

To learn more about how our app for Slack will collect, manage, and store third-party data refer to our privacy policy.

Connecting to Slack programmatically

If you'd like more control of various features of Slack API, you can also connect to Slack programmatically from Deepnote. The following guide walks you through using Slack to deliver notifications at different points of your data workflows on Deepnote (like updating you on the status of scheduled notebook runs).

API tokens must be stored securely and should never be logged, stored in client-side code and public repositories, or made accessible to end-users. If you choose this approach - make sure your notebooks are not public.

The first step in integrating Slack with your Deepnote notebooks is creating a Slack app and getting your app's token. All you need to do to get started is:

  1. Create a Slack app by clicking the Create App button here.
  2. Copy the Slack token of your new app. It should start with "xoxb", for example xoxb-not-a-real-token-this-will-not-work.
  3. Store the token in a variable (such as SLACK_TOKEN). If you'd like to keep your data secure, consider storing the token as an environment variable. Environment variables in Deepnote are encrypted and provide a secure way of storing sensitive data.
  4. Install the slack_sdk __ Python __ package by running !pip install slack_sdk.

Once you've created your Slack app and installed the slack_sdk Python package, sending notifications via Slack becomes rather straightforward. The code below sends a notification into the #general channel informing everyone in that channel of a successful run.

import os
from datetime import datetime
import slack_sdk

CHANNEL = '#general' # Insert the name of channel here
USERNAME = 'Deepnote Bot'
ICON = 'https://avatars.githubusercontent.com/u/45339858?s=280&v=4' # This is a URL pointing to the icon of your bot.
today = datetime.today().strftime('%B %d, %Y at %H:%M UTC')
MESSAGE_TEXT = f'Experiment status: Success!\nLast run: {today}' # This is a sample message. Replace with your own text.

def post_message_to_slack(slack_token, text, channel, blocks=None):
    try:
        print('Sending message...')
        # Connect to the Slack client via token
        client = slack_sdk.WebClient(token=SLACK_TOKEN)

        # Post the Slack message
        request = client.chat_postMessage(
            text=text,
            channel=channel,
            blocks=blocks,
            icon_url=ICON,
            username=USERNAME
        )
        print('Message was sent successfully.')
        return request

        # Print error
    except Exception as e:
        print(f'Error: {e}')

request = post_message_to_slack(SLACK_TOKEN, MESSAGE_TEXT, CHANNEL)

Using the function above to send a message will produce a Slack notification that is going to look a little something like this:

Slack notification from Deepnote

Jump right into Deepnote & view an example of manually sending scheduled notebook run Slack updates here. You can also save yourself some setup work by hitting Duplicate button in the top-right corner to start exploring on your own!