I'm building a chatbot through a web back-end that interacts with large chatting platform APIs, such as Slack. This is the current workflow:
- The user sends a message to my bot through Slack
- My webapp (Python Flask) receives an HTTP request from Slack's servers, with the identifier of the user
- The event is added to a queue and my webapp simply sends back a 200 status code
- A worker is spawned to handle the event. The worker ends up making an API call to Slack, with the ID of the user and the message to be displayed.
This system works fine. However, now I want to have my own chat front-end, interacting with my back-end. How can I manage to make my front-end wait for notifications sent by my back-end and display the message subsequently? Do I have to rely on websocket? Are there other means to do this that I haven't thought of? Clearly, it seems like I will need to have something that constantly maintains a connection between the client and my servers, unlike when making API calls which don't require a constant connection?
An additional issue is the fact that my API server and my workers are independent. That is, when the API server receives a request, the worker is spawned independently. If I imagined something using websocket, I believe my worker would have to send a request to my API server, which would then send the content through websocket to the client. I'm wondering if this seems correct or just totally absurd.