ABC 2026
<aside> 🚨 DISCLAIMER: This material has been produced using various openly available online resources to enhance its quality and comprehensiveness. In creating this document, we have attempted to acknowledge the original authors and primary contributors of the sourced materials. However, due to the extensive range of resources consulted, there may be instances where some contributors should be explicitly mentioned. Should there be any concerns or complaints regarding the attribution or content of this material, please do not hesitate to contact [email protected] for resolution and clarification.
</aside>
In this Lab, you’ll learn how to provide access to sensor data by creating and deploying a Telegram bot, enabling seamless interaction and real-time data retrieval through a user-friendly messaging platform.
The first Bot will be a simple example that returns a random number between 0 and 100.
The https://github.com/python-telegram-bot/python-telegram-bot package is necessary to program the Bot. You’ll have to install it using:
python3 -m pip install python-telegram-bot
To create your Bot, you need an Access Token. To generate an Access Token, you have to talk to the BotFather following a few simple steps as described here: https://core.telegram.org/bots/tutorial#obtain-your-bot-token
<aside> đź—Ł
You need a Telegram account and the Telegram app installed on your smartphone, or the web app at https://web.telegram.org/.
</aside>
The “dialogue” will be something like this:

Store the token somewhere !!!
Below is the code (file: tel_1.py) that returns a random number. The program defines three asynchronous functions (async def), which allow the bot to handle multiple user interactions efficiently without blocking execution:
start: Triggered by the /start command. It sends a welcome message to the user, confirming that the bot is active.getdata: Triggered by the /getdata command. It generates a random integer between 0 and 100 using Python’s built-in random module and sends it to the user.unknown: Handles any unrecognized text input that is not a valid command, guiding the user toward the available commands.The use of async and await enables non-blocking communication with the Telegram servers. This means the bot can process multiple messages concurrently, improving responsiveness and scalability, especially when handling many users simultaneously.