Skip to content
Merged
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
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
# Telegram Bot API for PHP Change Log

## 0.17.1 under development
## 0.18 April 4, 2026

- Enh #190: Open file in binary mode in `InputFile::fromLocalFile()` method.
- New #191: Add `GetManagedBotToken`, `ReplaceManagedBotToken` and `SavePreparedKeyboardButton` methods.
- New #191: Add `KeyboardButtonRequestManagedBot`, `ManagedBotCreated`, `ManagedBotUpdated`, `PreparedKeyboardButton`,
`PollOptionAdded` and `PollOptionDeleted` types.
- New #191: Add `requestManagedBot` field to `KeyboardButton` type.
- New #191: Add `canManageBots` field to `User` type.
- New #191: Add `managedBotCreated`, `pollOptionAdded`, `pollOptionDeleted` and `replyToPollOptionId` field to `Message`
type.
- New #191: Add `managedBot` field to `Update` type.
- Chg #191: Replace `correctOptionId` field with `correctOptionIds` in `Poll` type.
- New #191: Add `allowsRevoting`, `description` and `descriptionEntities` fields to `Poll` type.
- Chg #191: Replace `correctOptionId` parameter with `correctOptionIds` in `SendPoll` method.
- New #191: Add `allowsRevoting`, `shuffleOptions`, `allowAddingOptions`, `hideResultsUntilCloses`, `description`,
`descriptionParseMode` and `descriptionEntities` parameters to `SendPoll` method.
- New #191: Add `persistentId`, `addedByUser`, `addedByChat` and `additionDate` fields to `PollOption` type.
- New #191: Add `optionPersistentIds` field to `PollAnswer` type.
- New #191: Add `pollOptionId` field to `ReplyParameters` type.

## 0.17 March 1, 2026

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

The package provides a simple and convenient way to interact with the Telegram Bot API.

✔️ Telegram Bot API 9.5 (March 1, 2026) is **fully supported**.
✔️ Telegram Bot API 9.6 (April 3, 2026) is **fully supported**.

♻️ **Zero dependencies** — no third-party libraries, only native PHP.

Expand Down
41 changes: 41 additions & 0 deletions src/Method/GetManagedBotToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Phptg\BotApi\Method;

use Phptg\BotApi\ParseResult\ValueProcessor\StringValue;
use Phptg\BotApi\Transport\HttpMethod;
use Phptg\BotApi\MethodInterface;

/**
* @see https://core.telegram.org/bots/api#getmanagedbottoken
*
* @template-implements MethodInterface<string>
*/
final readonly class GetManagedBotToken implements MethodInterface
{
public function __construct(
private int $userId,
) {}

public function getHttpMethod(): HttpMethod
{
return HttpMethod::POST;
}

public function getApiMethod(): string
{
return 'getManagedBotToken';
}

public function getData(): array
{
return ['user_id' => $this->userId];
}

public function getResultType(): StringValue
{
return new StringValue();
}
}
41 changes: 41 additions & 0 deletions src/Method/ReplaceManagedBotToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Phptg\BotApi\Method;

use Phptg\BotApi\ParseResult\ValueProcessor\StringValue;
use Phptg\BotApi\Transport\HttpMethod;
use Phptg\BotApi\MethodInterface;

/**
* @see https://core.telegram.org/bots/api#replacemanagedbottoken
*
* @template-implements MethodInterface<string>
*/
final readonly class ReplaceManagedBotToken implements MethodInterface
{
public function __construct(
private int $userId,
) {}

public function getHttpMethod(): HttpMethod
{
return HttpMethod::POST;
}

public function getApiMethod(): string
{
return 'replaceManagedBotToken';
}

public function getData(): array
{
return ['user_id' => $this->userId];
}

public function getResultType(): StringValue
{
return new StringValue();
}
}
47 changes: 47 additions & 0 deletions src/Method/SavePreparedKeyboardButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Phptg\BotApi\Method;

use Phptg\BotApi\ParseResult\ValueProcessor\ObjectValue;
use Phptg\BotApi\Transport\HttpMethod;
use Phptg\BotApi\MethodInterface;
use Phptg\BotApi\Type\KeyboardButton;
use Phptg\BotApi\Type\PreparedKeyboardButton;

