Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -211,20 +211,25 @@ def start_conversation_monitor(client, index, embed_model, text_chunks):
|
|
211 |
latest_msg = fetch_latest_incoming_message(client, convo_sid)
|
212 |
if latest_msg:
|
213 |
msg_time = latest_msg["timestamp"]
|
214 |
-
if
|
215 |
-
last_processed_timestamp[convo_sid]
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
|
|
222 |
time.sleep(5)
|
223 |
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
|
|
|
|
|
|
|
|
228 |
|
229 |
# ---------------- Main Entry ----------------
|
230 |
if __name__ == "__main__":
|
|
|
211 |
latest_msg = fetch_latest_incoming_message(client, convo_sid)
|
212 |
if latest_msg:
|
213 |
msg_time = latest_msg["timestamp"]
|
214 |
+
if msg_time > APP_START_TIME:
|
215 |
+
if convo_sid not in last_processed_timestamp or msg_time > last_processed_timestamp[convo_sid]:
|
216 |
+
last_processed_timestamp[convo_sid] = msg_time
|
217 |
+
question = latest_msg["body"]
|
218 |
+
sender = latest_msg["author"]
|
219 |
+
print(f"📩 New message from {sender}: {question}")
|
220 |
+
context = "\n\n".join(retrieve_chunks(question, index, embed_model, text_chunks))
|
221 |
+
answer = generate_answer_with_groq(question, context)
|
222 |
+
send_twilio_message(client, convo_sid, answer)
|
223 |
time.sleep(5)
|
224 |
|
225 |
+
# Filter only conversations created after app start
|
226 |
+
conversations = client.conversations.v1.conversations.list()
|
227 |
+
for convo in conversations:
|
228 |
+
if convo.date_created > APP_START_TIME:
|
229 |
+
if convo.sid not in processed_convos:
|
230 |
+
processed_convos.add(convo.sid)
|
231 |
+
threading.Thread(target=poll_convo, args=(convo.sid,), daemon=True).start()
|
232 |
+
|
233 |
|
234 |
# ---------------- Main Entry ----------------
|
235 |
if __name__ == "__main__":
|