๐๐ป HiToAll
A tool for sending fast and managed messages to Telegram bot users
About
In some telegram bots programmed with php language, if there are many users of the bot, the bot will have trouble sending public messages to users and because the number of requests increases, it causes the timeout source to be sent and the message is not sent to all users. Using the simple HiToAll tool, this problem can be solved and messages can be managed in a timely manner.
Getting started
To use HiToAll, you need your bot database to use mysql. First you need to define your database information in an array:
include('hitoall.php');
define('API_KEY', ''); // Bot token
define('MYSQLI', [
'host'=> 'localhost',
'username'=> 'database_username',
'password'=> 'database_password',
'name'=> 'database_name'
]);
You then need to create a 1 minute cron job on the loop.php file. This cron job is used to manage posts per minute. You can use cron-job.org to add a cronjob, or enter the following command in the server's cronjob settings:
php -q /home/path/to/loop.php
Add to Queue
To create a new message in the send queue, just enter the sending method and information in the following format:
- Note: In the fields where you need to enter the user's chat id, enter the phrase
[*USER*]
. This phrase will be replaced when sending.
// Add a new message to the queue to send to all bot users
HiToAll('sendMessage',[
'chat_id'=>'[*USER*]',
'text'=>'Hello Everyone!'
], $api_key=API_KEY, $mysqli=MYSQLI);
Your message will be in the queue and finally after 1 minute sending to all members of the bot will begin. Messages will be sent to 50 members of your bot every minute.
Get sending Queue
When you add a send to the queue, the id value is also returned. You can use this code to receive a list of all active sends:
// Get a array of contents waiting to be sent
$list = HiToAll('list', $api_key=API_KEY, $mysqli=MYSQLI)['list'];
Get a send info from Queue
You can use this code to receive the basic information of a post from the queue :
// Get a send with ID '15978'
$id = 15978;
$info = HiToAll('get', ['id'=>$id], $api_key=API_KEY, $mysqli=MYSQLI);
$sends = $info['send']; // Number of sends so far
$method = $info['type']; // Get send method (example: sendMessage, ...)
Remove from sending Queue
To delete or cancel a post from the queue, you can use this code:
// Delete a send with ID '15978'
$id = 15978;
HiToAll('remove', ['id'=>$id], $api_key=API_KEY, $mysqli=MYSQLI);
Adjusting the user table
The table where the user list is located is user by default, but you can set this using the users_table argument:
HiToAll('list', $users_table='botusers', $api_key=API_KEY, $mysqli=MYSQLI);
Also, the structure in which users chat id is located is on id by default. If you want to configure this manually, you can use the chatid_structure argument:
HiToAll('list', $chatid_structure='userid', $api_key=API_KEY, $mysqli=MYSQLI);