fix message
Browse files- app/config.py +4 -4
- app/facebook.py +4 -2
app/config.py
CHANGED
|
@@ -8,9 +8,9 @@ from loguru import logger
|
|
| 8 |
load_dotenv()
|
| 9 |
|
| 10 |
# Debug: Check environment variables
|
| 11 |
-
logger.info(f"[CONFIG] FACEBOOK_APP_SECRET from env: {os.getenv('FACEBOOK_APP_SECRET', 'NOT_SET')}")
|
| 12 |
-
logger.info(f"[CONFIG] FACEBOOK_VERIFY_TOKEN from env: {os.getenv('FACEBOOK_VERIFY_TOKEN', 'NOT_SET')}")
|
| 13 |
-
logger.info(f"[CONFIG] SUPABASE_URL from env: {os.getenv('SUPABASE_URL', 'NOT_SET')}")
|
| 14 |
|
| 15 |
class Settings(BaseSettings):
|
| 16 |
"""
|
|
@@ -35,7 +35,7 @@ class Settings(BaseSettings):
|
|
| 35 |
port: int = int(os.getenv("PORT", "8000")) or 8000
|
| 36 |
|
| 37 |
# Logging Configuration
|
| 38 |
-
log_level: str = os.getenv("LOG_LEVEL", "
|
| 39 |
|
| 40 |
# Gemini Configuration
|
| 41 |
# Hỗ trợ nhiều API key và model cho Gemini
|
|
|
|
| 8 |
load_dotenv()
|
| 9 |
|
| 10 |
# Debug: Check environment variables
|
| 11 |
+
logger.info(f"[CONFIG] FACEBOOK_APP_SECRET from env: {os.getenv('FACEBOOK_APP_SECRET', 'NOT_SET')[5:]}...")
|
| 12 |
+
logger.info(f"[CONFIG] FACEBOOK_VERIFY_TOKEN from env: {os.getenv('FACEBOOK_VERIFY_TOKEN', 'NOT_SET')[5:]}...")
|
| 13 |
+
logger.info(f"[CONFIG] SUPABASE_URL from env: {os.getenv('SUPABASE_URL', 'NOT_SET')[5:]}...")
|
| 14 |
|
| 15 |
class Settings(BaseSettings):
|
| 16 |
"""
|
|
|
|
| 35 |
port: int = int(os.getenv("PORT", "8000")) or 8000
|
| 36 |
|
| 37 |
# Logging Configuration
|
| 38 |
+
log_level: str = os.getenv("LOG_LEVEL", "DEBUG") or "DEBUG"
|
| 39 |
|
| 40 |
# Gemini Configuration
|
| 41 |
# Hỗ trợ nhiều API key và model cho Gemini
|
app/facebook.py
CHANGED
|
@@ -69,11 +69,13 @@ class FacebookClient:
|
|
| 69 |
recipient_id = recipient_id or self.sender_id
|
| 70 |
if not page_access_token or not recipient_id:
|
| 71 |
raise ValueError("FacebookClient: page_access_token and recipient_id must not be None when sending a message.")
|
| 72 |
-
|
|
|
|
|
|
|
| 73 |
url = f"https://graph.facebook.com/v18.0/me/messages?access_token={page_access_token}"
|
| 74 |
payload = {
|
| 75 |
"recipient": {"id": recipient_id},
|
| 76 |
-
"message": {"text":
|
| 77 |
}
|
| 78 |
try:
|
| 79 |
response = await self._client.post(url, json=payload)
|
|
|
|
| 69 |
recipient_id = recipient_id or self.sender_id
|
| 70 |
if not page_access_token or not recipient_id:
|
| 71 |
raise ValueError("FacebookClient: page_access_token and recipient_id must not be None when sending a message.")
|
| 72 |
+
# Replace all occurrences of '**' with '*' before sending
|
| 73 |
+
response_to_send = message.replace('**', '*') if isinstance(message, str) else message
|
| 74 |
+
logger.info(f"Đang gửi tin nhắn đến Facebook Messenger....\n\t{response_to_send}")
|
| 75 |
url = f"https://graph.facebook.com/v18.0/me/messages?access_token={page_access_token}"
|
| 76 |
payload = {
|
| 77 |
"recipient": {"id": recipient_id},
|
| 78 |
+
"message": {"text": response_to_send} # Sử dụng response_to_send đã được xử lý
|
| 79 |
}
|
| 80 |
try:
|
| 81 |
response = await self._client.post(url, json=payload)
|