-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Socket Mode and Flask/Gunicorn simultaneous run #255
Comments
Hey @rdbreak, thanks for asking the question! For an app that run with a Socket Mode connection, the app no longer needs to serve That being said, you may want to run web app too for Slack OAuth flow or some other purpose. For this, your app can use SocketModeAdapter's #
# Bolt App
#
import os
import logging
from slack_bolt import App
logging.basicConfig(level=logging.DEBUG)
app = App(token=os.environ["SLACK_BOT_TOKEN"])
# Add middleware / listeners here
@app.command("/hi")
def hello(body, ack):
user_id = body["user_id"]
ack(f"Hi <@{user_id}>!")
#
# Socket Mode
#
from slack_bolt.adapter.socket_mode import SocketModeHandler
handler = SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"])
# Use connect() method as start() blocks the current thread
handler.connect()
#
# Web App
#
from flask import Flask, request
flask_app = Flask(__name__)
# You won't use the Flask adapter as all the event requests are handled by the above Socket Mode connection
# from slack_bolt.adapter.flask import SlackRequestHandler
# handler = SlackRequestHandler(app)
@flask_app.route("/", methods=["GET"])
def index():
return "Hello World"
# You can run this app by the following command:
# gunicorn --bind :3000 --workers 1 --threads 2 --timeout 0 app:flask_app |
Thanks for you reply! I'll make the necessary changes. Thanks again! |
This sounds like a roundabout way to create a liveness endpoint for local user health checks. Is there some more built-in way to have a local user interact with SocketModeHandler().start()? This is for kubernetes to check periodically if the app is health. |
I recently switched my bot running in Heroku to the bolt framework but I'm only able to get it working in Socket Mode.
Reproducible in:
Steps to reproduce:
1.) Searched issues for existing issues.
2.) Tried various code changes. One example below:
3.) Disabled Socket Mode, reenabled.
4.) Tried different code snippets from Docker/Flask/flask-gunicorn examples directory
Expected result:
The bot to run and accept event requests server-side (via Heroku) and able to run Socket Mode for ongoing local development simultaneously.
Actual result:
Getting 404 and 503 errors (with Socket Mode disabled)
The text was updated successfully, but these errors were encountered: