1. Go to this page and download the library: Download alexsisukin/telegram-core library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Longman\TelegramBot\Entities\Update;
// For all update types currently implemented in this library:
// $allowed_updates = Update::getUpdateTypes();
// Define the list of allowed Update types manually:
$allowed_updates = [
Update::TYPE_MESSAGE,
Update::TYPE_CHANNEL_POST,
// etc.
];
// When setting the webhook.
$telegram->setWebhook($hook_url, ['allowed_updates' => $allowed_updates]);
// When handling the getUpdates method.
$telegram->handleGetUpdates(['allowed_updates' => $allowed_updates]);
$telegram->setUpdateFilter(function (Update $update, Telegram $telegram, &$reason = 'Update denied by update_filter') {
$user_id = $update->getMessage()->getFrom()->getId();
if ($user_id === 428) {
return true;
}
$reason = "Invalid user with ID {$user_id}";
return false;
});
// Add a folder that contains command files
$telegram->addCommandsPath('/path/to/command/files');
//$telegram->addCommandsPaths(['/path/to/command/files', '/another/path']);
// Add a command directly using the class name
$telegram->addCommandClass(MyCommand::class);
//$telegram->addCommandClasses([MyCommand::class, MyOtherCommand::class]);
// Google geocode/timezone API key for /date command
$telegram->setCommandConfig('date', [
'google_api_key' => 'your_google_api_key_here',
]);
// OpenWeatherMap API key for /weather command
$telegram->setCommandConfig('weather', [
'owm_api_key' => 'your_owm_api_key_here',
]);