File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
5454if __name__ == '__main__' :
Original file line number Diff line number Diff line change 66
77
88class 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
5578class GreenAPI (GreenApi ):
5679 pass
You can’t perform that action at this time.
0 commit comments