Spaces:
Sleeping
Sleeping
imseldrith
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -56,21 +56,31 @@ def webhook():
|
|
56 |
# Set typing on
|
57 |
set_typing_on(sender_id)
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
# Set typing off after responding
|
76 |
set_typing_off(sender_id)
|
|
|
56 |
# Set typing on
|
57 |
set_typing_on(sender_id)
|
58 |
|
59 |
+
try:
|
60 |
+
# Get response with possible image URLs
|
61 |
+
response_data = chat_completion(message_text, sender_id)
|
62 |
+
print("ChatBot Response:\n", response_data)
|
63 |
+
|
64 |
+
# Ensure response_data is a dictionary
|
65 |
+
if isinstance(response_data, dict):
|
66 |
+
response_text = response_data.get('msg', '')
|
67 |
+
image_urls = response_data.get('image_urls', [])
|
68 |
+
|
69 |
+
print(f"ChatBot Response Text: {response_text}")
|
70 |
+
print(f"ChatBot Response Image URLs: {image_urls}")
|
71 |
+
|
72 |
+
# Send text and/or images
|
73 |
+
if response_text:
|
74 |
+
send_message(sender_id, response_text)
|
75 |
+
if image_urls:
|
76 |
+
for url in image_urls:
|
77 |
+
send_image(sender_id, url)
|
78 |
+
else:
|
79 |
+
print("Error: ChatBot response is not a dictionary.")
|
80 |
+
send_message(sender_id, "Sorry, I couldn't process your request.")
|
81 |
+
except Exception as e:
|
82 |
+
print(f"Exception occurred: {e}")
|
83 |
+
send_message(sender_id, "Sorry, an error occurred while processing your request.")
|
84 |
|
85 |
# Set typing off after responding
|
86 |
set_typing_off(sender_id)
|