masadonline commited on
Commit
b94cf70
Β·
verified Β·
1 Parent(s): 31f1016

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -116,11 +116,18 @@ def send_twilio_message(client, conversation_sid, body):
116
  def get_latest_whatsapp_conversation_sid(client):
117
  conversations = client.conversations.v1.conversations.list(limit=20)
118
  for convo in conversations:
119
- if convo.chat_service_sid and "whatsapp" in convo.friendly_name.lower():
120
- return convo.sid
121
- # fallback to the first available conversation
 
 
 
 
 
 
122
  return conversations[0].sid if conversations else None
123
 
 
124
  # Streamlit UI
125
  st.set_page_config(page_title="Quasa – A Smart WhatsApp Chatbot", layout="wide")
126
  st.title("πŸ“± Quasa – A Smart WhatsApp Chatbot")
 
116
  def get_latest_whatsapp_conversation_sid(client):
117
  conversations = client.conversations.v1.conversations.list(limit=20)
118
  for convo in conversations:
119
+ try:
120
+ participants = client.conversations.v1.conversations(convo.sid).participants.list()
121
+ for p in participants:
122
+ if p.identity and p.identity.startswith("whatsapp:"):
123
+ return convo.sid
124
+ if p.messaging_binding and p.messaging_binding.get("address", "").startswith("whatsapp:"):
125
+ return convo.sid
126
+ except Exception as e:
127
+ continue
128
  return conversations[0].sid if conversations else None
129
 
130
+
131
  # Streamlit UI
132
  st.set_page_config(page_title="Quasa – A Smart WhatsApp Chatbot", layout="wide")
133
  st.title("πŸ“± Quasa – A Smart WhatsApp Chatbot")