How to receive other notifications and process the notification body#
Installation#
python -m pip install telegram-chatbot-python
Import#
from telegram_chatbot_python import GreenAPIBot, Notification
Examples#
How to initialize an object#
bot = GreenAPIBot(
"4100000000", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345"
)
How to receive other notifications and process the notification body#
You can receive not only incoming messages, but also outgoing ones. You can also receive the status of a sent message.
- To receive outgoing messages, you need to use the
bot.router.outgoing_messageobject; - To receive outgoing API messages, you need to use the
bot.router.outgoing_api_messageobject; - To receive the status of a sent message, you need to use the
bot.router.outgoing_message_statusobject.
The notification body is in notification.event. In this example we print the body of a new notification to the console.
Link to the example: event.py.
@bot.router.message()
def message_handler(notification: Notification) -> None:
print(notification.event)
bot.run_forever()
Running the application#
python event.py
The list of examples#
| Description | Link to the example |
|---|---|
| How to start receiving messages and replying to them | base.py |
| How to receive other notifications and process the notification body | event.py |
| How to filter incoming messages | filters.py |
| A bot example | full.py |