masadonline commited on
Commit
9bf5f49
·
verified ·
1 Parent(s): 2ed8220

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -121,11 +121,26 @@ def fetch_latest_incoming_message(account_sid, auth_token, conversation_sid):
121
  def send_twilio_message(account_sid, auth_token, conversation_sid, body):
122
  try:
123
  client = Client(account_sid, auth_token)
124
- message = client.conversations.v1.conversations(conversation_sid).messages.create(author="system", body=body)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  return message.sid
126
  except Exception as e:
127
  return str(e)
128
 
 
129
  # --- Streamlit UI ---
130
  st.set_page_config(page_title="Quasa – A Smart WhatsApp Chatbot", layout="wide")
131
 
 
121
  def send_twilio_message(account_sid, auth_token, conversation_sid, body):
122
  try:
123
  client = Client(account_sid, auth_token)
124
+ # Get participants to find the bot's WhatsApp identity
125
+ participants = client.conversations.v1.conversations(conversation_sid).participants.list()
126
+ # Pick the first participant whose identity starts with 'whatsapp:'
127
+ bot_identity = None
128
+ for p in participants:
129
+ if p.identity.startswith("whatsapp:"):
130
+ bot_identity = p.identity
131
+ break
132
+ if not bot_identity:
133
+ return "⚠️ Bot identity with whatsapp: prefix not found in participants."
134
+
135
+ message = client.conversations.v1.conversations(conversation_sid).messages.create(
136
+ author=bot_identity,
137
+ body=body
138
+ )
139
  return message.sid
140
  except Exception as e:
141
  return str(e)
142
 
143
+
144
  # --- Streamlit UI ---
145
  st.set_page_config(page_title="Quasa – A Smart WhatsApp Chatbot", layout="wide")
146