How to integrate dbt with Slack

Using Slack bots can be a great time saver. They can enhance whatever workflow they are a part of, be it project management, version control or simple content sharing.
As we bring our dbt projects to production, Slack bots can help us stay on top of dbt runs and models. In this post, we will walk through a process of building a simple Slack bot that sends messages about dbt models. The bot will be written in Python and we will use fal to run the bot script inside a dbt project.
Setup a Slack bot
The first step is to configure a Slack bot via the Slack website:
- Create a Slack App from scratch
- Go to OAuth & Permissions section
- On the left sidebar find Bot Token Scopes
- Click Add an OAuth Scope and add these scopes:
channels:join
andchat:write
- Go to Install App and click on Install to Workspace
- Copy the resulting Bot User OAuth Token and put it in a safe place
Now switch to a Slack window and go to a channel that you want the bot to post messages to. Type this message: /invite @YourBotName

In the side-bar, right-click on the channel name and click on Open channel details.

A modal should open and at the very bottom there is a channel ID. Copy that and put it in a safe place.
We're done configuring the Slack bot. The next step is to build our bot.
Slack Bot Script
In your dbt project directory, create a new file named slack_bot.py
and open it. We start by importing dependencies and setting the Slack variables that we stored earlier:
import os
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
CHANNEL_ID = "your_slack_channel_id"
SLACK_TOKEN = "your_slack_bot_token"
client = WebClient(token=SLACK_TOKEN)
We then prepare a message that is going to be sent to Slack:
message_text = f"Model: {context.current_model.name}. Status: {context.current_model.status}."
context
is a magic variable that will be provided by fal. You don't need to import it. It lets you access information about a model connected to this script. More on connecting models to scripts in the next section. Here, we're using the context variable to access a model name and status.
The final bit of our script will actually send our message:
client.chat_postMessage(
channel=CHANNEL_ID,
text=message_text
)
The full code example is available here:
Setup fal
fal is a package that lets you run Python inside your dbt project. You can install it with pip:
pip install fal
You're now ready to connect a dbt model to your Python script. Go to your dbt project directory and find a relevant schema.yml file. Choose a model that you want to use with your bot and add a fal meta tag:
models:
- name: boston
description: Ozone levels
config:
materialized: table
meta:
fal:
scripts:
- slack_bot.py
That's it. The boston
model in this example is now connected to slack_bot.py.
Run scripts
In the command line, run dbt:
dbt run
Followed by fal:
fal run
If everything is setup correctly, you should see a bot Slack message in your channel.

Conclusion
Congratulations! You have used fal in order to built a Slack bot that runs inside your dbt project.
Stay tuned for more posts on the cool things you can do with fal and dbt. Check out the fal repository for more info and join our Discord server.