whatsapp-chatbot-python 0.9.6__tar.gz → 0.9.8__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.9.6 → whatsapp_chatbot_python-0.9.8}/PKG-INFO +95 -30
  2. {whatsapp_chatbot_python-0.9.6 → whatsapp_chatbot_python-0.9.8}/README.md +81 -27
  3. {whatsapp_chatbot_python-0.9.6 → whatsapp_chatbot_python-0.9.8}/setup.py +2 -2
  4. {whatsapp_chatbot_python-0.9.6 → whatsapp_chatbot_python-0.9.8}/whatsapp_chatbot_python/manager/handler.py +36 -7
  5. {whatsapp_chatbot_python-0.9.6 → whatsapp_chatbot_python-0.9.8}/whatsapp_chatbot_python.egg-info/PKG-INFO +95 -30
  6. whatsapp_chatbot_python-0.9.8/whatsapp_chatbot_python.egg-info/requires.txt +1 -0
  7. whatsapp_chatbot_python-0.9.6/whatsapp_chatbot_python.egg-info/requires.txt +0 -1
  8. {whatsapp_chatbot_python-0.9.6 → whatsapp_chatbot_python-0.9.8}/LICENSE +0 -0
  9. {whatsapp_chatbot_python-0.9.6 → whatsapp_chatbot_python-0.9.8}/setup.cfg +0 -0
  10. {whatsapp_chatbot_python-0.9.6 → whatsapp_chatbot_python-0.9.8}/tests/test_manager.py +0 -0
  11. {whatsapp_chatbot_python-0.9.6 → whatsapp_chatbot_python-0.9.8}/whatsapp_chatbot_python/__init__.py +0 -0
  12. {whatsapp_chatbot_python-0.9.6 → whatsapp_chatbot_python-0.9.8}/whatsapp_chatbot_python/bot.py +0 -0
  13. {whatsapp_chatbot_python-0.9.6 → whatsapp_chatbot_python-0.9.8}/whatsapp_chatbot_python/filters.py +0 -0
  14. {whatsapp_chatbot_python-0.9.6 → whatsapp_chatbot_python-0.9.8}/whatsapp_chatbot_python/manager/__init__.py +0 -0
  15. {whatsapp_chatbot_python-0.9.6 → whatsapp_chatbot_python-0.9.8}/whatsapp_chatbot_python/manager/observer.py +0 -0
  16. {whatsapp_chatbot_python-0.9.6 → whatsapp_chatbot_python-0.9.8}/whatsapp_chatbot_python/manager/router.py +0 -0
  17. {whatsapp_chatbot_python-0.9.6 → whatsapp_chatbot_python-0.9.8}/whatsapp_chatbot_python/manager/state.py +0 -0
  18. {whatsapp_chatbot_python-0.9.6 → whatsapp_chatbot_python-0.9.8}/whatsapp_chatbot_python.egg-info/SOURCES.txt +0 -0
  19. {whatsapp_chatbot_python-0.9.6 → whatsapp_chatbot_python-0.9.8}/whatsapp_chatbot_python.egg-info/dependency_links.txt +0 -0
  20. {whatsapp_chatbot_python-0.9.6 → whatsapp_chatbot_python-0.9.8}/whatsapp_chatbot_python.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: whatsapp-chatbot-python
3
- Version: 0.9.6
3
+ Version: 0.9.8
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,18 @@ 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.49
33
+ Requires-Dist: whatsapp-api-client-python>=0.0.53
34
+ Dynamic: author
35
+ Dynamic: author-email
36
+ Dynamic: classifier
37
+ Dynamic: description
38
+ Dynamic: description-content-type
39
+ Dynamic: home-page
40
+ Dynamic: license
41
+ Dynamic: license-file
42
+ Dynamic: requires-dist
43
+ Dynamic: requires-python
44
+ Dynamic: summary
34
45
 
35
46
  # whatsapp-chatbot-python
36
47
 
@@ -133,7 +144,7 @@ To start the bot, call the `bot.run_forever` function. You can stop the bot with
133
144
 
134
145
  In this example, the bot will only answer the `message` message.
135
146
 
