Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -212,22 +212,22 @@ def start_conversation_monitor(client, index, embed_model, text_chunks):
|
|
212 |
if latest_msg:
|
213 |
msg_time = latest_msg["timestamp"]
|
214 |
if msg_time > APP_START_TIME:
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
time.sleep(5)
|
224 |
|
225 |
for convo in client.conversations.v1.conversations.list():
|
226 |
# convo.date_created is a datetime object in UTC, compare it with APP_START_TIME
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
|
232 |
|
233 |
# ---------------- Main Entry ----------------
|
|
|
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 |
for convo in client.conversations.v1.conversations.list():
|
226 |
# convo.date_created is a datetime object in UTC, compare it with APP_START_TIME
|
227 |
+
if convo.date_created is not None and convo.date_created > APP_START_TIME:
|
228 |
+
if convo.sid not in processed_convos:
|
229 |
+
processed_convos.add(convo.sid)
|
230 |
+
threading.Thread(target=poll_convo, args=(convo.sid,), daemon=True).start()
|
231 |
|
232 |
|
233 |
# ---------------- Main Entry ----------------
|