How to create a group and send a message to it#
Installation#
python -m pip install whatsapp-api-client-python
Import#
from whatsapp_api_client_python import API
Examples#
-
Full example for synchronous version: createGroupAndSendMessage.py
-
Full example for asynchronous version: createGroupAndSendMessageAsync.py
How to initialize an object#
greenAPI = API.GreenAPI(ID_INSTANCE, API_TOKEN_INSTANCE)
How to create a group and send a message to it#
IMPORTANT
If one tries to create a group with a non-existent number, WhatsApp may block the sender's number. The number in the example is non-existent.
Synchronous version:
create_group_response = greenAPI.groups.createGroup(
"Group Name", ["79876543210@c.us", "11001234568@c.us"]
)
if create_group_response.code == 200:
send_message_response = greenAPI.sending.sendMessage(
create_group_response.data["chatId"], "Message text"
)
Asynchronous version:
create_group_response = await greenAPI.groups.createGroupAsync(
"SDK Python", ["79876543210@c.us", "11001234568@c.us"]
)
if create_group_response.code == 200:
send_message_response = await greenAPI.sending.sendMessageAsync(
create_group_response.data["chatId"], "Message text"
)
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 |