From f3cffb3c334a5365a2552006b9275f3307c13b0e Mon Sep 17 00:00:00 2001 From: Yoandre Saavedra Gonzalez <2855358+yoandresaav@users.noreply.github.com> Date: Mon, 29 Jul 2024 10:09:26 -0600 Subject: [PATCH] restoring version control --- whatsapp/__init__.py | 48 +++++++++++++++++++++---------------------- whatsapp/constants.py | 2 +- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/whatsapp/__init__.py b/whatsapp/__init__.py index 9970d22..8feb01b 100644 --- a/whatsapp/__init__.py +++ b/whatsapp/__init__.py @@ -31,23 +31,23 @@ def __init__(self, token: str = "", phone_number_id: str = "", logger: bool = Tr logging.getLogger(__name__).addHandler(logging.NullHandler()) self.VERSION = VERSION - # if update_check is True: - # latest = str(requests.get( - # "https://pypi.org/pypi/whatsapp-python/json").json()["info"]["version"]) - # if self.VERSION != latest: - # try: - # version_int = int(self.VERSION.replace(".", "")) - # except: - # version_int = 0 - # latest_int = int(latest.replace(".", "")) - # # this is to avoid the case where the version is 1.0.10 and the latest is 1.0.2 (possible if user is using the github version) - # if version_int < latest_int: - # if version_int == 0: - # logging.critical( - # f"There was an error while checking for updates, please update the package manually or report the issue on GitHub.") - # else: - # logging.critical( - # f"Whatsapp-python is out of date. Please update to the latest version {latest}. READ THE CHANGELOG BEFORE UPDATING. NEW VERSIONS MAY BREAK YOUR CODE IF NOT PROPERLY UPDATED.") + if update_check is True: + latest = str(requests.get( + "https://pypi.org/pypi/whatsapp-python-cloud-api/json").json()["info"]["version"]) + if self.VERSION != latest: + try: + version_int = int(self.VERSION.replace(".", "")) + except: + version_int = 0 + latest_int = int(latest.replace(".", "")) + # this is to avoid the case where the version is 1.0.10 and the latest is 1.0.2 (possible if user is using the github version) + if version_int < latest_int: + if version_int == 0: + logging.critical( + f"There was an error while checking for updates, please update the package manually or report the issue on GitHub.") + else: + logging.critical( + f"Whatsapp-python is out of date. Please update to the latest version {latest}. READ THE CHANGELOG BEFORE UPDATING. NEW VERSIONS MAY BREAK YOUR CODE IF NOT PROPERLY UPDATED.") if token == "": logging.error("Token not provided") @@ -80,19 +80,19 @@ async def base(*args): # Verification handler has 1 argument: challenge (str | bool): str if verification is successful, False if not - async def verify_endpoint(self, query_params: dict): + def verify_endpoint(self, query_params: dict): if query_params.get("hub.verify_token") == self.verify_token: logging.debug("Webhook verified successfully") challenge = query_params.get("hub.challenge") self.verification_handler(challenge) self.other_handler(challenge) - return int(challenge) + return str(challenge) logging.error("Webhook Verification failed - token mismatch") - await self.verification_handler(False) - await self.other_handler(False) + self.verification_handler(False) + self.other_handler(False) return {"success": False} - async def hook(request: dict): + def hook(self, request: dict): try: # Handle Webhook Subscriptions data = request.get('data') @@ -107,8 +107,8 @@ async def hook(request: dict): new_message = self.is_message(data) if new_message: msg = Message(instance=self, data=data) - await self.message_handler(msg) - await self.other_handler(msg) + self.message_handler(msg) + self.other_handler(msg) return {"success": True} except Exception as e: logging.error(f"Error parsing message: {e}") diff --git a/whatsapp/constants.py b/whatsapp/constants.py index df75afb..c444503 100644 --- a/whatsapp/constants.py +++ b/whatsapp/constants.py @@ -1,4 +1,4 @@ # This file contains the constants used in the project. # The VERSION constant is used to store the version of the project - it's not only used in the __init__.py file, but also in the pyproject.toml file. -VERSION = "3.1.1" +VERSION = "3.1.2"