Skip to content

How to process incoming notifications#

Installation#

pip install telegram-api-client-python

Import#

from telegram_api_client_python import API

Example#

How to initialize an object#

greenAPI = API.GreenAPI(ID_INSTANCE, API_TOKEN_INSTANCE)

Receiving incoming messages through the HTTP API#

The general concept of receiving data in GREEN-API is described here. To start receiving messages through the HTTP API, you need to execute the library method:

A synchronous example:

greenAPI.webhooks.startReceivingNotifications(onEvent)

An asynchronous example:

try:
    await greenAPI.webhooks.startReceivingNotificationsAsync(handler)
except Exception as e:
    print(e)

onEvent - your method, which must contain the parameters:

Parameter Description
typeWebhook the type of the received message (a string)
body the message body (json)

The types and formats of the message bodies are here

This method will be called when an incoming message is received. Then you process the messages according to the business logic of your system.

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