masadonline commited on
Commit
a66595a
·
verified ·
1 Parent(s): 9590248

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
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 convo_sid not in last_processed_timestamp or msg_time > last_processed_timestamp[convo_sid]:
215
- last_processed_timestamp[convo_sid] = msg_time
216
- question = latest_msg["body"]
217
- sender = latest_msg["author"]
218
- print(f"📩 New message from {sender}: {question}")
219
- context = "\n\n".join(retrieve_chunks(question, index, embed_model, text_chunks))
220
- answer = generate_answer_with_groq(question, context)
221
- send_twilio_message(client, convo_sid, answer)
 
222
  time.sleep(5)
223
 
224
- for convo in client.conversations.v1.conversations.list():
225
- if convo.sid not in processed_convos:
226
- processed_convos.add(convo.sid)
227
- threading.Thread(target=poll_convo, args=(convo.sid,), daemon=True).start()
 
 
 
 
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__":