Upload main.py
Browse files
main.py
CHANGED
|
@@ -12,20 +12,7 @@ PHONE_NUMBER_ID = os.getenv("PHONE_NUMBER_ID", "")
|
|
| 12 |
WHATSAPP_API_TOKEN = os.getenv("WHATSAPP_API_TOKEN", "")
|
| 13 |
RUMAS_API_URL = os.getenv("RUMAS_API_URL", "")
|
| 14 |
|
| 15 |
-
|
| 16 |
-
DEDUP_FILE = "processed_message_ids.txt"
|
| 17 |
-
def load_processed_ids():
|
| 18 |
-
try:
|
| 19 |
-
with open(DEDUP_FILE, "r") as f:
|
| 20 |
-
return set(line.strip() for line in f if line.strip())
|
| 21 |
-
except FileNotFoundError:
|
| 22 |
-
return set()
|
| 23 |
-
|
| 24 |
-
def save_processed_id(msg_id):
|
| 25 |
-
with open(DEDUP_FILE, "a") as f:
|
| 26 |
-
f.write(msg_id + "\n")
|
| 27 |
-
|
| 28 |
-
processed_message_ids = load_processed_ids()
|
| 29 |
|
| 30 |
async def forward_to_rumas(b64_str: str, wa_id: str):
|
| 31 |
"""Fire-and-forget call to RUMAS /api/process_id."""
|
|
@@ -139,7 +126,6 @@ async def receive_update(req: Request):
|
|
| 139 |
print(f"Duplicate message {msg_id}, skipping.")
|
| 140 |
return JSONResponse({"status": "duplicate", "id": msg_id})
|
| 141 |
processed_message_ids.add(msg_id)
|
| 142 |
-
save_processed_id(msg_id)
|
| 143 |
|
| 144 |
# IMAGE: if user sent an image, convert to Base64 preview
|
| 145 |
if msg["type"] == "image":
|
|
|
|
| 12 |
WHATSAPP_API_TOKEN = os.getenv("WHATSAPP_API_TOKEN", "")
|
| 13 |
RUMAS_API_URL = os.getenv("RUMAS_API_URL", "")
|
| 14 |
|
| 15 |
+
processed_message_ids = set()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
async def forward_to_rumas(b64_str: str, wa_id: str):
|
| 18 |
"""Fire-and-forget call to RUMAS /api/process_id."""
|
|
|
|
| 126 |
print(f"Duplicate message {msg_id}, skipping.")
|
| 127 |
return JSONResponse({"status": "duplicate", "id": msg_id})
|
| 128 |
processed_message_ids.add(msg_id)
|
|
|
|
| 129 |
|
| 130 |
# IMAGE: if user sent an image, convert to Base64 preview
|
| 131 |
if msg["type"] == "image":
|