Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telegram Bot API 8.0 support #125

Merged
merged 16 commits into from
Nov 18, 2024
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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Telegram Bot API for PHP Change Log

## 0.4.6 November 18, 2024

- New #125: Add `subscriptionPeriod` and `businessConnectionId` parameters to `createInvoiceLink` method.
- New #125: Add `subscriptionExpirationDate`, `isRecurring` and `isFirstRecurring` fields to `SuccessfulPayment` type.
- New #125: Add `editUserStarSubscription` method.
- New #125: Add `subscriptionPeriod` and `gift` fields to `TransactionPartnerUser` type.
- New #125: Add `setUserEmojiStatus` method.
- New #125: Add `PreparedInlineMessage` type.
- New #125: Add `savePreparedInlineMessage` method.
- New #125: Add `Gift` and `Gifts` types.
- New #125: Add `getAvailableGifts` and `SendGift` methods.

## 0.4.5 October 31, 2024

- New #124: Add `CopyTextButton` type.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

✔️ Telegram Bot API 7.11 (October 31, 2024) is **fully supported**.
✔️ Telegram Bot API 8.0 (November 17, 2024) is **fully supported**.

## Requirements

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

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Method\Inline;

use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;
use Vjik\TelegramBot\Api\Type\Inline\InlineQueryResult;
use Vjik\TelegramBot\Api\Type\Inline\PreparedInlineMessage;

/**
* @see https://core.telegram.org/bots/api#savepreparedinlinemessage
*
* @template-implements TelegramRequestWithResultPreparingInterface<class-string<PreparedInlineMessage>>
*/
final readonly class SavePreparedInlineMessage implements TelegramRequestWithResultPreparingInterface
{
public function __construct(
private int $userId,
private InlineQueryResult $result,
private ?bool $allowUserChats = null,
private ?bool $allowBotChats = null,
private ?bool $allowGroupChats = null,
private ?bool $allowChannelChats = null,
) {}

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

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

public function getData(): array
{
return array_filter(
[
'user_id' => $this->userId,
'result' => $this->result->toRequestArray(),
'allow_user_chats' => $this->allowUserChats,
'allow_bot_chats' => $this->allowBotChats,
'allow_group_chats' => $this->allowGroupChats,
'allow_channel_chats' => $this->allowChannelChats,
],
static fn(mixed $value): bool => $value !== null,
);
}

public function getResultType(): string
{
return PreparedInlineMessage::class;
}
}
4 changes: 4 additions & 0 deletions src/Method/Payment/CreateInvoiceLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public function __construct(
private ?bool $sendPhoneNumberToProvider = null,
private ?bool $sendEmailToProvider = null,
private ?bool $isFlexible = null,
private ?int $subscriptionPeriod = null,
private ?string $businessConnectionId = null,
) {}

public function getHttpMethod(): HttpMethod
Expand All @@ -57,6 +59,7 @@ public function getData(): array
{
return array_filter(
[
'business_connection_id' => $this->businessConnectionId,
'title' => $this->title,
'description' => $this->description,
'payload' => $this->payload,
Expand All @@ -66,6 +69,7 @@ public function getData(): array
static fn(LabeledPrice $price) => $price->toRequestArray(),
$this->prices,
),
'subscription_period' => $this->subscriptionPeriod,
'max_tip_amount' => $this->maxTipAmount,
'suggested_tip_amounts' => $this->suggestedTipAmounts,
'provider_data' => $this->providerData,
Expand Down
47 changes: 47 additions & 0 deletions src/Method/Payment/EditUserStarSubscription.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Method\Payment;

use Vjik\TelegramBot\Api\ParseResult\ValueProcessor\TrueValue;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;

/**
* @see https://core.telegram.org/bots/api#edituserstarsubscription
*
* @template-implements TelegramRequestWithResultPreparingInterface<TrueValue>
*/
final readonly class EditUserStarSubscription implements TelegramRequestWithResultPreparingInterface
{
public function __construct(
private int $userId,
private string $telegramPaymentChargeId,
private bool $isCanceled,
) {}

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

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

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

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

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Method;

use DateTimeImmutable;
use Vjik\TelegramBot\Api\ParseResult\ValueProcessor\TrueValue;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;

/**
* @see https://core.telegram.org/bots/api#setuseremojistatus
*
* @template-implements TelegramRequestWithResultPreparingInterface<TrueValue>
*/
final readonly class SetUserEmojiStatus implements TelegramRequestWithResultPreparingInterface
{
public function __construct(
private int $userId,
private ?string $emojiStatusCustomEmojiId = null,
private ?DateTimeImmutable $emojiStatusExpirationDate = null,
) {}

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

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

public function getData(): array
{
return array_filter(
[
'user_id' => $this->userId,
'emoji_status_custom_emoji_id' => $this->emojiStatusCustomEmojiId,
'emoji_status_expiration_date' => $this->emojiStatusExpirationDate?->getTimestamp(),
],
static fn(mixed $value): bool => $value !== null,
);
}

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

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Method\Sticker;

use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;
use Vjik\TelegramBot\Api\Type\Sticker\Gifts;

/**
* @see https://core.telegram.org/bots/api#getavailablegifts
*
* @template-implements TelegramRequestWithResultPreparingInterface<class-string<Gifts>>
*/
final readonly class GetAvailableGifts implements TelegramRequestWithResultPreparingInterface
{
public function getHttpMethod(): HttpMethod
{
return HttpMethod::GET;
}

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

public function getData(): array
{
return [];
}

public function getResultType(): string
{
return Gifts::class;
}
}
63 changes: 63 additions & 0 deletions src/Method/Sticker/SendGift.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Method\Sticker;

use Vjik\TelegramBot\Api\ParseResult\ValueProcessor\TrueValue;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;
use Vjik\TelegramBot\Api\Type\MessageEntity;

/**
* @see https://core.telegram.org/bots/api#sendgift
*
* @template-implements TelegramRequestWithResultPreparingInterface<TrueValue>
*/
final readonly class SendGift implements TelegramRequestWithResultPreparingInterface
{
/**
* @param MessageEntity[]|null $textEntities
*/
public function __construct(
private int $userId,
private string $giftId,
private ?string $text = null,
private ?string $textParseMode = null,
private ?array $textEntities = null,
) {}

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

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

public function getData(): array
{
return array_filter(
[
'user_id' => $this->userId,
'gift_id' => $this->giftId,
'text' => $this->text,
'text_parse_mode' => $this->textParseMode,
'text_entities' => $this->textEntities === null
? null
: array_map(
static fn(MessageEntity $entity) => $entity->toRequestArray(),
$this->textEntities,
),
],
static fn(mixed $value): bool => $value !== null,
);
}

public function getResultType(): TrueValue
{
return new TrueValue();
}
}
Loading
Loading