By default TelegramBotApi uses cURL to make requests to the Telegram Bot API and download files from Telegram servers.
But you can use any other transport implementation that implements
the Phptg\BotApi\Transport\TransportInterface interface.
Out of the box, available two transport implementations: cURL and native.
Additionally, the phptg/transport-psr package provides PsrTransport
based on PSR-18 HTTP client and PSR-17 HTTP factories.
The CurlTransport class is a transport implementation for making requests to the Telegram Bot API using
the cURL extension in PHP. This transport is often the easiest choice
since the cURL extension is included in most PHP installations.
General usage:
use Phptg\BotApi\TelegramBotApi;
use Phptg\BotApi\Transport\CurlTransport;
// Telegram bot authentication token
$token = '110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw';
$transport = new CurlTransport();
$api = new TelegramBotApi($token, transport: $transport);Constructor parameters:
$mimeTypeResolver— MIME type resolver for determining file types. Defaults toApacheMimeTypeResolver.
The NativeTransport uses native PHP functions file_get_contents() and file_put_contents() to make requests to
the Telegram Bot API and not require any additional extensions.
Note:
NativeTransportrequires thatallow_url_fopenoption be enabled.
General usage:
use Phptg\BotApi\TelegramBotApi;
use Phptg\BotApi\Transport\NativeTransport;
// Telegram bot authentication token
$token = '110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw';
$transport = new NativeTransport();
$api = new TelegramBotApi($token, transport: $transport);Constructor parameters:
$mimeTypeResolver— MIME type resolver for determining file types. Defaults toApacheMimeTypeResolver.
Available MIME type resolvers:
ApacheMimeTypeResolver- based on file extension and Apache'smime.typesfile (uses by default);CustomMimeTypeResolver- based on file extension and custom MIME types map;CompositeMimeTypeResolver- allows to combine multiple resolvers into one.