1. Go to this page and download the library: Download prog-time/max-php-sdk 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/ */
prog-time / max-php-sdk example snippets
use MaxBotApi\MaxClient;
use MaxBotApi\Config;
$client = new MaxClient(new Config('your-bot-token'));
$client->messages->send(text: 'Hello!', chatId: 123456789);
$result = $client->uploads->getUploadUrl(Uploads::TYPE_IMAGE);
// $result->url — upload the file here with your own HTTP client
// $result->token — for video/audio: use this as the attachment token
use MaxBotApi\Webhook;
$data = Webhook::parse();
$update = \MaxBotApi\DTO\Update::fromArray($data);
switch ($update->updateType) {
case 'message_created':
$message = $update->payload['message'];
break;
case 'bot_started':
$user = $update->payload['user'];
break;
case 'message_callback':
$callback = $update->payload['callback'];
break;
}
use MaxBotApi\Exceptions\RateLimitException;
use MaxBotApi\Exceptions\ApiException;
use MaxBotApi\Exceptions\NetworkException;
try {
$client->messages->send(text: 'Hello!', chatId: 123456789);
} catch (RateLimitException $e) {
// HTTP 429 — retry after the specified delay
sleep($e->retryAfter ?? 60);
} catch (ApiException $e) {
// HTTP 4xx / 5xx — API returned an error
echo $e->getMessage();
echo $e->getCode(); // HTTP status code
} catch (NetworkException $e) {
// Connection failure, timeout, DNS error
echo $e->getMessage();
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.