Spaces:
Build error
Build error
Commit
·
c3cb991
1
Parent(s):
db6bff5
Add reply function
Browse files- app/services/message.py +22 -0
app/services/message.py
CHANGED
@@ -2,9 +2,17 @@ import os
|
|
2 |
import requests
|
3 |
from fastapi.exceptions import HTTPException
|
4 |
from dotenv import load_dotenv
|
|
|
5 |
import datetime
|
|
|
6 |
load_dotenv()
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
# Define the WhatsApp API URL
|
9 |
WHATSAPP_API_URL = os.environ.get("WHATSAPP_API_URL")
|
10 |
|
@@ -45,3 +53,17 @@ async def generate_reply(sender: str, content: str, timestamp: str) -> str:
|
|
45 |
return f"Hello {sender}, I hope you're having a great day!"
|
46 |
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import requests
|
3 |
from fastapi.exceptions import HTTPException
|
4 |
from dotenv import load_dotenv
|
5 |
+
from typing import Dict, Any
|
6 |
import datetime
|
7 |
+
import logging
|
8 |
load_dotenv()
|
9 |
|
10 |
+
logging.basicConfig(
|
11 |
+
level=logging.INFO,
|
12 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
13 |
+
)
|
14 |
+
logger = logging.getLogger(__name__)
|
15 |
+
|
16 |
# Define the WhatsApp API URL
|
17 |
WHATSAPP_API_URL = os.environ.get("WHATSAPP_API_URL")
|
18 |
|
|
|
53 |
return f"Hello {sender}, I hope you're having a great day!"
|
54 |
|
55 |
|
56 |
+
async def process_message_with_retry(
|
57 |
+
sender_id: str,
|
58 |
+
content: str,
|
59 |
+
timestamp: int
|
60 |
+
) -> Dict[str, Any]:
|
61 |
+
"""Process message with retry logic"""
|
62 |
+
try:
|
63 |
+
generated_reply = await generate_reply(sender_id, content, timestamp)
|
64 |
+
await send_reply(sender_id, generated_reply)
|
65 |
+
return {"status": "success", "reply": generated_reply}
|
66 |
+
except Exception as e:
|
67 |
+
logger.error(f"Error processing message: {str(e)}", exc_info=True)
|
68 |
+
raise
|
69 |
+
|