/**
* @see https://core.telegram.org/bots/api#savepreparedkeyboardbutton
*
* @template-implements MethodInterface<PreparedKeyboardButton>
*/
final readonly class SavePreparedKeyboardButton implements MethodInterface
{
public function __construct(
private int $userId,
private KeyboardButton $button,
) {}

public function getHttpMethod(): HttpMethod
{
return HttpMethod::POST;
}

public function getApiMethod(): string
{
return 'savePreparedKeyboardButton';
}

public function getData(): array
{
return [
'user_id' => $this->userId,
'button' => $this->button->toRequestArray(),
];
}

public function getResultType(): ObjectValue
{
return new ObjectValue(PreparedKeyboardButton::class);
}
}
25 changes: 23 additions & 2 deletions src/Method/SendPoll.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
/**
* @param InputPollOption[] $options
* @param MessageEntity[]|null $questionEntities
* @param int[]|null $correctOptionIds
* @param MessageEntity[]|null $explanationEntities
* @param MessageEntity[]|null $descriptionEntities
*/
public function __construct(
private int|string $chatId,
Expand All @@ -40,7 +42,7 @@ public function __construct(
private ?bool $isAnonymous = null,
private ?string $type = null,
private ?bool $allowsMultipleAnswers = null,
private ?int $correctOptionId = null,
private ?array $correctOptionIds = null,
private ?string $explanation = null,
private ?string $explanationParseMode = null,
private ?array $explanationEntities = null,
Expand All @@ -53,6 +55,13 @@ public function __construct(
private ?ReplyParameters $replyParameters = null,
private InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup = null,
private ?bool $allowPaidBroadcast = null,
private ?bool $allowsRevoting = null,
private ?bool $shuffleOptions = null,
private ?bool $allowAddingOptions = null,
private ?bool $hideResultsUntilCloses = null,
private ?string $description = null,
private ?string $descriptionParseMode = null,
private ?array $descriptionEntities = null,
) {}

public function getHttpMethod(): HttpMethod
Expand Down Expand Up @@ -87,7 +96,11 @@ public function getData(): array
'is_anonymous' => $this->isAnonymous,
'type' => $this->type,
'allows_multiple_answers' => $this->allowsMultipleAnswers,
'correct_option_id' => $this->correctOptionId,
'allows_revoting' => $this->allowsRevoting,
'shuffle_options' => $this->shuffleOptions,
'allow_adding_options' => $this->allowAddingOptions,
'hide_results_until_closes' => $this->hideResultsUntilCloses,
'correct_option_ids' => $this->correctOptionIds,
'explanation' => $this->explanation,
'explanation_parse_mode' => $this->explanationParseMode,
'explanation_entities' => $this->explanationEntities === null
Expand All @@ -99,6 +112,14 @@ public function getData(): array
'open_period' => $this->openPeriod,
'close_date' => $this->closeDate?->getTimestamp(),
'is_closed' => $this->isClosed,
'description' => $this->description,
'description_parse_mode' => $this->descriptionParseMode,
'description_entities' => $this->descriptionEntities === null
? null
: array_map(
static fn(MessageEntity $entity) => $entity->toRequestArray(),
$this->descriptionEntities,
),
'disable_notification' => $this->disableNotification,
'protect_content' => $this->protectContent,
'allow_paid_broadcast' => $this->allowPaidBroadcast,
Expand Down
51 changes: 48 additions & 3 deletions src/TelegramBotApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
use Phptg\BotApi\Method\GetChatMenuButton;
use Phptg\BotApi\Method\GetFile;
use Phptg\BotApi\Method\GetForumTopicIconStickers;
use Phptg\BotApi\Method\GetManagedBotToken;
use Phptg\BotApi\Method\GetMe;
use Phptg\BotApi\Method\GetMyCommands;
use Phptg\BotApi\Method\GetMyDefaultAdministratorRights;
Expand Down Expand Up @@ -81,15 +82,17 @@
use Phptg\BotApi\Method\PinChatMessage;
use Phptg\BotApi\Method\PostStory;
use Phptg\BotApi\Method\PromoteChatMember;
use Phptg\BotApi\Method\RepostStory;
use Phptg\BotApi\Method\RemoveBusinessAccountProfilePhoto;
use Phptg\BotApi\Method\ReplaceManagedBotToken;
use Phptg\BotApi\Method\RepostStory;
use Phptg\BotApi\Method\RemoveMyProfilePhoto;
use Phptg\BotApi\Method\RemoveChatVerification;
use Phptg\BotApi\Method\RemoveUserVerification;
use Phptg\BotApi\Method\ReopenForumTopic;
use Phptg\BotApi\Method\ReopenGeneralForumTopic;
use Phptg\BotApi\Method\RestrictChatMember;
use Phptg\BotApi\Method\RevokeChatInviteLink;
use Phptg\BotApi\Method\SavePreparedKeyboardButton;
use Phptg\BotApi\Method\SendAnimation;
use Phptg\BotApi\Method\SendAudio;
use Phptg\BotApi\Method\SendChatAction;
Expand Down Expand Up @@ -200,6 +203,8 @@
use Phptg\BotApi\Type\Inline\PreparedInlineMessage;
use Phptg\BotApi\Type\Inline\SentWebAppMessage;
use Phptg\BotApi\Type\InlineKeyboardMarkup;
use Phptg\BotApi\Type\KeyboardButton;
use Phptg\BotApi\Type\PreparedKeyboardButton;
use Phptg\BotApi\Type\InputChecklist;
use Phptg\BotApi\Type\InputFile;
use Phptg\BotApi\Type\InputMedia;
Expand Down Expand Up @@ -1350,6 +1355,14 @@ public function getMe(): FailResult|User
return $this->call(new GetMe());
}

/**
* @see https://core.telegram.org/bots/api#getmanagedbottoken
*/
public function getManagedBotToken(int $userId): FailResult|string
{
return $this->call(new GetManagedBotToken($userId));
}

/**
* @see https://core.telegram.org/bots/api#getmycommands
*/
Expand Down Expand Up @@ -1759,6 +1772,14 @@ public function reopenGeneralForumTopic(int|string $chatId): FailResult|true
);
}

