Telegram bot: auto parts search

Telegram Bot API | PHP 7 | Object-Oriented Programming | Chatbots | SQLite | MySQL | Linux

Project Challenge

Create a Telegram bot that will allow us in a convenient and easy way to search for auto parts by a part number. The interface of communication with the bot should be as simple as possible.

The task is complicated by the fact that each automotive brand produces its own parts, the numbers of which coincide with the part numbers of other brands. It is necessary to implement a clarifying question from the side of the bot to find out what brand of car the visitor needs.

In addition, it is necessary to implement the choice of the price category of parts (wholesale or retail). Additional requirement: we need to implement periodic advertising of the project’s Internet resources and connect an analytics system to track user activity.

The database stores more than 1 million parts.

Project Solution

As a basis for the solution, I took the PHP-based Everhard/Telegram-Bot-API library, which is a high-quality OOP wrapper for the Telegram Bot API.

Since interactivity when communicating with the bot meant preserving the state, it was necessary to implement session storage. I did it using SQLite to minimize the number of dependent services. As the primary key of the session table, I took the user ID in Telegram.

To interact with the project database, a class was written that encapsulates the logic of interacting with MySQL through a PDO extension.

Since the transport for the Telegram Bot API should be through an SSL connection, I chose the free solution from Cloudflare, which allows us to implement encryption without the need to install a certificate on a server.

Involved skills

Telegram Bot API
PHP
Object Oriented Programming
SQLite
MySQL
Linux