Spaces:
Sleeping
Sleeping
imseldrith
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -55,12 +55,12 @@ def webhook():
|
|
55 |
|
56 |
# Set typing on
|
57 |
set_typing_on(sender_id)
|
58 |
-
|
|
|
|
|
|
|
59 |
try:
|
60 |
-
|
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', '')
|
@@ -80,8 +80,9 @@ def webhook():
|
|
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,
|
84 |
-
|
|
|
85 |
# Set typing off after responding
|
86 |
set_typing_off(sender_id)
|
87 |
|
@@ -138,6 +139,17 @@ def set_typing_off(recipient_id):
|
|
138 |
print(f"Sending typing off request: {payload}")
|
139 |
response = requests.post(url, headers=headers, json=payload)
|
140 |
print(f"Typing off response: {response.status_code}, {response.text}")
|
141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
if __name__ == '__main__':
|
143 |
app.run(host="0.0.0.0", port=7860, debug=True)
|
|
|
55 |
|
56 |
# Set typing on
|
57 |
set_typing_on(sender_id)
|
58 |
+
# Get response with possible image URLs
|
59 |
+
response_data = chat_completion(message_text, sender_id)
|
60 |
+
print("ChatBot Response:\n", response_data)
|
61 |
+
|
62 |
try:
|
63 |
+
|
|
|
|
|
|
|
64 |
# Ensure response_data is a dictionary
|
65 |
if isinstance(response_data, dict):
|
66 |
response_text = response_data.get('msg', '')
|
|
|
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, )
|
84 |
+
# Mark message as seen
|
85 |
+
mark_seen(sender_id)
|
86 |
# Set typing off after responding
|
87 |
set_typing_off(sender_id)
|
88 |
|
|
|
139 |
print(f"Sending typing off request: {payload}")
|
140 |
response = requests.post(url, headers=headers, json=payload)
|
141 |
print(f"Typing off response: {response.status_code}, {response.text}")
|
142 |
+
|
143 |
+
def mark_seen(recipient_id):
|
144 |
+
url = f'https://graph.facebook.com/v12.0/me/messages?access_token={PAGE_ACCESS_TOKEN}'
|
145 |
+
headers = {'Content-Type': 'application/json'}
|
146 |
+
payload = {
|
147 |
+
'recipient': {'id': recipient_id},
|
148 |
+
'sender_action': 'mark_seen'
|
149 |
+
}
|
150 |
+
print(f"Sending mark seen request: {payload}")
|
151 |
+
response = requests.post(url, headers=headers, json=payload)
|
152 |
+
print(f"Mark seen response: {response.status_code}, {response.text}")
|
153 |
+
|
154 |
if __name__ == '__main__':
|
155 |
app.run(host="0.0.0.0", port=7860, debug=True)
|