I have the following Python code which works fine using the Web Socket mode. When I type a slash command (/hello-socket-mode) on my Slash application then it very well invokes my method, handle_some_command():-
import os
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler
# Install the Slack app and get xoxb- token in advance
app = App(token="<bot token>")
# Add functionality here
@app.command("/hello-socket-mode")
def handle_some_command(ack, body, logger):
ack()
print('testing slash command')
logger.info(body)
if __name__ == "__main__":
# Create an app-level token with connections:write scope
handler = SocketModeHandler(app,"<app token>")
handler.start()
Since I'm in the development phase of my Slack app, I want to add reload functionality to this backend code of the web socket such that it reloads automatically whenever there is a change in the code. I tried to add uvicorn here but with that, I stopped getting invocation to my backend method, handle_some_command()whenever I tried to enter the slash command in the my slack application. I created a separate Python script called run.py with following code:-
from uvicorn import run
if __name__ == "__main__":
run("main:app", host="0.0.0.0", port=3000, reload=True, log_level="info")
And then executed, python run.py to run my app using uvicorn to reload whenever there is a code change. It is not working at all, I'm not getting any slash command invocation to my backend code now.
I just need some way of reload and not necessarily uvicorn here. I would appreciate it if someone could please guide me on this to make it work.
Code like this will work; you may delete fastapi dependency if not needed when development finished
And call this code like this: