Skip to content

Commit 1a00a73

Browse files
authored
Merge pull request #15 from green-api/dev
Added parameters for the bot
2 parents d91ef10 + af2b5be commit 1a00a73

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

tests/test_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def handler(_):
4848
def create_bot(self, mock__update_settings: MagicMock) -> GreenAPIBot:
4949
mock__update_settings.return_value = None
5050

51-
return GreenAPIBot("", "")
51+
return GreenAPIBot("", "", delete_notifications_at_startup=False)
5252

5353

5454
if __name__ == '__main__':

whatsapp_chatbot_python/bot.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,22 @@
66

77

88
class Bot:
9-
def __init__(self, id_instance: str, api_token_instance: str):
9+
def __init__(
10+
self,
11+
id_instance: str,
12+
api_token_instance: str,
13+
settings: Optional[dict] = None,
14+
delete_notifications_at_startup: bool = True
15+
):
1016
self.api = GreenAPI(id_instance, api_token_instance)
1117

12-
self._update_settings()
18+
if not settings:
19+
self._update_settings()
20+
else:
21+
self.api.account.setSettings(settings)
22+
23+
if delete_notifications_at_startup:
24+
self._delete_notifications_at_startup()
1325

1426
self.router = Router(self.api)
1527

@@ -51,6 +63,17 @@ def _update_settings(self) -> Optional[NoReturn]:
5163
"outgoingAPIMessageWebhook": "yes"
5264
})
5365

66+
def _delete_notifications_at_startup(self) -> Optional[NoReturn]:
67+
while True:
68+
response = self.api.receiving.receiveNotification()
69+
if response.error:
70+
raise GreenAPIError(response.error)
71+
72+
if not response.data:
73+
break
74+
75+
self.api.receiving.deleteNotification(response.data["receiptId"])
76+
5477

5578
class GreenAPI(GreenApi):
5679
pass

0 commit comments

Comments
 (0)