Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ use BushlanovDev\MaxMessengerBot\Api;

$api = new Api('YOUR_BOT_API_TOKEN');

// Использовать свой сертификат
$api = new Api('YOUR_BOT_API_TOKEN', guzzleConfig: ['verify' => '/path/to/cert.crt']);

// Настроить прокси и таймауты
$api = new Api('YOUR_BOT_API_TOKEN', guzzleConfig: [
'timeout' => 60,
'proxy' => 'tcp://proxy:8080'
]);

// Загрузка файла
$fileAttachmentRequest = $api->uploadAttachment(
type: UploadType::File,
Expand Down
20 changes: 14 additions & 6 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ class Api

public const string API_VERSION = '1.2.5';

private const array DEFAULT_GUZZLE_CONFIG = [
'timeout' => 10,
'connect_timeout' => 5,
'read_timeout' => 10,
'headers' => ['User-Agent' => 'max-bot-api-client-php/' . self::LIBRARY_VERSION . ' PHP/' . PHP_VERSION],
'verify' => false
];

private const string API_BASE_URL = 'https://platform-api2.max.ru';

private const string METHOD_GET = 'GET';
Expand Down Expand Up @@ -92,6 +100,7 @@ class Api
* @param ClientApiInterface|null $client Http api client.
* @param ModelFactory|null $modelFactory The model factory.
* @param LoggerInterface|null $logger PSR LoggerInterface.
* @param array<string, mixed>|null $guzzleConfig Additional configuration for the default Guzzle HTTP client.
*
* @throws InvalidArgumentException
*/
Expand All @@ -100,6 +109,7 @@ public function __construct(
?ClientApiInterface $client = null,
?ModelFactory $modelFactory = null,
?LoggerInterface $logger = null,
?array $guzzleConfig = null,
) {
if (empty($accessToken) && $client === null) {
throw new InvalidArgumentException('You must provide either an access token or a client.');
Expand All @@ -115,12 +125,10 @@ public function __construct(
);
}

$guzzle = new \GuzzleHttp\Client([
'timeout' => 10,
'connect_timeout' => 5,
'read_timeout' => 10,
'headers' => ['User-Agent' => 'max-bot-api-client-php/' . self::LIBRARY_VERSION . ' PHP/' . PHP_VERSION],
]);
$finalGuzzleConfig = $guzzleConfig !== null
? array_merge(self::DEFAULT_GUZZLE_CONFIG, $guzzleConfig)
: self::DEFAULT_GUZZLE_CONFIG;
$guzzle = new \GuzzleHttp\Client($finalGuzzleConfig);
$httpFactory = new \GuzzleHttp\Psr7\HttpFactory();
$client = new Client(
$accessToken,
Expand Down
Loading