/**
* @see https://core.telegram.org/bots/api#replacemanagedbottoken
*/
public function replaceManagedBotToken(int $userId): FailResult|string
{
return $this->call(new ReplaceManagedBotToken($userId));
}

/**
* @see https://core.telegram.org/bots/api#replacestickerinset
*/
Expand Down Expand Up @@ -1798,6 +1819,14 @@ public function revokeChatInviteLink(int|string $chatId, string $inviteLink): Fa
);
}

/**
* @see https://core.telegram.org/bots/api#savepreparedkeyboardbutton
*/
public function savePreparedKeyboardButton(int $userId, KeyboardButton $button): FailResult|PreparedKeyboardButton
{
return $this->call(new SavePreparedKeyboardButton($userId, $button));
}

/**
* @see https://core.telegram.org/bots/api#savepreparedinlinemessage
*/
Expand Down Expand Up @@ -2476,7 +2505,9 @@ public function sendPhoto(
/**
* @param InputPollOption[] $options
* @param MessageEntity[]|null $questionEntities
* @param int[]|null $correctOptionIds
* @param MessageEntity[]|null $explanationEntities
* @param MessageEntity[]|null $descriptionEntities
*
* @see https://core.telegram.org/bots/api#sendpoll
*/
Expand All @@ -2491,7 +2522,7 @@ public function sendPoll(
?bool $isAnonymous = null,
?string $type = null,
?bool $allowsMultipleAnswers = null,
?int $correctOptionId = null,
?array $correctOptionIds = null,
?string $explanation = null,
?string $explanationParseMode = null,
?array $explanationEntities = null,
Expand All @@ -2504,6 +2535,13 @@ public function sendPoll(
?ReplyParameters $replyParameters = null,
InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup = null,
?bool $allowPaidBroadcast = null,
?bool $allowsRevoting = null,
?bool $shuffleOptions = null,
?bool $allowAddingOptions = null,
?bool $hideResultsUntilCloses = null,
?string $description = null,
?string $descriptionParseMode = null,
?array $descriptionEntities = null,
): FailResult|Message {
return $this->call(
new SendPoll(
Expand All @@ -2517,7 +2555,7 @@ public function sendPoll(
$isAnonymous,
$type,
$allowsMultipleAnswers,
$correctOptionId,
$correctOptionIds,
$explanation,
$explanationParseMode,
$explanationEntities,
Expand All @@ -2530,6 +2568,13 @@ public function sendPoll(
$replyParameters,
$replyMarkup,
$allowPaidBroadcast,
$allowsRevoting,
$shuffleOptions,
$allowAddingOptions,
$hideResultsUntilCloses,
$description,
$descriptionParseMode,
$descriptionEntities,
),
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Type/KeyboardButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function __construct(
public ?WebAppInfo $webApp = null,
public ?string $iconCustomEmojiId = null,
public ?string $style = null,
public ?KeyboardButtonRequestManagedBot $requestManagedBot = null,
) {}

public function toRequestArray(): array
Expand All @@ -32,6 +33,7 @@ public function toRequestArray(): array
'style' => $this->style,
'request_users' => $this->requestUsers?->toRequestArray(),
'request_chat' => $this->requestChat?->toRequestArray(),
'request_managed_bot' => $this->requestManagedBot?->toRequestArray(),
'request_contact' => $this->requestContact,
'request_location' => $this->requestLocation,
'request_poll' => $this->requestPoll?->toRequestArray(),
Expand Down
Loading
Loading