imseldrith commited on
Commit
23dddca
·
verified ·
1 Parent(s): 27dc5d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -15
app.py CHANGED
@@ -56,21 +56,31 @@ def webhook():
56
  # Set typing on
57
  set_typing_on(sender_id)
58
 
59
- # Get response with possible image URLs
60
- response_data = chat_completion(message_text, sender_id)
61
- print("ChatBot Response:\n", response_data)
62
- response_text = response_data.get('msg', '')
63
- image_urls = response_data.get('image_urls', [])
64
-
65
- print(f"ChatBot Response Text: {response_text}")
66
- print(f"ChatBot Response Image URLs: {image_urls}")
67
-
68
- # Send text and/or images
69
- if response_text:
70
- send_message(sender_id, response_text)
71
- if image_urls:
72
- for url in image_urls:
73
- send_image(sender_id, url)
 
 
 
 
 
 
 
 
 
 
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)