@@ -233,25 +233,26 @@ async def response_to_user_whatsapp(message: str, from_number: str, body, intro_
233
233
234
234
if chat_response .get ("response" ):
235
235
chat_response_text = chat_response ["response" ]
236
- data = make_whatsapp_payload (chat_response_text , from_number )
237
- response = whatsapp_cloud_api_session .post (url , json = data )
238
- response .raise_for_status ()
239
- elif chat_response .get ("image" ):
240
- media_url = chat_response ["image" ]
241
- if media_url :
242
- # Write the file to a tmp directory
243
- filepath = f"/tmp/{ int (time .time () * 1000 )} .png"
244
- response = requests .get (media_url )
245
- response .raise_for_status ()
236
+ if chat_response_text .get ("image" ):
237
+ media_url = chat_response_text ["image" ]
238
+ if media_url :
239
+ # Write the file to a tmp directory
240
+ filepath = f"/tmp/{ int (time .time () * 1000 )} .png"
241
+ response = requests .get (media_url )
242
+ response .raise_for_status ()
246
243
247
- with open (filepath , "wb" ) as f :
248
- f .write (response .content )
244
+ with open (filepath , "wb" ) as f :
245
+ f .write (response .content )
249
246
250
- media_id = upload_media_to_whatsapp (filepath , "image/png" , phone_number_id )
251
- data = make_whatsapp_image_payload (media_id , from_number )
252
- response = whatsapp_cloud_api_session .post (url , json = data )
253
- response .raise_for_status ()
254
- os .remove (filepath )
247
+ media_id = upload_media_to_whatsapp (filepath , "image/png" , phone_number_id )
248
+ data = make_whatsapp_image_payload (media_id , from_number )
249
+ response = whatsapp_cloud_api_session .post (url , json = data )
250
+ response .raise_for_status ()
251
+ os .remove (filepath )
252
+ else :
253
+ data = make_whatsapp_payload (chat_response_text , from_number )
254
+ response = whatsapp_cloud_api_session .post (url , json = data )
255
+ response .raise_for_status ()
255
256
elif chat_response .get ("detail" ):
256
257
chat_response_text = chat_response ["detail" ]
257
258
data = make_whatsapp_payload (chat_response_text , from_number )
0 commit comments