whatsapp-chatbot-python 0.8.0__tar.gz → 0.9.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (20) hide show
  1. {whatsapp-chatbot-python-0.8.0 → whatsapp-chatbot-python-0.9.1}/PKG-INFO +15 -2
  2. {whatsapp-chatbot-python-0.8.0 → whatsapp-chatbot-python-0.9.1}/README.md +13 -0
  3. {whatsapp-chatbot-python-0.8.0 → whatsapp-chatbot-python-0.9.1}/setup.py +2 -2
  4. {whatsapp-chatbot-python-0.8.0 → whatsapp-chatbot-python-0.9.1}/whatsapp_chatbot_python/__init__.py +2 -1
  5. {whatsapp-chatbot-python-0.8.0 → whatsapp-chatbot-python-0.9.1}/whatsapp_chatbot_python/bot.py +21 -2
  6. {whatsapp-chatbot-python-0.8.0 → whatsapp-chatbot-python-0.9.1}/whatsapp_chatbot_python/filters.py +25 -5
  7. {whatsapp-chatbot-python-0.8.0 → whatsapp-chatbot-python-0.9.1}/whatsapp_chatbot_python/manager/handler.py +13 -0
  8. {whatsapp-chatbot-python-0.8.0 → whatsapp-chatbot-python-0.9.1}/whatsapp_chatbot_python/manager/observer.py +31 -1
  9. {whatsapp-chatbot-python-0.8.0 → whatsapp-chatbot-python-0.9.1}/whatsapp_chatbot_python/manager/router.py +10 -1
  10. {whatsapp-chatbot-python-0.8.0 → whatsapp-chatbot-python-0.9.1}/whatsapp_chatbot_python.egg-info/PKG-INFO +15 -2
  11. whatsapp-chatbot-python-0.9.1/whatsapp_chatbot_python.egg-info/requires.txt +1 -0
  12. whatsapp-chatbot-python-0.8.0/whatsapp_chatbot_python.egg-info/requires.txt +0 -1
  13. {whatsapp-chatbot-python-0.8.0 → whatsapp-chatbot-python-0.9.1}/LICENSE +0 -0
  14. {whatsapp-chatbot-python-0.8.0 → whatsapp-chatbot-python-0.9.1}/setup.cfg +0 -0
  15. {whatsapp-chatbot-python-0.8.0 → whatsapp-chatbot-python-0.9.1}/tests/test_manager.py +0 -0
  16. {whatsapp-chatbot-python-0.8.0 → whatsapp-chatbot-python-0.9.1}/whatsapp_chatbot_python/manager/__init__.py +0 -0
  17. {whatsapp-chatbot-python-0.8.0 → whatsapp-chatbot-python-0.9.1}/whatsapp_chatbot_python/manager/state.py +0 -0
  18. {whatsapp-chatbot-python-0.8.0 → whatsapp-chatbot-python-0.9.1}/whatsapp_chatbot_python.egg-info/SOURCES.txt +0 -0
  19. {whatsapp-chatbot-python-0.8.0 → whatsapp-chatbot-python-0.9.1}/whatsapp_chatbot_python.egg-info/dependency_links.txt +0 -0
  20. {whatsapp-chatbot-python-0.8.0 → whatsapp-chatbot-python-0.9.1}/whatsapp_chatbot_python.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: whatsapp-chatbot-python
3
- Version: 0.8.0
3
+ Version: 0.9.1
4
4
  Summary: This library helps you easily create a Python chatbot with WhatsApp API.
5
5
  Home-page: https://github.com/green-api/whatsapp-chatbot-python
6
6
  Author: GREEN API
@@ -30,7 +30,7 @@ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
30
30
  Requires-Python: >=3.7
31
31
  Description-Content-Type: text/markdown
32
32
  License-File: LICENSE
33
- Requires-Dist: whatsapp-api-client-python==0.0.44
33
+ Requires-Dist: whatsapp-api-client-python==0.0.45
34
34
 
35
35
  # whatsapp-chatbot-python
36
36
 
@@ -70,6 +70,19 @@ python -m pip install whatsapp-chatbot-python
70
70
  from whatsapp_chatbot_python import GreenAPIBot, Notification
71
71
  ```
72
72
 
73
+ ## Setup
74
+
75
+ Before launching the bot, you should enable incoming notifications in instance settings by using [SetSettings method](https://green-api.com/en/docs/api/account/SetSettings/).
76
+
77
+
78
+ ```json
79
+ {
80
+ "incomingWebhook": "yes",
81
+ "outgoingMessageWebhook": "yes",
82
+ "outgoingAPIMessageWebhook": "yes"
83
+ }
84
+ ```
85
+
73
86
  ## Examples
74
87
 
75
88
  ### How to initialize an object
@@ -36,6 +36,19 @@ python -m pip install whatsapp-chatbot-python
36
36
  from whatsapp_chatbot_python import GreenAPIBot, Notification
37
37
  ```
38
38
 
