Adding a webhook to a Streamlit app


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!


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!

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.