phpbotgram

CallbackAnswer
in package

FinalYes

Mutable config DTO that carries the answer parameters for a single {@see CallbackAnswerMiddleware} invocation.

Mirrors the CallbackAnswer helper class from upstream aiogram/utils/callback_answer.py.

Once markAnswered() has been called the object becomes effectively frozen — any subsequent setter call throws CallbackAnswerException. This invariant prevents accidentally mutating answer parameters after the answerCallbackQuery API call has already been sent.

Typical usage inside a handler:

public function myHandler(CallbackQuery $query, CallbackAnswer $callbackAnswer): void
{
    // Customise the answer text before the middleware sends it.
    $callbackAnswer->text = 'Done!';
    $callbackAnswer->showAlert = true;

    // … handler logic …

    // Optionally disable the auto-answer (middleware will skip it).
    $callbackAnswer->disable();
}

Table of Contents

Properties

$cacheTime  : int|null
Seconds the client should cache this answer (0–86400).
$disabled  : bool
Whether answering has been suppressed for this handler invocation.
$showAlert  : bool|null
When `true`, the answer is shown as an alert popup instead of a toast.
$text  : string|null
Optional notification text shown to the user (≤ 200 chars).
$url  : string|null
Deep-link URL to open (for game callbacks).
$answered  : bool
$cacheTimeValue  : int|null
$disabledValue  : bool
$showAlertValue  : bool|null
$textValue  : string|null
$urlValue  : string|null

Methods

__construct()  : mixed
disable()  : void
Convenience helper — equivalent to `$this->disabled = true` but reads more naturally from handler code.
isAnswered()  : bool
Returns `true` once the `answerCallbackQuery` API call has been made (or when the DTO was constructed with `$answered = true` for pre-mode).
markAnswered()  : void
Called by {@see CallbackAnswerMiddleware} after the API call completes.

Properties

$cacheTime virtual

Seconds the client should cache this answer (0–86400).

public int|null $cacheTime
Hooks
public int|null get public set

$disabled virtual

Whether answering has been suppressed for this handler invocation.

public bool $disabled
Hooks
public bool get public set

$showAlert virtual

When `true`, the answer is shown as an alert popup instead of a toast.

public bool|null $showAlert
Hooks
public bool|null get public set

$text virtual

Optional notification text shown to the user (≤ 200 chars).

public string|null $text
Hooks
public string|null get public set

$url virtual

Deep-link URL to open (for game callbacks).

public string|null $url
Hooks
public string|null get public set

Methods

__construct()

public __construct(bool $answered[, bool $disabled = false ][, string|null $text = null ][, bool|null $showAlert = null ][, string|null $url = null ][, int|null $cacheTime = null ]) : mixed
Parameters
$answered : bool

Internal flag. The middleware passes true here when pre=true so the pre-send counts as "already answered" and the finally-block skips a second send.

$disabled : bool = false

When true, the middleware skips answering.

$text : string|null = null

See $text.

$showAlert : bool|null = null

See $showAlert.

$url : string|null = null

See $url.

$cacheTime : int|null = null

See $cacheTime.

disable()

Convenience helper — equivalent to `$this->disabled = true` but reads more naturally from handler code.

public disable() : void

Guarded by the $disabled setter: throws if the answer was already sent.

isAnswered()

Returns `true` once the `answerCallbackQuery` API call has been made (or when the DTO was constructed with `$answered = true` for pre-mode).

public isAnswered() : bool
Return values
bool

markAnswered()

Called by {@see CallbackAnswerMiddleware} after the API call completes.

public markAnswered() : void

Idempotent — subsequent calls are a no-op.

After this point, all property setters will throw CallbackAnswerException.

On this page

Search results