39
+ ## Setup
40
+
41
+ Before launching the bot, you should enable incoming notifications in instance settings by using [SetSettings method](https://green-api.com/en/docs/api/account/SetSettings/).
42
+
43
+
44
+ ```json
45
+ {
46
+ "incomingWebhook": "yes",
47
+ "outgoingMessageWebhook": "yes",
48
+ "outgoingAPIMessageWebhook": "yes"
49
+ }
50
+ ```
51
+
39
52
  ## Examples
40
53
 
41
54
  ### How to initialize an object
@@ -5,7 +5,7 @@ with open("README.md", encoding="UTF-8") as file:
5
5
 
6
6
  setup(
7
7
  name="whatsapp-chatbot-python",
8
- version="0.8.0",
8
+ version="0.9.1",
9
9
  description=(
10
10
  "This library helps you easily create"
11
11
  " a Python chatbot with WhatsApp API."
@@ -43,6 +43,6 @@ setup(
43
43
  "Creative Commons Attribution-NoDerivatives 4.0 International"
44
44
  " (CC BY-ND 4.0)"
45
45
  ),
46
- install_requires=["whatsapp-api-client-python==0.0.44"],
46
+ install_requires=["whatsapp-api-client-python==0.0.45"],
47
47
  python_requires=">=3.7"
48
48
  )
@@ -1,4 +1,4 @@
1
- from .bot import Bot, GreenAPI, GreenAPIBot, GreenAPIError
1
+ from .bot import Bot, GreenAPI, GreenAPIBot, GreenAPIError, GreenAPIBotError
2
2
  from .manager.handler import Notification
3
3
  from .manager.state import BaseStates
4
4
 
@@ -7,6 +7,7 @@ __all__ = [
7
7
  "GreenAPI",
8
8
  "GreenAPIBot",
9
9
  "GreenAPIError",
10
+ "GreenAPIBotError",
10
11
  "Notification",
11
12
  "BaseStates"
12
13
  ]
@@ -1,4 +1,5 @@
1
1
  import logging
2
+ import time
2
3
  from typing import NoReturn, Optional
3
4
 
4
5
  from whatsapp_api_client_python.API import GreenAPI, GreenAPIError
@@ -12,7 +13,7 @@ class Bot:
12
13
  id_instance: str,
13
14
  api_token_instance: str,
14
15
  debug_mode: bool = False,
15
- raise_errors: bool = True,
16
+ raise_errors: bool = False,
16
17
  host: Optional[str] = None,
17
18
  media: Optional[str] = None,
18
19
  bot_debug_mode: bool = False,
@@ -78,6 +79,14 @@ class Bot:
78
79
  self.api.receiving.deleteNotification(response["receiptId"])
79
80
  except KeyboardInterrupt:
80
81
  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
81
90
 
82
91
  self.api.session.headers["Connection"] = "close"
83
92
 
@@ -158,4 +167,14 @@ class GreenAPIBot(Bot):
158
167
  pass
159
168
 
160
169
 
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
+ ]
@@ -5,6 +5,8 @@ from typing import Dict, List, Optional, TYPE_CHECKING, Type, Union
5
5
  if TYPE_CHECKING:
6
6
  from .manager.handler import Notification
7
7
 
8
+ TEXT_TYPES = ["textMessage", "extendedTextMessage", "quotedMessage"]
9
+
8
10
 
9
11
  class AbstractFilter(ABC):
10
12
  @abstractmethod
@@ -132,6 +134,22 @@ class StateFilter(AbstractFilter):
132
134
  return False
133
135
 
134
136
 
137
+ class StanzaFilter(AbstractFilter):
138
+ def __init__(self, stanza: Optional[str]):
139
+ self.stanza = stanza
140
+
141
+ def check_event(self, notification: "Notification") -> bool:
142
+ message_data = notification.event["messageData"]
143
+
144
+ type_message = message_data["typeMessage"]
145
+ if type_message == "pollUpdateMessage":
146
+ stanza = message_data["pollMessageData"]["stanzaId"]
147
+ if stanza == self.stanza:
148
+ return True
149
+
150
+ return False
151
+
152
+
135
153
  filters: Dict[str, Type[AbstractFilter]] = {
136
154
  "from_chat": ChatIDFilter,
137
155
  "from_sender": SenderFilter,
@@ -139,12 +157,13 @@ filters: Dict[str, Type[AbstractFilter]] = {
139
157
  "text_message": TextMessageFilter,
140
158
  "regexp": RegExpFilter,
141
159
  "command": CommandFilter,
142
- "state": StateFilter
160
+ "state": StateFilter,
161
+ "stanza": StanzaFilter
143
162
  }
144
163
 
145
- TEXT_TYPES = ["textMessage", "extendedTextMessage", "quotedMessage"]
146
-
147
164
  __all__ = [
165
+ "TEXT_TYPES",
166
+
148
167
  "AbstractFilter",
149
168
  "ChatIDFilter",
150
169
  "SenderFilter",
@@ -153,6 +172,7 @@ __all__ = [
153
172
  "RegExpFilter",
154
173
  "CommandFilter",
155
174
  "StateFilter",
156
- "filters",
157
- "TEXT_TYPES"
175
+ "StanzaFilter",
176
+
177
+ "filters"
158
178
  ]
@@ -104,6 +104,19 @@ class Notification:
104
104
  chat, file, file_name, caption, quoted_message_id
105
105
  )
106
106
 
107
+ def answer_with_poll(
108
+ self,
109
+ message: str,
110
+ options: List[Dict[str, str]],
111
+ multiple_answers: Optional[bool] = None,
112
+ quoted_message_id: Optional[str] = None
113
+ ) -> Optional[Response]:
114
+ chat = self.get_chat()
115
+ if chat:
116
+ return self.api.sending.sendPoll(
117
+ chat, message, options, multiple_answers, quoted_message_id
118
+ )
119
+
107
120
 
108
121
  HandlerType = Callable[[Notification], Any]
109
122
 
@@ -89,4 +89,34 @@ class ButtonObserver(Observer):
89
89
  self.router.message.add_handler(handler, **filters)
90
90
 
91
91
 
92
- __all__ = ["AbstractObserver", "ButtonObserver", "Observer"]
92
+ class PollObserver(Observer):
93
+ def add_handler(self, handler: HandlerType, **filters: Any) -> None:
94
+ filters["type_message"] = "pollMessage"
95
+
96
+ self.router.message.add_handler(handler, **filters)
97
+
98
+
99
+ class PollUpdateObserver(Observer):
100
+ def add_handler(self, handler: HandlerType, **filters: Any) -> None:
101
+ filters["type_message"] = "pollUpdateMessage"
102
+
103
+ self.router.message.add_handler(handler, **filters)
104
+
105
+ def add_handler_with_stanza(
106
+ self, handler: HandlerType, stanza: str, **filters: Any
107
+ ) -> None:
108
+ filters.update({
109
+ "stanza": stanza,
110
+ "type_message": "pollUpdateMessage"
111
+ })
112
+
113
+ self.router.message.add_handler(handler, **filters)
114
+
115
+
116
+ __all__ = [
117
+ "AbstractObserver",
118
+ "ButtonObserver",
119
+ "Observer",
120
+ "PollObserver",
121
+ "PollUpdateObserver"
122
+ ]
@@ -2,7 +2,13 @@ import json
2
2
  import logging
3
3
  from typing import Dict, TYPE_CHECKING
4
4
 
5
- from .observer import AbstractObserver, ButtonObserver, Observer
5
+ from .observer import (
6
+ AbstractObserver,
7
+ ButtonObserver,
8
+ Observer,
9
+ PollObserver,
10
+ PollUpdateObserver
11
+ )
6
12
 
7
13
  if TYPE_CHECKING:
8
14
  from ..bot import GreenAPI
@@ -20,6 +26,9 @@ class Router:
20
26
 
21
27
  self.buttons: AbstractObserver = ButtonObserver(self)
22
28
 
29
+ self.poll_message: PollObserver = PollObserver(self)
30
+ self.poll_update_message: PollUpdateObserver = PollUpdateObserver(self)
31
+
23
32
  self.observers: Dict[str, AbstractObserver] = {
24
33
  "incomingMessageReceived": self.message,
25
34
  "outgoingMessageReceived": self.outgoing_message,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: whatsapp-chatbot-python
3
- Version: 0.8.0
3
+ Version: 0.9.1
4
4
  Summary: This library helps you easily create a Python chatbot with WhatsApp API.
5
5
  Home-page: https://github.com/green-api/whatsapp-chatbot-python
6
6
  Author: GREEN API
@@ -30,7 +30,7 @@ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
30
30
  Requires-Python: >=3.7
31
31
  Description-Content-Type: text/markdown
32
32
  License-File: LICENSE
33
- Requires-Dist: whatsapp-api-client-python==0.0.44
33
+ Requires-Dist: whatsapp-api-client-python==0.0.45
34
34
 
35
35
  # whatsapp-chatbot-python
36
36
 
@@ -70,6 +70,19 @@ python -m pip install whatsapp-chatbot-python
70
70
  from whatsapp_chatbot_python import GreenAPIBot, Notification
71
71
  ```
72
72
 
73
+ ## Setup
74
+
75
+ Before launching the bot, you should enable incoming notifications in instance settings by using [SetSettings method](https://green-api.com/en/docs/api/account/SetSettings/).
76
+
77
+
78
+ ```json
79
+ {
80
+ "incomingWebhook": "yes",
81
+ "outgoingMessageWebhook": "yes",
82
+ "outgoingAPIMessageWebhook": "yes"
83
+ }
84
+ ```
85
+
73
86
  ## Examples
74
87
 
75
88
  ### How to initialize an object
@@ -0,0 +1 @@
1
+ whatsapp-api-client-python==0.0.45
@@ -1 +0,0 @@
1
- whatsapp-api-client-python==0.0.44