phpbotgram

SendGift extends TelegramMethod
in package

FinalYes

Sends a gift to the given user or channel chat. The gift can't be converted to Telegram Stars by the receiver. Returns True on success.

Source: https://core.telegram.org/bots/api#sendgift

Tags
extends

Table of Contents

Constants

ApiMethod  : string = 'sendGift'
ReturnsType  : string = 'bool'
Subclasses override with either: - a `class-string<TelegramObject>` (e.g. Message::class) for object returns - a scalar type name ('bool', 'int', 'string') for primitive returns - 'list:<inner>' for array returns

Properties

$bot  : Bot|null
$chatId  : int|string|null
$giftId  : string
$payForUpgrade  : bool|null
$text  : string|null
$textEntities  : array<int, MessageEntity>
$textParseMode  : string|null
$userId  : int|null

Methods

__construct()  : mixed
as_()  : static
Alias of withBot() for grep-translating aiogram code that uses obj.as_(bot).
bindBot()  : static
Returns a clone bound to $bot. Used by hand-authored shortcut methods (Message::answer, etc.) so the chained ->emit() picks up the bot without an explicit argument.
emit()  : TReturn
Emit this method via the bound bot (or the explicitly-passed bot).
withBot()  : static
Returns a clone of $this with $bot rebound recursively. Walks every public property; nested `BotContextController` instances are rebound via their own `withBot`, arrays (including nested arrays of arbitrary depth — e.g.

Constants

ApiMethod

public string ApiMethod = 'sendGift'

ReturnsType

Subclasses override with either: - a `class-string<TelegramObject>` (e.g. Message::class) for object returns - a scalar type name ('bool', 'int', 'string') for primitive returns - 'list:<inner>' for array returns

public string ReturnsType = 'bool'

Stays '' on the abstract base — Phase 2 codegen sets it per concrete method.

Properties

$chatId read-only

public int|string|null $chatId = null

$payForUpgrade read-only

public bool|null $payForUpgrade = null

$text read-only

public string|null $text = null

$textParseMode read-only

public string|null $textParseMode = null

$userId read-only

public int|null $userId = null

Methods

__construct()

public __construct(string $giftId[, int|null $userId = null ][, int|string|null $chatId = null ][, bool|null $payForUpgrade = null ][, string|null $text = null ][, string|null $textParseMode = null ][, array<string|int, mixed>|null $textEntities = null ][, Bot|null $bot = null ]) : mixed
Parameters
$giftId : string
$userId : int|null = null
$chatId : int|string|null = null
$payForUpgrade : bool|null = null
$text : string|null = null
$textParseMode : string|null = null
$textEntities : array<string|int, mixed>|null = null
$bot : Bot|null = null

as_()

Alias of withBot() for grep-translating aiogram code that uses obj.as_(bot).

public as_(Bot|null $bot) : static

IMPORTANT: behaves DIFFERENTLY from upstream — upstream mutates self.bot in place and returns self. The PHP port can't mutate readonly, so this returns a clone. Callers must reassign: $msg = $msg->as($bot).

Parameters
$bot : Bot|null
Return values
static

bindBot()

Returns a clone bound to $bot. Used by hand-authored shortcut methods (Message::answer, etc.) so the chained ->emit() picks up the bot without an explicit argument.

public bindBot(Bot|null $bot) : static
Parameters
$bot : Bot|null
Return values
static

emit()

Emit this method via the bound bot (or the explicitly-passed bot).

public emit([Bot|null $bot = null ]) : TReturn

Mirrors upstream methods/base.py:81-93 (await + emit).

Parameters
$bot : Bot|null = null
Return values
TReturn

withBot()

Returns a clone of $this with $bot rebound recursively. Walks every public property; nested `BotContextController` instances are rebound via their own `withBot`, arrays (including nested arrays of arbitrary depth — e.g.

public withBot(Bot|null $bot) : static

list<list<KeyboardButton>>) are walked element-wise. Plain values (scalars, DateTime, enums, InputFile etc.) pass through untouched.

Mirrors upstream pydantic model_validate(context={"bot": bot}) (aiogram ContextController.as_/model_dump_json+model_validate).

Scope note: PHP 8.5 treats public readonly as effectively public protected(set) readonly for clone-with — only code running with a scope in the property's declaring class hierarchy (declaring class plus its ancestors and descendants) can use clone($obj, ['x' => ...]) against it. Because this method lives on BotContextController and every TelegramObject/TelegramMethod subclass extends it, the walker's clone($this, [...]) call legally rewrites subclass-declared readonly slots like Message::$chat. External callers cannot use the same syntax — they must funnel through this method.

Parameters
$bot : Bot|null
Return values
static
On this page

Search results