Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -135,9 +135,8 @@ def setup_knowledge_base():
|
|
135 |
# --- Monitor All Conversations ---
|
136 |
def start_conversation_monitor(client, index, embed_model, text_chunks):
|
137 |
last_msg_index = {}
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
def poll_conversation(convo_sid):
|
142 |
while True:
|
143 |
try:
|
@@ -154,8 +153,23 @@ def start_conversation_monitor(client, index, embed_model, text_chunks):
|
|
154 |
print(f"❌ Error in convo {convo_sid} polling:", e)
|
155 |
time.sleep(5)
|
156 |
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
# --- Streamlit UI ---
|
161 |
st.set_page_config(page_title="Quasa – A Smart WhatsApp Chatbot", layout="wide")
|
|
|
135 |
# --- Monitor All Conversations ---
|
136 |
def start_conversation_monitor(client, index, embed_model, text_chunks):
|
137 |
last_msg_index = {}
|
138 |
+
monitored_sids = set()
|
139 |
+
|
|
|
140 |
def poll_conversation(convo_sid):
|
141 |
while True:
|
142 |
try:
|
|
|
153 |
print(f"❌ Error in convo {convo_sid} polling:", e)
|
154 |
time.sleep(5)
|
155 |
|
156 |
+
def monitor_all_conversations():
|
157 |
+
while True:
|
158 |
+
try:
|
159 |
+
current_sids = set(get_whatsapp_conversation_sids(client))
|
160 |
+
new_sids = current_sids - monitored_sids
|
161 |
+
for sid in new_sids:
|
162 |
+
print(f"➡️ Starting to monitor new conversation: {sid}")
|
163 |
+
monitored_sids.add(sid)
|
164 |
+
threading.Thread(target=poll_conversation, args=(sid,), daemon=True).start()
|
165 |
+
time.sleep(15) # refresh every 15 seconds or adjust as needed
|
166 |
+
except Exception as e:
|
167 |
+
print("❌ Error in conversation monitoring loop:", e)
|
168 |
+
time.sleep(15)
|
169 |
+
|
170 |
+
# Start the monitoring loop in a separate thread so it runs in background
|
171 |
+
threading.Thread(target=monitor_all_conversations, daemon=True).start()
|
172 |
+
|
173 |
|
174 |
# --- Streamlit UI ---
|
175 |
st.set_page_config(page_title="Quasa – A Smart WhatsApp Chatbot", layout="wide")
|