Skip to content

Commit d78a6d4

Browse files
authored
Merge pull request #28 from green-api/SW-2934
SW-2934
2 parents 49239b6 + 3b5ea88 commit d78a6d4

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .bot import Bot, GreenAPI, GreenAPIBot, GreenAPIError
1+
from .bot import Bot, GreenAPI, GreenAPIBot, GreenAPIError, GreenAPIBotError
22
from .manager.handler import Notification
33
from .manager.state import BaseStates
44

@@ -7,6 +7,7 @@
77
"GreenAPI",
88
"GreenAPIBot",
99
"GreenAPIError",
10+
"GreenAPIBotError",
1011
"Notification",
1112
"BaseStates"
1213
]

whatsapp_chatbot_python/bot.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import time
23
from typing import NoReturn, Optional
34

45
from whatsapp_api_client_python.API import GreenAPI, GreenAPIError
@@ -78,6 +79,14 @@ def run_forever(self) -> Optional[NoReturn]:
7879
self.api.receiving.deleteNotification(response["receiptId"])
7980
except KeyboardInterrupt:
8081
break
82+
except Exception as error:
83+
if self.raise_errors:
84+
raise GreenAPIBotError(error)
85+
self.logger.log(logging.ERROR, error)
86+
87+
time.sleep(5.0)
88+
89+
continue
8190

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

@@ -158,4 +167,14 @@ class GreenAPIBot(Bot):
158167
pass
159168

160169

161-
__all__ = ["Bot", "GreenAPI", "GreenAPIBot", "GreenAPIError"]
170+
class GreenAPIBotError(Exception):
171+
pass
172+
173+
174+
__all__ = [
175+
"Bot",
176+
"GreenAPI",
177+
"GreenAPIBot",
178+
"GreenAPIError",
179+
"GreenAPIBotError"
180+
]

0 commit comments

Comments
 (0)