Develop PHP sending messages in telegram bot (Telegram bot)
The hosting hosts the database mysql-5.7.27
The database has a BOTUSERS table, it has a field User_id (user ID in Telegram)
Telegram bot is connected to the hosting
This bot is written in PHP and allows you to find out the readiness of the order by number.
When the bot works, a request is made to the database with a check of the number and status of the order. And in addition to verification, there is a record User_id (user ID in Telegram) in the BOTUSERS table
At the moment, the number of users is about 4000.
The bot uses the autoload library.php @generated by Composer https://www.php-fig.org/psr/psr-0/
TASK:
Create a PHP file (send.php), which will be launched by the hosting administrator manually.
The logic of the file:
- Connect to the database by accessing the config file.php
Contents of the config.php file:
- Make a request to the database in order to extract the User_id (user ID in Telegram) into the BOTUSERS table, a certain text message (or picture) is sent to the user, an entry in the log file about the success of the sending.
And then in the cycle, its going through all the users.
Consider that there are interval restrictions of Telegram on sending messages: up to 30 messages with an interval of 1 second.
If a pic .jpg is sent, it will lie at the root of the folder with the send file.php
If text .txt is sent, it will lie at the root of the folder with the send file.php
You can create 2 different files: one sends text, another picture (for example, send_pic.php and send_txt.php)
The log file reflects the user_id, time of dispatch, delivery / not delivered and other available data on the shipment.
25.01.2023 12:03