How to create a group and send a message to it#
Installation#
python -m pip install telegram-api-client-python
Import#
from telegram_api_client_python import API
Example#
- The full example of the synchronous method is available at: createGroupAndSendMessage.py
- The full example of the asynchronous method is available at: 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#
A synchronous example:
create_group_response = greenAPI.groups.createGroup(
"Group Name", ["79876543210@c.us"]
)
if create_group_response.code == 200:
send_message_response = greenAPI.sending.sendMessage(
create_group_response.data["chatId"], "Message text"
)
An asynchronous example:
create_group_response = await greenAPI.groups.createGroupAsync(
"Group Name", ["79876543210@c.us"]
)
if create_group_response.code == 200:
send_message_response = await greenAPI.sending.sendMessageAsync(
create_group_response.data["chatId"], "Message text"
)
The full list of examples#
| Description | Module |
|---|---|
| An example of sending text | sendtMessage.py |
| An example of sending an image by URL | sendFileByUrl.py |
| An example of sending an image by uploading it from disk | sendFileByUpload.py |
| An example of creating a group and sending a message to the group | createGroupAndSendMessage.py |
| An example of receiving incoming notifications | receiveNotification.py |