@@ -99,7 +99,7 @@ To start the bot, call the `bot.run_forever` function. You can stop the bot with
9999
100100In this example, the bot will only answer the ` message ` message.
101101
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) .
103103
104104```
105105@bot.router.message(text_message="message")
@@ -123,7 +123,7 @@ body.
123123
124124In this example, the bot receives all incoming messages.
125125
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) .
127127
128128```
129129@bot.router.message()
@@ -206,7 +206,7 @@ command = ("help", "!/")
206206
207207In this example, the bot will send a photo in response to the ` rates ` command.
208208
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) .
210210
211211```
212212@bot.router.message(command="rates")
@@ -217,32 +217,48 @@ def message_handler(notification: Notification) -> None:
217217bot.run_forever()
218218```
219219
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
223221
224222To be notified when a button is pressed, you must use the ` bot.router.buttons ` object.
225223
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+
227226
228227```
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"
235238 },
236239 {
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"
239254 },
240255 {
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+ )
246262
247263bot.run_forever()
248264```
@@ -268,7 +284,7 @@ You also have the option to save the user's data in his state.
268284
269285The first argument is the sender ID. It can be found by calling ` notification.sender ` .
270286
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) .
272288
273289``` python
274290from 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:
400416- 2 or Show office address (the bot will send the office address as a map)
401417- 3 or Show available rates (the bot will send a picture of the rates)
402418- 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)
403421
404422To send a text message, you have to use the ` notification.answer ` method.
405423To send a location, you have to use the ` sending.sendLocation ` method from ` notification.api ` .
406424To 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.
407427
408428In this example, the bot only responds to commands from the list above.
409429
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) .
411431
412432``` python
413433from whatsapp_chatbot_python import GreenAPIBot, Notification
@@ -428,19 +448,19 @@ def message_handler(notification: Notification) -> None:
428448 " 1. Report a problem\n "
429449 " 2. Show office address\n "
430450 " 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 "
432454 " Choose a number and send to me."
433455 )
434456 )
435457
436-
437458@bot.router.message (text_message = [" 1" , " Report a problem" ])
438459def report_problem_handler (notification : Notification) -> None :
439460 notification.answer(
440461 " https://github.com/green-api/issues/issues/new" , link_preview = False
441462 )
442463
443-
444464@bot.router.message (text_message = [" 2" , " Show office address" ])
445465def show_office_address_handler (notification : Notification) -> None :
446466 chat = notification.chat
@@ -449,16 +469,50 @@ def show_office_address_handler(notification: Notification) -> None:
449469 chatId = chat, latitude = 55.7522200 , longitude = 37.6155600
450470 )
451471
452-
453472@bot.router.message (text_message = [" 3" , " Show available rates" ])
454473def show_available_rates_handler (notification : Notification) -> None :
455- notification.answer_with_file(" data/rates.png" )
474+ notification.answer_with_file(" examples/ data/rates.png" )
456475
457476
458477@bot.router.message (text_message = [" 4" , " Call a support operator" ])
459478def call_support_operator_handler (notification : Notification) -> None :
460479 notification.answer(" Good. A tech support operator will contact you soon." )
461480
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+ )
462516
463517bot.run_forever()
464518```
0 commit comments