Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import uuid
|
|
6 |
from db import fetch_json_from_github
|
7 |
from qwen import get_qwen_response
|
8 |
from upload import upload_image_to_cdn, upload_audio_to_cdn
|
|
|
9 |
|
10 |
app = Flask(__name__)
|
11 |
|
@@ -95,6 +96,9 @@ def handle_message():
|
|
95 |
message = messaging_event["message"]
|
96 |
|
97 |
# Fetch the user's profile information via the proxy API
|
|
|
|
|
|
|
98 |
try:
|
99 |
proxy_params = {
|
100 |
"sender_id": sender_id,
|
@@ -106,12 +110,12 @@ def handle_message():
|
|
106 |
|
107 |
if proxy_data["success"]:
|
108 |
user_full_name = proxy_data["full_name"]
|
|
|
|
|
109 |
else:
|
110 |
print(f"Proxy API error: {proxy_data['error']}")
|
111 |
-
user_full_name = "User" # Default fallback
|
112 |
except Exception as e:
|
113 |
print(f"Error calling proxy API: {str(e)}")
|
114 |
-
user_full_name = "User" # Default fallback
|
115 |
|
116 |
# Get or create chat history for this user
|
117 |
user_history = chat_histories.setdefault(sender_id, {
|
@@ -217,6 +221,16 @@ def handle_message():
|
|
217 |
chat_history=user_history['history']
|
218 |
)
|
219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
# Append the AI's response to the chat history
|
221 |
user_history['history'].append({
|
222 |
"role": "assistant",
|
|
|
6 |
from db import fetch_json_from_github
|
7 |
from qwen import get_qwen_response
|
8 |
from upload import upload_image_to_cdn, upload_audio_to_cdn
|
9 |
+
from admin_messages import extract_admin_message, save_admin_message
|
10 |
|
11 |
app = Flask(__name__)
|
12 |
|
|
|
96 |
message = messaging_event["message"]
|
97 |
|
98 |
# Fetch the user's profile information via the proxy API
|
99 |
+
user_full_name = "User" # Default fallback
|
100 |
+
user_profile_img = "" # Default empty profile image URL
|
101 |
+
|
102 |
try:
|
103 |
proxy_params = {
|
104 |
"sender_id": sender_id,
|
|
|
110 |
|
111 |
if proxy_data["success"]:
|
112 |
user_full_name = proxy_data["full_name"]
|
113 |
+
# Also get the profile image URL if available
|
114 |
+
user_profile_img = proxy_data.get("profile_pic", "")
|
115 |
else:
|
116 |
print(f"Proxy API error: {proxy_data['error']}")
|
|
|
117 |
except Exception as e:
|
118 |
print(f"Error calling proxy API: {str(e)}")
|
|
|
119 |
|
120 |
# Get or create chat history for this user
|
121 |
user_history = chat_histories.setdefault(sender_id, {
|
|
|
221 |
chat_history=user_history['history']
|
222 |
)
|
223 |
|
224 |
+
# Check if the AI response contains an admin message
|
225 |
+
admin_message, cleaned_response = extract_admin_message(ai_response)
|
226 |
+
|
227 |
+
# If there's an admin message, save it to the GitHub JSON file
|
228 |
+
if admin_message:
|
229 |
+
print(f"Admin message detected: {admin_message}")
|
230 |
+
save_admin_message(page_id, admin_message, user_profile_img)
|
231 |
+
# Use the cleaned response (without admin tags) for the user
|
232 |
+
ai_response = cleaned_response
|
233 |
+
|
234 |
# Append the AI's response to the chat history
|
235 |
user_history['history'].append({
|
236 |
"role": "assistant",
|