Skip to content

Commit 5820fb1

Browse files
committed
Added more validations
1 parent 498f299 commit 5820fb1

1 file changed

Lines changed: 22 additions & 12 deletions

File tree

whatsapp_chatbot_python/bot.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(
1818
if not settings:
1919
self._update_settings()
2020
else:
21-
self.api.account.setSettings(settings)
21+
self.__validate_response(self.api.account.setSettings(settings))
2222

2323
if delete_notifications_at_startup:
2424
self._delete_notifications_at_startup()
@@ -38,14 +38,18 @@ def run_forever(self) -> Optional[NoReturn]:
3838

3939
self.router.route_event(response["body"])
4040

41-
self.api.receiving.deleteNotification(response["receiptId"])
41+
self.__validate_response(
42+
self.api.receiving.deleteNotification(
43+
response["receiptId"]
44+
)
45+
)
4246
except KeyboardInterrupt:
4347
break
4448

4549
def _update_settings(self) -> Optional[NoReturn]:
4650
settings = self.api.account.getSettings()
47-
if settings.error:
48-
raise GreenAPIError(settings.error)
51+
52+
self.__validate_response(settings)
4953

5054
response = settings.data
5155

@@ -57,22 +61,28 @@ def _update_settings(self) -> Optional[NoReturn]:
5761
and outgoing_message_webhook == "no"
5862
and outgoing_api_message_webhook == "no"
5963
):
60-
self.api.account.setSettings({
61-
"incomingWebhook": "yes",
62-
"outgoingMessageWebhook": "yes",
63-
"outgoingAPIMessageWebhook": "yes"
64-
})
64+
self.__validate_response(
65+
self.api.account.setSettings({
66+
"incomingWebhook": "yes",
67+
"outgoingMessageWebhook": "yes",
68+
"outgoingAPIMessageWebhook": "yes"
69+
})
70+
)
6571

6672
def _delete_notifications_at_startup(self) -> Optional[NoReturn]:
6773
while True:
6874
response = self.api.receiving.receiveNotification()
69-
if response.error:
70-
raise GreenAPIError(response.error)
75+
76+
self.__validate_response(response)
7177

7278
if not response.data:
7379
break
7480

75-
self.api.receiving.deleteNotification(response.data["receiptId"])
81+
self.__validate_response(
82+
self.api.receiving.deleteNotification(
83+
response.data["receiptId"]
84+
)
85+
)
7686

7787
@staticmethod
7888
def __validate_response(response: Response) -> Optional[NoReturn]:

0 commit comments

Comments
 (0)