To use the getUpdates method for retrieving Telegram updates, create a PHP script (e.g., getUpdatesCLI.php) that initializes the Telegram object, enables MySQL for performance, and calls handleGetUpdates().
For best performance, use a MySQL database. If you cannot use a database, call $telegram->useGetUpdatesWithoutDatabase(); instead.
#!/usr/bin/env php
<?php
require __DIR__ . '/vendor/autoload.php';
$bot_api_key = 'your:bot_api_key';
$bot_username = 'username_bot';
$mysql_credentials = [
'host' => 'localhost',
'port' => 3306, // optional
'user' => 'dbuser',
'password' => 'dbpass',
'database' => 'dbname',
];
try {
// Create Telegram API object
$telegram = new Longman\TelegramBot\Telegram($bot_api_key, $bot_username);
// Enable MySQL
$telegram->enableMySql($mysql_credentials);
// Handle telegram getUpdates request
$telegram->handleGetUpdates();
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
// log telegram errors
// echo $e->getMessage();
}
Then, make the file executable and run it:
$ chmod +x getUpdatesCLI.php
$ ./getUpdatesCLI.php