Telegram bot that shows traffic statistics

Telegram Bot API | PHP | Chatbots | Yandex.Metrica | SQLite | Linux

Project Challenge

My client asked me to create a simple Telegram bot that could show the statistics of his website traffic. He was collecting statistics using the Yandex.Metrica service. However, this project presented several challenges:

1. Session Management Improvement: The first challenge was to evaluate the current session management system and propose improvements or alternative solutions that can handle a larger number of concurrent users efficiently. Inefficient session handling could lead to data inconsistencies and degraded user experiences.

2. Security Audit: The second challenge involved conducting a security audit of the solution. Securing sensitive data and authentication mechanisms was paramount to protect user privacy and the integrity of the bot. Ensuring the bot token is kept secure was a critical aspect of this challenge.

Project Solution

To address these challenges, I opted for the following solutions:

1. Library Selection: As a basis for the solution, I selected the PHP-based Everhard/Telegram-Bot-API library. This high-quality object-oriented programming (OOP) wrapper for the Telegram Bot API provided a robust foundation for building the bot.

2. Session Management: To implement session management efficiently, I chose SQLite as the storage solution. This minimized the number of dependent services and allowed for quick access to user session data. User IDs from Telegram served as the primary keys in the session table.

3. Security Measures: To enhance security, I ensured that all communications with the Telegram Bot API were through an SSL connection. I leveraged the free SSL solution from Cloudflare, eliminating the need to install a certificate on the server. This step enhanced data encryption and overall system security.

Involved skills

Telegram Bot API
PHP
Yandex.Metrica API
Object Oriented Programming
SQLite
Linux