phpbotgram

AmphpSession extends BaseSession
in package

FinalYes

Production session backed by amphp/http-client (Fiber-aware HTTP/1.1).

Phase 1 implements form-urlencoded body encoding only. Multipart/form-data with InputFile streaming lands in Phase 6 when the webhook layer needs symmetric multipart handling.

Table of Contents

Properties

$api  : TelegramApiServer
$jsonDumps  : callable(mixed): string
$jsonLoads  : callable(string): mixed
$middleware  : RequestMiddlewareManager
$timeout  : float
$client  : HttpClient|null

Methods

__construct()  : mixed
__invoke()  : mixed
Run $method through the session's middleware chain, terminating at makeRequest.
checkResponse()  : Response<string|int, mixed>
Maps Telegram error status codes to typed exceptions.
close()  : void
makeRequest()  : mixed
prepareValue()  : mixed
Resolves BotDefault sentinels, detaches InputFile to $files, encodes datetimes / enums / nested TelegramObject. Port of upstream session/base.py:179-250.
streamContent()  : ReadableStream
buildResponse()  : Response<string|int, mixed>
Build a typed Response from the wire payload.
buildFormBody()  : string
client()  : HttpClient

Properties

$jsonDumps read-only

public callable(mixed): string $jsonDumps

$jsonLoads read-only

public callable(string): mixed $jsonLoads

Methods

__construct()

public __construct([TelegramApiServer|null $api = null ][, null|callable(string): mixed $jsonLoads = null ][, null|callable(mixed): string $jsonDumps = null ][, float $timeout = 60.0 ]) : mixed
Parameters
$api : TelegramApiServer|null = null
$jsonLoads : null|callable(string): mixed = null
$jsonDumps : null|callable(mixed): string = null
$timeout : float = 60.0

__invoke()

Run $method through the session's middleware chain, terminating at makeRequest.

public __invoke(Bot $bot, TelegramMethod<string|int, mixed> $method[, int|null $timeout = null ]) : mixed

Mirrors aiogram's BaseSession.__call__ (session/base.py:267-274). With an empty chain this is equivalent to calling makeRequest directly.

Parameters
$bot : Bot
$method : TelegramMethod<string|int, mixed>
$timeout : int|null = null

checkResponse()

Maps Telegram error status codes to typed exceptions.

public checkResponse(Bot $bot, TelegramMethod<string|int, mixed> $method, int $statusCode, string $content) : Response<string|int, mixed>
Parameters
$bot : Bot
$method : TelegramMethod<string|int, mixed>
$statusCode : int
$content : string
Return values
Response<string|int, mixed>

prepareValue()

Resolves BotDefault sentinels, detaches InputFile to $files, encodes datetimes / enums / nested TelegramObject. Port of upstream session/base.py:179-250.

public prepareValue(mixed $value, Bot $bot, array<string, InputFile&$files[, bool $dumpsJson = true ]) : mixed
Parameters
$value : mixed
$bot : Bot
$files : array<string, InputFile>
$dumpsJson : bool = true

streamContent()

public streamContent(string $url[, array<string, string> $headers = [] ][, int $timeout = 30 ][, int $chunkSize = 65536 ][, bool $raiseForStatus = true ]) : ReadableStream
Parameters
$url : string
$headers : array<string, string> = []
$timeout : int = 30
$chunkSize : int = 65536
$raiseForStatus : bool = true
Return values
ReadableStream

buildResponse()

Build a typed Response from the wire payload.

protected buildResponse(Bot $bot, TelegramMethod<string|int, mixed> $method, array<string|int, mixed> $data) : Response<string|int, mixed>

On the happy path (ok: true + a present result), the raw result is routed through deserializeResult() against the method's declared ReturnsType const so the caller sees a typed TelegramObject (or list thereof, or scalar). Error / non-ok payloads land here too — they surface to checkResponse() which maps the status code to the matching exception subclass without consulting $response->result.

Wired in by Cycle 3: prior to this commit, BaseSession returned result: null unconditionally — AmphpSession's success path would then throw a LogicException because the typed Method return contract couldn't be satisfied. The Method-class-side ReturnsType const is emitted by codegen precisely so this hook can do the right thing without per-method dispatch tables.

Parameters
$bot : Bot
$method : TelegramMethod<string|int, mixed>
$data : array<string|int, mixed>
Return values
Response<string|int, mixed>

client()

private client() : HttpClient
Return values
HttpClient
On this page

Search results