Skip to content

Commit

Permalink
Merge pull request #28 from green-api/SW-2934
Browse files Browse the repository at this point in the history
SW-2934
  • Loading branch information
Amele9 committed Feb 5, 2024
2 parents 49239b6 + 3b5ea88 commit d78a6d4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion whatsapp_chatbot_python/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .bot import Bot, GreenAPI, GreenAPIBot, GreenAPIError
from .bot import Bot, GreenAPI, GreenAPIBot, GreenAPIError, GreenAPIBotError
from .manager.handler import Notification
from .manager.state import BaseStates

Expand All @@ -7,6 +7,7 @@
"GreenAPI",
"GreenAPIBot",
"GreenAPIError",
"GreenAPIBotError",
"Notification",
"BaseStates"
]
21 changes: 20 additions & 1 deletion whatsapp_chatbot_python/bot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import time
from typing import NoReturn, Optional

from whatsapp_api_client_python.API import GreenAPI, GreenAPIError
Expand Down Expand Up @@ -78,6 +79,14 @@ def run_forever(self) -> Optional[NoReturn]:
self.api.receiving.deleteNotification(response["receiptId"])
except KeyboardInterrupt:
break
except Exception as error:
if self.raise_errors:
raise GreenAPIBotError(error)
self.logger.log(logging.ERROR, error)

time.sleep(5.0)

continue

self.api.session.headers["Connection"] = "close"

Expand Down Expand Up @@ -158,4 +167,14 @@ class GreenAPIBot(Bot):
pass


__all__ = ["Bot", "GreenAPI", "GreenAPIBot", "GreenAPIError"]
class GreenAPIBotError(Exception):
pass


__all__ = [
"Bot",
"GreenAPI",
"GreenAPIBot",
"GreenAPIError",
"GreenAPIBotError"
]

0 comments on commit d78a6d4

Please sign in to comment.