How to process incoming notifications#
Installation#
pip install whatsapp-api-client-python
Import#
from whatsapp_api_client_python import API
Examples#
-
Full example for synchronous version: receiveNotification.py
-
Full example of asynchronous version: receiveNotificationAsync.py
How to initialize an object#
greenAPI = API.GreenAPI(ID_INSTANCE, API_TOKEN_INSTANCE)
Receiving incoming messages by HTTP API#
The general concept of receiving data in the GREEN-API is described here To start receiving messages by the HTTP API, you need to execute the library method:
Synchronous version:
greenAPI.webhooks.startReceivingNotifications(onEvent)
Asynchronous version:
try:
await greenAPI.webhooks.startReceivingNotificationsAsync(handler)
except Exception as e:
print(e)
onEvent - your method which should contain parameters:
| Parameter | Description |
|---|---|
| typewebhook | received message type (string) |
| body | message body (json) |
Notification body types and formats can be found here
This method will be called when an incoming notification is received. Next, process notifications according to the business logic of your system.
Examples list#
| Description | Module |
|---|---|
| Example of sending text | sendTextMessage.py |
| Example of sending text asynchronously | sendMessageAsync.py |
| Example of sending a picture by URL | sendPictureByLink.py |
| Example of sending a file by URL asynchronously | sendFileByUrlAsync.py |
| Example of sending a picture by uploading from the disk | sendPictureByUpload.py |
| Example of sending file by uploading from the disk asynchronously | sendFileByUploadAsync.py |
| Example of a group creation and sending a message to the group | createGroupAndSendMessage.py |
| Example of a group creation and sending a message to the group asynchronously | createGroupAndSendMessageAsync.py |
| Example of incoming webhooks receiving | receiveNotification.py |
| Example of incoming webhooks receiving asynchronously | receiveNotificationAsync.py |
| Example of sending a polling message | sendPoll.py |
| Example of sending a polling message asynchronously | sendPollAsync.py |