Adding a webhook to a Streamlit app

Hi,

I have a WhatsApp chatbot that has a webhook to receive messages from WhatsApp and sends messages to WhatsApp using Meta GraphAPI. To test it, I would like to use Streamlit as the test UI. Sending messages from Streamlit to my chatbot backend is easy, I just send them to the webhook. However, how can I receive messages from my chatbot backend? For that, I would need to add a webhook to the Streamlit app that could listen for incoming messages. After some research on the Internet, it seems that it’s not possible. Or is it? Alternatively, I could automatically refresh the page every couple of seconds. However, it seems that also that is not possible. Is that correct?

Any hints are appreciated!

Best,
Konstantin

EDIT: I tried to run FastAPI in a parallel process that implements the webhook and then uses Selenium to refresh the Streamlit app, as described here but it doesn’t work and I even don’t understand how the solution in that post could have worked at all, as it opens a separate connection to the Streamlit app and so doesn’t affect the already existing instance of the UI. Or am I missing an important step?

Hi @Konstantin_Miller,

Thanks for sharing this question!

You can try using our new st.experimental_fragment which allows you to rerun the app after a given time interval. See the docs here on how to implement it.

Thanks! That seems to work!

1 Like

It would be nice to create webhooks, basically REST endpoints, that one could call to trigger a refresh of the app. Then the app wouldn’t need to poll for information but could efficiently listen for it. Are there any plans for something like that?

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.

That’s a good idea. We have some stuff planned on our roadmap that you can check out here. Feel free to create an issue on our GitHub for this suggestion or check to see if it has been suggested already so you vote on it by thumbs upping it.

Glad it worked! Happy Streamlit-ing! :balloon: