From 9585046d07f488a8da002e22cb83b1028a0d5be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=98=E3=82=B2=E3=83=87=E3=82=A3=E3=82=B9=E3=83=BB?= =?UTF-8?q?=E3=82=B8=E3=83=A7=E3=82=B7=E3=83=A5=E3=82=A2?= Date: Tue, 17 Sep 2024 14:16:43 +0200 Subject: [PATCH 1/4] updated deprecated receiver --- reciever/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/reciever/main.py b/reciever/main.py index f5ef4e0..ad95740 100644 --- a/reciever/main.py +++ b/reciever/main.py @@ -46,8 +46,9 @@ def handler_data(data, conn: socket.socket, cursor: Cursor, connection: Connecti count = cursor.fetchone() if count is not None: count = count[0] - print(f"Deleting {count} records with phone {phone}") - cursor.execute('DELETE FROM "Recipient" WHERE "phone" = (%s)', (phone,)) + print(f"Unsubscribing {count} records with phone {phone}") + # Setting the 'isSubscribed' to False for all records with the given phone number + cursor.execute('UPDATE "Recipient" SET "isSubscribed" = FALSE WHERE "phone" = (%s)', (phone,)) connection.commit() insert_log(cursor, "INFO", f"Deleted {count} records with phone {phone}", "RECEIVER") conn.sendall(b"OK") From bca8a62f606b3676b089e7a3a06b97d88936b6a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=98=E3=82=B2=E3=83=87=E3=82=A3=E3=82=B9=E3=83=BB?= =?UTF-8?q?=E3=82=B8=E3=83=A7=E3=82=B7=E3=83=A5=E3=82=A2?= Date: Tue, 17 Sep 2024 14:16:52 +0200 Subject: [PATCH 2/4] ignored idea/ --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 47c9966..ba8230c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ handler/.env /**/__pycache__/ /**/dblib.py !/dblib/dblib.py + +.idea/ From 891d4bee220687cd8adaf4640628368114c225d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=98=E3=82=B2=E3=83=87=E3=82=A3=E3=82=B9=E3=83=BB?= =?UTF-8?q?=E3=82=B8=E3=83=A7=E3=82=B7=E3=83=A5=E3=82=A2?= Date: Tue, 17 Sep 2024 14:17:05 +0200 Subject: [PATCH 3/4] changed deletion to cancelling --- handler/groups_router.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/handler/groups_router.py b/handler/groups_router.py index 0349b6f..ac3b141 100644 --- a/handler/groups_router.py +++ b/handler/groups_router.py @@ -7,9 +7,16 @@ groupsrouter = APIRouter() cursor, connection = get_db_cursor_and_connection() - logger = Logger("HANDLER", cursor, "GROUPS_ROUTER") +stopMessages = ["stop", "stap", "stopp", "pauza"] + +def is_stop_message(message: str): + for stopMessage in stopMessages: + if stopMessage in message.lower(): + return True + return False + @groupsrouter.get("/", tags=["groups"]) async def get_groups(): cursor.execute('SELECT * FROM "Group"') @@ -43,7 +50,7 @@ async def get_group_details(id: int): @groupsrouter.post("/cancel", tags=["groups"]) -def delete_recipient_from_group(request: CancelRequest): +def cancel_recipient(request: CancelRequest): keys = request.dict().keys() if not request or not 'phone_number' in keys or not 'message' in keys: return {"message": "ERROR", "success": False} @@ -55,7 +62,7 @@ def delete_recipient_from_group(request: CancelRequest): return {"message": "ERROR", "success": False} - if not ("STOP" in message.upper() or "Stap" in message.upper() or "Stopp" in message.upper()): + if not is_stop_message(message): print(f"Received: {phone}, but no STOP message (or similar) found: {message}") logger.info(f"Received: {phone}, but no STOP message (or similar) found: {message}") return { "message": "NO_ACTION_REQUIRED", "success": True} @@ -66,9 +73,9 @@ def delete_recipient_from_group(request: CancelRequest): logger.info(f"Recipient with phone number {phone} not found") return {"message": "NO_ACTION_REQUIRED", "success": True} else: - cursor.execute('DELETE FROM "Recipient" WHERE "phone" = (%s)', (phone,)) + cursor.execute('UPDATE "Recipient" SET "isSubscribed" = FALSE WHERE "phone" = (%s)', (phone,)) connection.commit() - logger.info(f"Recipient with phone number {phone} deleted") + logger.info(f"Recipient with phone number {phone} cancelled") return {"message": "OK", "success": True} except InvalidTextRepresentation as e: print(e) @@ -76,5 +83,5 @@ def delete_recipient_from_group(request: CancelRequest): return {"message": "ERROR", "success": False} except Exception as e: print(e) - logger.error(f"Error deleting recipient: {phone}") + logger.error(f"Error cancelling recipient: {phone}") return {"message": "Error Occurred: " + str(e), "success": False} From fdc9ef08ea41b85b02f26fec155cba1c107ffe2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=98=E3=82=B2=E3=83=87=E3=82=A3=E3=82=B9=E3=83=BB?= =?UTF-8?q?=E3=82=B8=E3=83=A7=E3=82=B7=E3=83=A5=E3=82=A2?= Date: Tue, 17 Sep 2024 14:21:57 +0200 Subject: [PATCH 4/4] fix wording --- handler/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handler/main.py b/handler/main.py index 28c5a19..447d53c 100644 --- a/handler/main.py +++ b/handler/main.py @@ -58,7 +58,7 @@ * **Create users** (_not implemented_). * **Read users** (_not implemented_). """ -print(f"Starting FastAPI on port 8000 ({SELF_URL}), with base path: {BASE_PATH}") +print(f"Starting FastAPI on ({SELF_URL}), with base path: {BASE_PATH}") app = FastAPI( title="SMS Automation API", description=description,