Skip right to the code

TLDR: Want to jump right into the code, checkout the code here:


A Slack account A Slack app with Bot Token Scopes and User Token Scopes set up

Step 1. Import the necessary libraries:

import logging
import os
from slack_bolt import App
from slack_bolt.oauth.oauth_settings import OAuthSettings
from slack_sdk.oauth.installation_store import FileInstallationStore
from slack_sdk.oauth.state_store import FileOAuthStateStore
from slack_bolt.adapter.flask import SlackRequestHandler
from slack_bolt.oauth import OAuthFlow
from slack_sdk import WebClient
import json
import requests
import uuid

Step 2. Create the OAuth settings object with your client ID, client secret, and desired scopes. You’ll also need to specify the installation and state store directories, as well as the redirect URI for the OAuth flow.

oauth_settings = OAuthSettings(
    "chat:write", "app_mentions:read", "channels:join", "im:write",
    "im:history", "chat:write.public", "commands", "mpim:write"

Step 3. Create the Slack Bolt app object with your signing secret and OAuth settings object.

app = App(signing_secret="YOUR_SIGNING_SECRET",


Step 4. Create a WebClient object with your bot token. This will be used to send messages later.

client = WebClient(token="YOUR_BOT_TOKEN")

Step 5. Define any event handlers that you want to use with your app. In this case, there are two event handlers: one for message events and one for app_mention events.

This code responds with a “Hi from your Slackbot!” message and calls the API endpoint at It retrieves the title field from the API response and sends it back as a message to the channel.

def handle_message():

def handle_mention(event, say):
    print("got message from app")
    thread_ts = event['thread_ts'] if 'thread_ts' in event else event['ts']
    message_text = event["text"]
    channel_id = event["channel"]
    thread_ts = event["ts"]
    say("Hi from your Slackbot!")
    response = requests.get("")
    if response.status_code == 200:
        response = response.json()['title']
        print(f"Request failed with status code {response.status_code}")
    say(text=response, thread_ts=thread_ts)

Step 6. Create a Flask app and a Slack request handler for your app.

flask_app = Flask(__name__)
handler = SlackRequestHandler(app)

Step 7. Define a route for Slack events and use the request handler to handle requests.

@flask_app.route("/slack/events", methods=["POST"])
def slack_events():
  return handler.handle(request)

@flask_app.route("/slack/install", methods=["GET"])
def install():
  return handler.handle(request)

@flask_app.route("/slack/oauth_redirect", methods=["GET"])
def oauth_redirect():
  print("in flask oauth handler")
  return handler.handle(request)

Step 8. Enjoy :)

Link to a demo slack bot we built at Berri: