Skip to content

How to start receiving and answering messages#



python -m pip install whatsapp-chatbot-python


from whatsapp_chatbot_python import GreenAPIBot, Notification


How to initialize an object#

bot = GreenAPIBot(
    "1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345"

How to start receiving and answering messages#

To start receiving messages, you must create a handler function with one parameter (notification). The notification parameter is the class where the notification object (event) and the functions to answer the message are stored. To send a text message in response to a notification, you need to call the notification.answer function and pass there the text of the message. You don't need to pass the chatId parameter because it is automatically taken from the notification.

Next, you need to add the handler function to the list of handlers. This can be done with the bot.router.message decorator as in the example or with the bot.router.message.add_handler function. The decorator must be called with brackets.

To start the bot, call the bot.run_forever function. You can stop the bot with the key combination Ctrl + C.

Link to example:

def message_handler(notification: Notification) -> None:


Running the application#


List of examples#

Description Link to example
How to start receiving and answering messages
How to receive other notifications and handle the notification body
How to filter incoming messages
How to handle buttons
Example of a bot
GREEN-API demo chatbot