Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -157,9 +157,10 @@ def fetch_latest_incoming_message(client, conversation_sid):
|
|
157 |
"timestamp": msg.date_created,
|
158 |
}
|
159 |
except TwilioRestException as e:
|
160 |
-
print(f"Twilio error: {e}")
|
161 |
return None
|
162 |
|
|
|
163 |
def send_twilio_message(client, conversation_sid, body):
|
164 |
return client.conversations.v1.conversations(conversation_sid).messages.create(
|
165 |
author="system", body=body
|
@@ -221,11 +222,16 @@ def start_conversation_monitor(client, index, embed_model, text_chunks):
|
|
221 |
send_twilio_message(client, convo_sid, answer)
|
222 |
time.sleep(5)
|
223 |
|
224 |
-
|
225 |
-
|
|
|
|
|
|
|
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__":
|
231 |
st.title("π€ ToyBot WhatsApp Assistant")
|
|
|
157 |
"timestamp": msg.date_created,
|
158 |
}
|
159 |
except TwilioRestException as e:
|
160 |
+
print(f"β Twilio error for SID {conversation_sid}: {e}")
|
161 |
return None
|
162 |
|
163 |
+
|
164 |
def send_twilio_message(client, conversation_sid, body):
|
165 |
return client.conversations.v1.conversations(conversation_sid).messages.create(
|
166 |
author="system", body=body
|
|
|
222 |
send_twilio_message(client, convo_sid, answer)
|
223 |
time.sleep(5)
|
224 |
|
225 |
+
conversations = client.conversations.v1.conversations.list()
|
226 |
+
|
227 |
+
for convo in conversations:
|
228 |
+
# Filter out conversations created before app startup
|
229 |
+
if convo.date_created > APP_START_TIME and convo.sid not in processed_convos:
|
230 |
processed_convos.add(convo.sid)
|
231 |
+
print(f"π Monitoring conversation SID: {convo.sid}, Created at: {convo.date_created}")
|
232 |
threading.Thread(target=poll_convo, args=(convo.sid,), daemon=True).start()
|
233 |
|
234 |
+
|
235 |
# ---------------- Main Entry ----------------
|
236 |
if __name__ == "__main__":
|
237 |
st.title("π€ ToyBot WhatsApp Assistant")
|