136
- Link to example: [base.py](https://github.com/green-api/whatsapp-chatbot-python/blob/master/examples/base.py).
147
+ Link to example: [base.py](./examples/base.py).
137
148
 
138
149
  ```
139
150
  @bot.router.message(text_message="message")
@@ -157,7 +168,7 @@ body.
157
168
 
158
169
  In this example, the bot receives all incoming messages.
159
170
 
160
- Link to example: [event.py](https://github.com/green-api/whatsapp-chatbot-python/blob/master/examples/event.py).
171
+ Link to example: [event.py](./examples/event.py).
161
172
 
162
173
  ```
163
174
  @bot.router.message()
@@ -240,7 +251,7 @@ command = ("help", "!/")
240
251
 
241
252
  In this example, the bot will send a photo in response to the `rates` command.
242
253
 
243
- Link to example: [filters.py](https://github.com/green-api/whatsapp-chatbot-python/blob/master/examples/filters.py).
254
+ Link to example: [filters.py](./examples/filters.py).
244
255
 
245
256
  ```
246
257
  @bot.router.message(command="rates")
@@ -251,32 +262,48 @@ def message_handler(notification: Notification) -> None:
251
262
  bot.run_forever()
252
263
  ```
253
264
 
254
- ### How to handle buttons (deprecated)
255
-
256
- The method is temporarily not working. When the method is called, a 403 error will be returned.
265
+ ### How to handle buttons
257
266
 
258
267
  To be notified when a button is pressed, you must use the `bot.router.buttons` object.
259
268
 
260
- Link to example: [buttons.py](https://github.com/green-api/whatsapp-chatbot-python/blob/master/examples/buttons.py).
269
+ Link to example: [interactive_buttons.py](./examples/interactive_buttons.py).
270
+
261
271
 
262
272
  ```
263
- @bot.router.buttons()
264
- def buttons_handler(notification: Notification) -> None:
265
- notification.answer_buttons("Choose a color", [
266
- {
267
- "buttonId": 1,
268
- "buttonText": "Red"
273
+ @bot.router.message()
274
+
275
+ def show_interactive_buttons_handler(notification: Notification) -> None:
276
+ notification.answer_with_interactive_buttons(
277
+ "This message contains interactive buttons",
278
+ [{
279
+ "type": "call",
280
+ "buttonId": "1",
281
+ "buttonText": "Call me",
282
+ "phoneNumber": "79123456789"
269
283
  },
270
284
  {
271
- "buttonId": 2,
272
- "buttonText": "Green"
285
+ "type": "url",
286
+ "buttonId": "2",
287
+ "buttonText": "Green-api",
288
+ "url": "https://green-api.com"
289
+ }],
290
+ "Hello!",
291
+ "Hope you like it!"
292
+ )
293
+
294
+ notification.answer_with_interactive_buttons_reply(
295
+ "This message contains interactive reply buttons",
296
+ [{
297
+ "buttonId": "1",
298
+ "buttonText": "First Button"
273
299
  },
274
300
  {
275
- "buttonId": 3,
276
- "buttonText": "Blue"
277
- }
278
- ])
279
-
301
+ "buttonId": "2",
302
+ "buttonText": "Second Button"
303
+ }],
304
+ "Hello!",
305
+ "Hope you like it!"
306
+ )
280
307
 
281
308
  bot.run_forever()
282
309
  ```
@@ -302,7 +329,7 @@ You also have the option to save the user's data in his state.
302
329
 
303
330
  The first argument is the sender ID. It can be found by calling `notification.sender`.
304
331
 
305
- Link to example: [states.py](https://github.com/green-api/whatsapp-chatbot-python/blob/master/examples/states.py).
332
+ Link to example: [states.py](./examples/states.py).
306
333
 
307
334
  ```python
308
335
  from whatsapp_chatbot_python import BaseStates, GreenAPIBot, Notification
@@ -434,14 +461,18 @@ As an example, a bot was created to support the GREEN API. Command list:
434
461
  - 2 or Show office address (the bot will send the office address as a map)
435
462
  - 3 or Show available rates (the bot will send a picture of the rates)
436
463
  - 4 or Call a support operator (the bot will send a text message)
464
+ - 5 or Show interactive buttons (the bot will send a message with interactive buttons)
465
+ - 6 or Show interactive reply buttons (the bot will send a message with interactive reply buttons)
437
466
 
438
467
  To send a text message, you have to use the `notification.answer` method.
439
468
  To send a location, you have to use the `sending.sendLocation` method from `notification.api`.
440
469
  To send a message with a file, you have to use the `notification.answer_with_file` method.
470
+ To send a message with interactive buttons, you have to use `notification.answer_with_interactive_buttons` method.
471
+ To send a message with interactive reply buttons, you have to use `notification.answer_with_interactive_buttons_reply` method.
441
472
 
442
473
  In this example, the bot only responds to commands from the list above.
443
474
 
444
- Link to example: [full.py](https://github.com/green-api/whatsapp-chatbot-python/blob/master/examples/full.py).
475
+ Link to example: [full.py](./examples/full.py).
445
476
 
446
477
  ```python
447
478
  from whatsapp_chatbot_python import GreenAPIBot, Notification
@@ -462,19 +493,19 @@ def message_handler(notification: Notification) -> None:
462
493
  "1. Report a problem\n"
463
494
  "2. Show office address\n"
464
495
  "3. Show available rates\n"
465
- "4. Call a support operator\n\n"
496
+ "4. Call a support operator\n"
497
+ "5. Show interactive buttons\n"
498
+ "6. Show interactive reply buttons\n\n"
466
499
  "Choose a number and send to me."
467
500
  )
468
501
  )
469
502
 
470
-
471
503
  @bot.router.message(text_message=["1", "Report a problem"])
472
504
  def report_problem_handler(notification: Notification) -> None:
473
505
  notification.answer(
474
506
  "https://github.com/green-api/issues/issues/new", link_preview=False
475
507
  )
476
508
 
477
-
478
509
  @bot.router.message(text_message=["2", "Show office address"])
479
510
  def show_office_address_handler(notification: Notification) -> None:
480
511
  chat = notification.chat
@@ -483,16 +514,50 @@ def show_office_address_handler(notification: Notification) -> None:
483
514
  chatId=chat, latitude=55.7522200, longitude=37.6155600
484
515
  )
485
516
 
486
-
487
517
  @bot.router.message(text_message=["3", "Show available rates"])
488
518
  def show_available_rates_handler(notification: Notification) -> None:
489
- notification.answer_with_file("data/rates.png")
519
+ notification.answer_with_file("examples/data/rates.png")
490
520
 
491
521
 
492
522
  @bot.router.message(text_message=["4", "Call a support operator"])
493
523
  def call_support_operator_handler(notification: Notification) -> None:
494
524
  notification.answer("Good. A tech support operator will contact you soon.")
495
525
 
526
+ @bot.router.message(text_message=["5", "Show interactive buttons"])
527
+ def show_interactive_buttons_handler(notification: Notification) -> None:
528
+ notification.answer_with_interactive_buttons(
529
+ "This message contains interactive buttons",
530
+ [{
531
+ "type": "call",
532
+ "buttonId": "1",
533
+ "buttonText": "Call me",
534
+ "phoneNumber": "79123456789"
535
+ },
536
+ {
537
+ "type": "url",
538
+ "buttonId": "2",
539
+ "buttonText": "Green-api",
540
+ "url": "https://green-api.com"
541
+ }],
542
+ "Hello!",
543
+ "Hope you like it!"
544
+ )
545
+
546
+ @bot.router.message(text_message=["6", "Show interactive reply buttons"])
547
+ def show_interactive_buttons_reply_handler(notification: Notification) -> None:
548
+ notification.answer_with_interactive_buttons_reply(
549
+ "This message contains interactive reply buttons",
550
+ [{
551
+ "buttonId": "1",
552
+ "buttonText": "First Button"
553
+ },
554
+ {
555
+ "buttonId": "2",
556
+ "buttonText": "Second Button"
557
+ }],
558
+ "Hello!",
559
+ "Hope you like it!"
560
+ )
496
561
 
497
562
  bot.run_forever()
498
563
  ```
@@ -99,7 +99,7 @@ To start the bot, call the `bot.run_forever` function. You can stop the bot with
99
99
 
100
100
  In this example, the bot will only answer the `message` message.
101
101
 
102
- Link to example: [base.py](https://github.com/green-api/whatsapp-chatbot-python/blob/master/examples/base.py).
102
+ Link to example: [base.py](./examples/base.py).
103
103
 
104
104
  ```
105
105
  @bot.router.message(text_message="message")
@@ -123,7 +123,7 @@ body.
123
123
 
124
124
  In this example, the bot receives all incoming messages.
125
125
 
126
- Link to example: [event.py](https://github.com/green-api/whatsapp-chatbot-python/blob/master/examples/event.py).
126
+ Link to example: [event.py](./examples/event.py).
127
127
 
128
128
  ```
129
129
  @bot.router.message()
@@ -206,7 +206,7 @@ command = ("help", "!/")
206
206
 
207
207
  In this example, the bot will send a photo in response to the `rates` command.
208
208
 
209
- Link to example: [filters.py](https://github.com/green-api/whatsapp-chatbot-python/blob/master/examples/filters.py).
209
+ Link to example: [filters.py](./examples/filters.py).
210
210
 
211
211
  ```
212
212
  @bot.router.message(command="rates")
@@ -217,32 +217,48 @@ def message_handler(notification: Notification) -> None:
217
217
  bot.run_forever()
218
218
  ```
219
219
 
220
- ### How to handle buttons (deprecated)
221
-
222
- The method is temporarily not working. When the method is called, a 403 error will be returned.
220
+ ### How to handle buttons
223
221
 
224
222
  To be notified when a button is pressed, you must use the `bot.router.buttons` object.
225
223
 
226
- Link to example: [buttons.py](https://github.com/green-api/whatsapp-chatbot-python/blob/master/examples/buttons.py).
224
+ Link to example: [interactive_buttons.py](./examples/interactive_buttons.py).
225
+
227
226
 
228
227
  ```
229
- @bot.router.buttons()
230
- def buttons_handler(notification: Notification) -> None:
231
- notification.answer_buttons("Choose a color", [
232
- {
233
- "buttonId": 1,
234
- "buttonText": "Red"
228
+ @bot.router.message()
229
+
230
+ def show_interactive_buttons_handler(notification: Notification) -> None:
231
+ notification.answer_with_interactive_buttons(
232
+ "This message contains interactive buttons",
233
+ [{
234
+ "type": "call",
235
+ "buttonId": "1",
236
+ "buttonText": "Call me",
237
+ "phoneNumber": "79123456789"
235
238
  },
236
239
  {
237
- "buttonId": 2,
238
- "buttonText": "Green"
240
+ "type": "url",
241
+ "buttonId": "2",
242
+ "buttonText": "Green-api",
243
+ "url": "https://green-api.com"
244
+ }],
245
+ "Hello!",
246
+ "Hope you like it!"
247
+ )
248
+
249
+ notification.answer_with_interactive_buttons_reply(
250
+ "This message contains interactive reply buttons",
251
+ [{
252
+ "buttonId": "1",
253
+ "buttonText": "First Button"
239
254
  },
240
255
  {
241
- "buttonId": 3,
242
- "buttonText": "Blue"
243
- }
244
- ])
245
-
256
+ "buttonId": "2",
257
+ "buttonText": "Second Button"
258
+ }],
259
+ "Hello!",
260
+ "Hope you like it!"
261
+ )
246
262
 
247
263
  bot.run_forever()
248
264
  ```
@@ -268,7 +284,7 @@ You also have the option to save the user's data in his state.
268
284
 
269
285
  The first argument is the sender ID. It can be found by calling `notification.sender`.
270
286
 
271
- Link to example: [states.py](https://github.com/green-api/whatsapp-chatbot-python/blob/master/examples/states.py).
287
+ Link to example: [states.py](./examples/states.py).
272
288
 
273
289
  ```python
274
290
  from whatsapp_chatbot_python import BaseStates, GreenAPIBot, Notification
@@ -400,14 +416,18 @@ As an example, a bot was created to support the GREEN API. Command list:
400
416
  - 2 or Show office address (the bot will send the office address as a map)
401
417
  - 3 or Show available rates (the bot will send a picture of the rates)
402
418
  - 4 or Call a support operator (the bot will send a text message)
419
+ - 5 or Show interactive buttons (the bot will send a message with interactive buttons)
420
+ - 6 or Show interactive reply buttons (the bot will send a message with interactive reply buttons)
403
421
 
404
422
  To send a text message, you have to use the `notification.answer` method.
405
423
  To send a location, you have to use the `sending.sendLocation` method from `notification.api`.
406
424
  To send a message with a file, you have to use the `notification.answer_with_file` method.
425
+ To send a message with interactive buttons, you have to use `notification.answer_with_interactive_buttons` method.
426
+ To send a message with interactive reply buttons, you have to use `notification.answer_with_interactive_buttons_reply` method.
407
427
 
408
428
  In this example, the bot only responds to commands from the list above.
409
429
 
410
- Link to example: [full.py](https://github.com/green-api/whatsapp-chatbot-python/blob/master/examples/full.py).
430
+ Link to example: [full.py](./examples/full.py).
411
431
 
412
432
  ```python
413
433
  from whatsapp_chatbot_python import GreenAPIBot, Notification
@@ -428,19 +448,19 @@ def message_handler(notification: Notification) -> None:
428
448
  "1. Report a problem\n"
429
449
  "2. Show office address\n"
430
450
  "3. Show available rates\n"
431
- "4. Call a support operator\n\n"
451
+ "4. Call a support operator\n"
452
+ "5. Show interactive buttons\n"
453
+ "6. Show interactive reply buttons\n\n"
432
454
  "Choose a number and send to me."
433
455
  )
434
456
  )
435
457
 
436
-
437
458
  @bot.router.message(text_message=["1", "Report a problem"])
438
459
  def report_problem_handler(notification: Notification) -> None:
439
460
  notification.answer(
440
461
  "https://github.com/green-api/issues/issues/new", link_preview=False
441
462
  )
442
463
 
443
-
444
464
  @bot.router.message(text_message=["2", "Show office address"])
445
465
  def show_office_address_handler(notification: Notification) -> None:
446
466
  chat = notification.chat
@@ -449,16 +469,50 @@ def show_office_address_handler(notification: Notification) -> None:
449
469
  chatId=chat, latitude=55.7522200, longitude=37.6155600
450
470
  )
451
471
 
452
-
453
472
  @bot.router.message(text_message=["3", "Show available rates"])
454
473
  def show_available_rates_handler(notification: Notification) -> None:
455
- notification.answer_with_file("data/rates.png")
474
+ notification.answer_with_file("examples/data/rates.png")
456
475
 
457
476
 
458
477
  @bot.router.message(text_message=["4", "Call a support operator"])
459
478
  def call_support_operator_handler(notification: Notification) -> None:
460
479
  notification.answer("Good. A tech support operator will contact you soon.")
461
480
 
481
+ @bot.router.message(text_message=["5", "Show interactive buttons"])
482
+ def show_interactive_buttons_handler(notification: Notification) -> None:
483
+ notification.answer_with_interactive_buttons(
484
+ "This message contains interactive buttons",
485
+ [{
486
+ "type": "call",
487
+ "buttonId": "1",
488
+ "buttonText": "Call me",
489
+ "phoneNumber": "79123456789"
490
+ },
491
+ {
492
+ "type": "url",
493
+ "buttonId": "2",
494
+ "buttonText": "Green-api",
495
+ "url": "https://green-api.com"
496
+ }],
497
+ "Hello!",
498
+ "Hope you like it!"
499
+ )
500
+
501
+ @bot.router.message(text_message=["6", "Show interactive reply buttons"])
502
+ def show_interactive_buttons_reply_handler(notification: Notification) -> None:
503
+ notification.answer_with_interactive_buttons_reply(
504
+ "This message contains interactive reply buttons",
505
+ [{
506
+ "buttonId": "1",
507
+ "buttonText": "First Button"
508
+ },
509
+ {
510
+ "buttonId": "2",
511
+ "buttonText": "Second Button"
512
+ }],
513
+ "Hello!",
514
+ "Hope you like it!"
515
+ )
462
516
 
463
517
  bot.run_forever()
464
518
  ```
@@ -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.9.6",
8
+ version="0.9.8",
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.49"],
46
+ install_requires=["whatsapp-api-client-python>=0.0.53"],
47
47
  python_requires=">=3.7"
48
48
  )
@@ -86,12 +86,13 @@ class Notification:
86
86
  message: str,
87
87
  quoted_message_id: Optional[str] = None,
88
88
  archive_chat: Optional[bool] = None,
89
- link_preview: Optional[bool] = None
89
+ link_preview: Optional[bool] = None,
90
+ typing_time: Optional[int] = None
90
91
  ) -> Optional[Response]:
91
92
  chat = self.get_chat()
92
93
  if chat:
93
94
  return self.api.sending.sendMessage(
94
- chat, message, quoted_message_id, archive_chat, link_preview
95
+ chat, message, quoted_message_id, archive_chat, link_preview, typing_time
95
96
  )
96
97
 
97
98
  def answer_buttons(
@@ -108,17 +109,45 @@ class Notification:
108
109
  chat, message, buttons, footer, quoted_message_id, archive_chat
109
110
  )
110
111
 
112
+ def answer_with_interactive_buttons(
113
+ self,
114
+ body: str,
115
+ buttons: List[Dict[str, Union[str, Dict[str, str]]]],
116
+ header: Optional[str] = None,
117
+ footer: Optional[str] = None
118
+ ) -> Optional[Response]:
119
+ chat = self.get_chat()
120
+ if chat:
121
+ return self.api.sending.sendInteractiveButtons(
122
+ chat, body, buttons, header, footer
123
+ )
124
+
125
+ def answer_with_interactive_buttons_reply(
126
+ self,
127
+ body: str,
128
+ buttons: List[Dict[str, str]],
129
+ header: Optional[str] = None,
130
+ footer: Optional[str] = None
131
+ ) -> Optional[Response]:
132
+ chat = self.get_chat()
133
+ if chat:
134
+ return self.api.sending.sendInteractiveButtonsReply(
135
+ chat, body, buttons, header, footer
136
+ )
137
+
111
138
  def answer_with_file(
112
139
  self,
113
140
  file: str,
114
141
  file_name: Optional[str] = None,
115
142
  caption: Optional[str] = None,
116
- quoted_message_id: Optional[str] = None
143
+ quoted_message_id: Optional[str] = None,
144
+ typing_time: Optional[int] = None,
145
+ typing_type: Optional[str] = None
117
146
  ) -> Optional[Response]:
118
147
  chat = self.get_chat()
119
148
  if chat:
120
149
  return self.api.sending.sendFileByUpload(
121
- chat, file, file_name, caption, quoted_message_id
150
+ chat, file, file_name, caption, quoted_message_id, typing_time, typing_type
122
151
  )
123
152
 
124
153
  def answer_with_poll(
@@ -126,15 +155,15 @@ class Notification:
126
155
  message: str,
127
156
  options: List[Dict[str, str]],
128
157
  multiple_answers: Optional[bool] = None,
129
- quoted_message_id: Optional[str] = None
158
+ quoted_message_id: Optional[str] = None,
159
+ typing_time: Optional[int] = None
130
160
  ) -> Optional[Response]:
131
161
  chat = self.get_chat()
132
162
  if chat:
133
163
  return self.api.sending.sendPoll(
134
- chat, message, options, multiple_answers, quoted_message_id
164
+ chat, message, options, multiple_answers, quoted_message_id, typing_time
135
165
  )
136
166
 
137
-
138
167
  HandlerType = Callable[[Notification], Any]
139
168
 
140
169
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: whatsapp-chatbot-python
3
- Version: 0.9.6
3
+ Version: 0.9.8
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,18 @@ 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.49
33
+ Requires-Dist: whatsapp-api-client-python>=0.0.53
34
+ Dynamic: author
35
+ Dynamic: author-email
36
+ Dynamic: classifier
37
+ Dynamic: description
38
+ Dynamic: description-content-type
39
+ Dynamic: home-page
40
+ Dynamic: license
41
+ Dynamic: license-file
42
+ Dynamic: requires-dist
43
+ Dynamic: requires-python
44
+ Dynamic: summary
34
45
 
35
46
  # whatsapp-chatbot-python
36
47
 
@@ -133,7 +144,7 @@ To start the bot, call the `bot.run_forever` function. You can stop the bot with
133
144
 
134
145
  In this example, the bot will only answer the `message` message.
135
146
 
136
- Link to example: [base.py](https://github.com/green-api/whatsapp-chatbot-python/blob/master/examples/base.py).
147
+ Link to example: [base.py](./examples/base.py).
137
148
 
138
149
  ```
139
150
  @bot.router.message(text_message="message")
@@ -157,7 +168,7 @@ body.
157
168
 
158
169
  In this example, the bot receives all incoming messages.
159
170
 
160
- Link to example: [event.py](https://github.com/green-api/whatsapp-chatbot-python/blob/master/examples/event.py).
171
+ Link to example: [event.py](./examples/event.py).
161
172
 
162
173
  ```
163
174
  @bot.router.message()
@@ -240,7 +251,7 @@ command = ("help", "!/")
240
251
 
241
252
  In this example, the bot will send a photo in response to the `rates` command.
242
253
 
243
- Link to example: [filters.py](https://github.com/green-api/whatsapp-chatbot-python/blob/master/examples/filters.py).
254
+ Link to example: [filters.py](./examples/filters.py).
244
255
 
245
256
  ```
246
257
  @bot.router.message(command="rates")
@@ -251,32 +262,48 @@ def message_handler(notification: Notification) -> None:
251
262
  bot.run_forever()
252
263
  ```
253
264
 
254
- ### How to handle buttons (deprecated)
255
-
256
- The method is temporarily not working. When the method is called, a 403 error will be returned.
265
+ ### How to handle buttons
257
266
 
258
267
  To be notified when a button is pressed, you must use the `bot.router.buttons` object.
259
268
 
260
- Link to example: [buttons.py](https://github.com/green-api/whatsapp-chatbot-python/blob/master/examples/buttons.py).
269
+ Link to example: [interactive_buttons.py](./examples/interactive_buttons.py).
270
+
261
271
 
262
272
  ```
263
- @bot.router.buttons()
264
- def buttons_handler(notification: Notification) -> None:
265
- notification.answer_buttons("Choose a color", [
266
- {
267
- "buttonId": 1,
268
- "buttonText": "Red"
273
+ @bot.router.message()
274
+
275
+ def show_interactive_buttons_handler(notification: Notification) -> None:
276
+ notification.answer_with_interactive_buttons(
277
+ "This message contains interactive buttons",
278
+ [{
279
+ "type": "call",
280
+ "buttonId": "1",
281
+ "buttonText": "Call me",
282
+ "phoneNumber": "79123456789"
269
283
  },
270
284
  {
271
- "buttonId": 2,
272
- "buttonText": "Green"
285
+ "type": "url",
286
+ "buttonId": "2",
287
+ "buttonText": "Green-api",
288
+ "url": "https://green-api.com"
289
+ }],
290
+ "Hello!",
291
+ "Hope you like it!"
292
+ )
293
+
294
+ notification.answer_with_interactive_buttons_reply(
295
+ "This message contains interactive reply buttons",
296
+ [{
297
+ "buttonId": "1",
298
+ "buttonText": "First Button"
273
299
  },
274
300
  {
275
- "buttonId": 3,
276
- "buttonText": "Blue"
277
- }
278
- ])
279
-
301
+ "buttonId": "2",
302
+ "buttonText": "Second Button"
303
+ }],
304
+ "Hello!",
305
+ "Hope you like it!"
306
+ )
280
307
 
281
308
  bot.run_forever()
282
309
  ```
@@ -302,7 +329,7 @@ You also have the option to save the user's data in his state.
302
329
 
303
330
  The first argument is the sender ID. It can be found by calling `notification.sender`.
304
331
 
305
- Link to example: [states.py](https://github.com/green-api/whatsapp-chatbot-python/blob/master/examples/states.py).
332
+ Link to example: [states.py](./examples/states.py).
306
333
 
307
334
  ```python
308
335
  from whatsapp_chatbot_python import BaseStates, GreenAPIBot, Notification
@@ -434,14 +461,18 @@ As an example, a bot was created to support the GREEN API. Command list:
434
461
  - 2 or Show office address (the bot will send the office address as a map)
435
462
  - 3 or Show available rates (the bot will send a picture of the rates)
436
463
  - 4 or Call a support operator (the bot will send a text message)
464
+ - 5 or Show interactive buttons (the bot will send a message with interactive buttons)
465
+ - 6 or Show interactive reply buttons (the bot will send a message with interactive reply buttons)
437
466
 
438
467
  To send a text message, you have to use the `notification.answer` method.
439
468
  To send a location, you have to use the `sending.sendLocation` method from `notification.api`.
440
469
  To send a message with a file, you have to use the `notification.answer_with_file` method.
470
+ To send a message with interactive buttons, you have to use `notification.answer_with_interactive_buttons` method.
471
+ To send a message with interactive reply buttons, you have to use `notification.answer_with_interactive_buttons_reply` method.
441
472
 
442
473
  In this example, the bot only responds to commands from the list above.
443
474
 
444
- Link to example: [full.py](https://github.com/green-api/whatsapp-chatbot-python/blob/master/examples/full.py).
475
+ Link to example: [full.py](./examples/full.py).
445
476
 
446
477
  ```python
447
478
  from whatsapp_chatbot_python import GreenAPIBot, Notification
@@ -462,19 +493,19 @@ def message_handler(notification: Notification) -> None:
462
493
  "1. Report a problem\n"
463
494
  "2. Show office address\n"
464
495
  "3. Show available rates\n"
465
- "4. Call a support operator\n\n"
496
+ "4. Call a support operator\n"
497
+ "5. Show interactive buttons\n"
498
+ "6. Show interactive reply buttons\n\n"
466
499
  "Choose a number and send to me."
467
500
  )
468
501
  )
469
502
 
470
-
471
503
  @bot.router.message(text_message=["1", "Report a problem"])
472
504
  def report_problem_handler(notification: Notification) -> None:
473
505
  notification.answer(
474
506
  "https://github.com/green-api/issues/issues/new", link_preview=False
475
507
  )
476
508
 
477
-
478
509
  @bot.router.message(text_message=["2", "Show office address"])
479
510
  def show_office_address_handler(notification: Notification) -> None:
480
511
  chat = notification.chat
@@ -483,16 +514,50 @@ def show_office_address_handler(notification: Notification) -> None:
483
514
  chatId=chat, latitude=55.7522200, longitude=37.6155600
484
515
  )
485
516
 
486
-
487
517
  @bot.router.message(text_message=["3", "Show available rates"])
488
518
  def show_available_rates_handler(notification: Notification) -> None:
489
- notification.answer_with_file("data/rates.png")
519
+ notification.answer_with_file("examples/data/rates.png")
490
520
 
491
521
 
492
522
  @bot.router.message(text_message=["4", "Call a support operator"])
493
523
  def call_support_operator_handler(notification: Notification) -> None:
494
524
  notification.answer("Good. A tech support operator will contact you soon.")
495
525
 
526
+ @bot.router.message(text_message=["5", "Show interactive buttons"])
527
+ def show_interactive_buttons_handler(notification: Notification) -> None:
528
+ notification.answer_with_interactive_buttons(
529
+ "This message contains interactive buttons",
530
+ [{
531
+ "type": "call",
532
+ "buttonId": "1",
533
+ "buttonText": "Call me",
534
+ "phoneNumber": "79123456789"
535
+ },
536
+ {
537
+ "type": "url",
538
+ "buttonId": "2",
539
+ "buttonText": "Green-api",
540
+ "url": "https://green-api.com"
541
+ }],
542
+ "Hello!",
543
+ "Hope you like it!"
544
+ )
545
+
546
+ @bot.router.message(text_message=["6", "Show interactive reply buttons"])
547
+ def show_interactive_buttons_reply_handler(notification: Notification) -> None:
548
+ notification.answer_with_interactive_buttons_reply(
549
+ "This message contains interactive reply buttons",
550
+ [{
551
+ "buttonId": "1",
552
+ "buttonText": "First Button"
553
+ },
554
+ {
555
+ "buttonId": "2",
556
+ "buttonText": "Second Button"
557
+ }],
558
+ "Hello!",
559
+ "Hope you like it!"
560
+ )
496
561
 
497
562
  bot.run_forever()
498
563
  ```
@@ -0,0 +1 @@
1
+ whatsapp-api-client-python>=0.0.53
@@ -1 +0,0 @@
1
- whatsapp-api-client-python>=0.0.49