Python Webhook server library#
Preparing environment#
The Python 3 must be installed on the computer and be version 3.8 or more. It can be downloaded from the official website: python.org.
Library installation#
python3 -m pip install whatsapp-api-webhook-server-python-v2
Server startup#
To use in your solutions, simply import the GreenAPIWebhookServer class and init server object.
from whatsapp_api_webhook_server_python_v2 import GreenAPIWebhookServer
Server start:
from whatsapp_api_webhook_server_python_v2 import GreenAPIWebhookServer
def event_handler(webhook_type: str, webhook_data: dict):
# Write webhook handling logic here
...
handler = GreenAPIWebhookServer(
event_handler=event_handler, # Your event handler func (check examples in repo)
host="0.0.0.0", # Your host
port=8080, # Your port
webhook_auth_header=None, # Webhook auth header param (check API console)
)
if __name__ == "__main__":
handler.start()
The event_handler parameter is a handler function that should be created by the developer.
Method parameters:
Parameter | Description |
---|---|
webhook_type: str | type of incoming webhook |
webhook_data: dict | data of incoming webhook |
Please see example receive_all_with_counter.py.