Multi Workspace app installation with slack bolt sdk

See original GitHub issue

Hello, I am trying to create a Slack Bolt SDK app which I can install in multiple workspaces. I am an admin in multiple workspaces, but so far I am only able to install the bot to one of the two spaces. I believe I’ve implemented the OAuth flow properly but in my logs I keep seeing the second one can’t.

https://slack.dev/python-slack-sdk/oauth/ https://slack.dev/bolt-python/concepts#authenticating-oauth

I am running a flask app with gunicorn on the digitalocean platform.

I know FileInstallationStore is the default to store the data, should I change that? or I know other parts of my app use mongoDB. is there an equivalent for Mongo storage? Right now I see there’s sqlalchemy and sqlite3, but didnt know if that was what was going wrong here.

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 datetime import datetime

# https://slack.dev/bolt-python/concepts#authenticating-oauth
oauth_settings = OAuthSettings(
    client_id=os.environ["SLACK_CLIENT_ID"],
    client_secret=os.environ["SLACK_CLIENT_SECRET"],
    scopes=["chat:write","chat:write.public","commands","mpim:write"],
    installation_store=FileInstallationStore(base_dir="./data/installations"),
    state_store=FileOAuthStateStore(expiration_seconds=600, base_dir="./data/states")
)

app = App(
    signing_secret=os.environ["SLACK_SIGNING_SECRET"],
    oauth_settings=oauth_settings
)


logging.basicConfig(level=logging.DEBUG)

### CORE FLASK APP ###
@app.middleware  # or app.use(log_request)
def log_request(logger, body, next):
    logger.debug(body)
    return next()

# push

@app.event("app_home_opened")
def handle_app_home_opened_events(body, logger):
    print(body)
    logger.info(body)
    postMessage([{
                "type": "divider"
            },
            {
                "type": "section",
                "text": {
                "type": "mrkdwn",
                "text": "*This works!* :partying_face:"
                }
            }],"Hello from Slack", body['event']['user'])


@app.event("message")
def handle_message():
    pass

@app.command("/hello")
def test_the_test(ack, body):
    ack()
    print(body)
    postMessage([{
                "type": "divider"
            },
            {
                "type": "section",
                "text": {
                "type": "mrkdwn",
                "text": "*HELLO?!*."
                }
            }],"Hello from Slack", body['user_id'])

from flask import Flask, request

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


@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():
    return handler.handle(request)

@flask_app.route('/')
def hello_world():
    return 'Hello World from the Slack bot instance! Now trying OAuth'

def postMessage(message, text, userID):
    result = app.client.chat_postMessage(
    channel = userID,
    text=str(text).replace("', '", "").replace("['", "").replace("']", "").replace(
                '",', '').replace("', '", "").replace("',", "").replace(' "', '').replace(" '", "").replace("\\n", "\n"),
    blocks= message
    )
    print(result)

gunicorn_config.py bind = "0.0.0.0:8080" workers = 2

The slack_bolt version

slack-bolt==1.15.5 slack-sdk==3.19.5

Python runtime version

apps@flask-app-856f4cc5dc-wcjq4:~$ python --version Python 3.10.8

OS info

not sure since its on digitalocean, looks like it ight be a python docker container right now, but ideally I’ll eventually put this in an ubuntu container.

Steps to reproduce:

(Share the commands to run, source code, and project settings (e.g., setup.py))

  1. gunicorn --worker-tmp-dir /dev/shm app:flask_app

Expected result:

Should be able to install the app from /slack/install into a workspace , see success message and open slack… then when you visit the app_home_mention to trigger a message or try the /hello command see a message

Actual result:

install is successful, but home mention and command produce nothing in the second installation.

[flask-app] [2022-12-09 17:14:58] DEBUG:slack_sdk.oauth.installation_store.file:Installation data missing for enterprise: none, team: T03G4RLT3K3: [Errno 2] No such file or directory: './data/installations/none-T03G4RLT3K3/installer-latest'
[flask-app] [2022-12-09 17:14:58] DEBUG:slack_sdk.oauth.installation_store.file:Installation data missing for enterprise: none, team: T03G4RLT3K3: [Errno 2] No such file or directory: './data/installations/none-T03G4RLT3K3/bot-latest'
[flask-app] [2022-12-09 17:14:58] DEBUG:slack_bolt.oauth.oauth_settings:No installation data found for enterprise_id: None team_id: T03G4RLT3K3
[flask-app] [2022-12-09 17:14:58] ERROR:slack_bolt.MultiTeamsAuthorization:Although the app should be installed into this workspace, the AuthorizeResult (returned value from authorize) for it was not found.
[flask-app] [2022-12-09 17:14:58] 10.244.3.81 - - [09/Dec/2022:17:14:58 +0000] "POST /slack/events HTTP/1.1" 200 52 "-" "Slackbot 1.0 (+https://api.slack.com/robots)"
[flask-app] [2022-12-09 17:23:43] 10.244.0.1 - - [09/Dec/2022:17:23:43 +0000] "GET /slack/install HTTP/1.1" 200 646 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"
[flask-app] [2022-12-09 17:24:05] DEBUG:slack_sdk.oauth.installation_store.file:Installation data missing for enterprise: none, team: T03G4RLT3K3: [Errno 2] No such file or directory: './data/installations/none-T03G4RLT3K3/installer-latest'
[flask-app] [2022-12-09 17:24:05] DEBUG:slack_sdk.oauth.installation_store.file:Installation data missing for enterprise: none, team: T03G4RLT3K3: [Errno 2] No such file or directory: './data/installations/none-T03G4RLT3K3/bot-latest'
[flask-app] [2022-12-09 17:24:05] DEBUG:slack_bolt.oauth.oauth_settings:No installation data found for enterprise_id: None team_id: T03G4RLT3K3
[flask-app] [2022-12-09 17:24:05] ERROR:slack_bolt.MultiTeamsAuthorization:Although the app should be installed into this workspace, the AuthorizeResult (returned value from authorize) for it was not found.
[flask-app] [2022-12-09 17:24:05] 10.244.0.1 - - [09/Dec/2022:17:24:05 +0000] "POST /slack/events HTTP/1.1" 200 52 "-" "Slackbot 1.0 (+https://api.slack.com/robots)"

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

Issue Analytics

  • State:open
  • Created 9 months ago
  • Comments:27 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
seratchcommented, Dec 13, 2022

@ryanrestivo No need to do so! You need to do so only when your installation_store has lost some of the installation data due to misbehaviors.

1reaction
ryanrestivocommented, Dec 9, 2022

Oh I"m sorry about that. I’ll edit the other I see in there. just regenerated that OAuth token.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Distributing Slack apps
In this overview, we'll run through the different types of distribution, and explain how to install and authenticate users for each. Single-workspace apps;...
Read more >
Single Slack app to handle multiple workspaces (using Spring ...
So I'm using Spring Boot, Java, and Bolt to build a Slack bot. I've followed the instructions for making a Slack app bot...
Read more >
Getting started with Bolt for JavaScript
This guide is meant to walk you through getting up and running with a Slack app using Bolt for JavaScript. Along the way,...
Read more >
How to Build a Multi-Workspace Slack Application in Go - Blink
As we're developing a multi workspace app, we need to enable the OAuth installation flow. Navigate to Features → OAuth & Permissions:.
Read more >
Questions about [@slack/bolt] package for configuring for ...
If you build using the OAuth examples here, then it will work across multiple workspaces using a single instance of the app.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found