Skip to content

Commit

Permalink
Add setPassportDataErrors method and PassportElementError* types (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik authored Jun 29, 2024
1 parent 874edb4 commit 1edbbc5
Show file tree
Hide file tree
Showing 24 changed files with 686 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
- New #82: Add `createInvoiceLink` method.
- New #83: Add `answerShippingQuery` and `answerPreCheckoutQuery` methods, and `ShippingOption` type.
- New #84: Add `refundStarPayment` method.
- New #85: Add `setPassportDataErrors` method and `PassportElementError*` types.
- Chg #24: Move update methods to `Vjik\TelegramBot\Api\Method\Update` namespace, and update types to
`Vjik\TelegramBot\Api\Type\Update` namespace.
- Chg #30: Remove `TelegramRequestWithFilesInterface`.
Expand Down
52 changes: 52 additions & 0 deletions src/Method/Passport/SetPassportDataErrors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Method\Passport;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;
use Vjik\TelegramBot\Api\Type\Passport\PassportElementError;

/**
* @see https://core.telegram.org/bots/api#setpassportdataerrors
*/
final readonly class SetPassportDataErrors implements TelegramRequestWithResultPreparingInterface
{
/**
* @param PassportElementError[] $errors
*/
public function __construct(
private int $userId,
private array $errors,
) {
}

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

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

public function getData(): array
{
return [
'user_id' => $this->userId,
'errors' => array_map(
static fn(PassportElementError $error) => $error->toRequestArray(),
$this->errors
),
];
}

public function prepareResult(mixed $result): true
{
ValueHelper::assertTrueResult($result);
return $result;
}
}
20 changes: 17 additions & 3 deletions src/TelegramBotApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
use Vjik\TelegramBot\Api\Method\Inline\AnswerWebAppQuery;
use Vjik\TelegramBot\Api\Method\LeaveChat;
use Vjik\TelegramBot\Api\Method\LogOut;
use Vjik\TelegramBot\Api\Method\Passport\SetPassportDataErrors;
use Vjik\TelegramBot\Api\Method\Payment\AnswerPreCheckoutQuery;
use Vjik\TelegramBot\Api\Method\Payment\AnswerShippingQuery;
use Vjik\TelegramBot\Api\Method\Payment\CreateInvoiceLink;
Expand Down Expand Up @@ -156,6 +157,7 @@
use Vjik\TelegramBot\Api\Type\Message;
use Vjik\TelegramBot\Api\Type\MessageEntity;
use Vjik\TelegramBot\Api\Type\MessageId;
use Vjik\TelegramBot\Api\Type\Passport\PassportElementError;
use Vjik\TelegramBot\Api\Type\Payment\LabeledPrice;
use Vjik\TelegramBot\Api\Type\Payment\ShippingOption;
use Vjik\TelegramBot\Api\Type\Payment\StarTransactions;
Expand Down Expand Up @@ -2158,6 +2160,16 @@ public function setChatTitle(int|string $chatId, string $title): FailResult|true
);
}

/**
* @see https://core.telegram.org/bots/api#setcustomemojistickersetthumbnail
*
* @psalm-suppress MixedInferredReturnType,MixedReturnStatement
*/
public function setCustomEmojiStickerSetThumbnail(string $name, ?string $customEmojiId = null): FailResult|true
{
return $this->send(new SetCustomEmojiStickerSetThumbnail($name, $customEmojiId));
}

/**
* @see https://core.telegram.org/bots/api#setmessagereaction
*
Expand Down Expand Up @@ -2236,13 +2248,15 @@ public function setMyShortDescription(
}

/**
* @see https://core.telegram.org/bots/api#setcustomemojistickersetthumbnail
* @see https://core.telegram.org/bots/api#setpassportdataerrors
*
* @param PassportElementError[] $errors
*
* @psalm-suppress MixedInferredReturnType,MixedReturnStatement
*/
public function setCustomEmojiStickerSetThumbnail(string $name, ?string $customEmojiId = null): FailResult|true
public function setPassportDataErrors(int $userId, array $errors): FailResult|true
{
return $this->send(new SetCustomEmojiStickerSetThumbnail($name, $customEmojiId));
return $this->send(new SetPassportDataErrors($userId, $errors));
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/Type/Passport/PassportElementError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Type\Passport;

/**
* @see https://core.telegram.org/bots/api#passportelementerror
*/
interface PassportElementError
{
public function getSource(): string;

public function toRequestArray(): array;
}
35 changes: 35 additions & 0 deletions src/Type/Passport/PassportElementErrorDataField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Type\Passport;

/**
* @see https://core.telegram.org/bots/api#passportelementerrordatafield
*/
final readonly class PassportElementErrorDataField implements PassportElementError
{
public function __construct(
public string $type,
public string $fieldName,
public string $dataHash,
public string $message,
) {
}

public function getSource(): string
{
return 'data';
}

public function toRequestArray(): array
{
return [
'source' => $this->getSource(),
'type' => $this->type,
'field_name' => $this->fieldName,
'data_hash' => $this->dataHash,
'message' => $this->message,
];
}
}
33 changes: 33 additions & 0 deletions src/Type/Passport/PassportElementErrorFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Type\Passport;

/**
* @see https://core.telegram.org/bots/api#passportelementerrorfile
*/
final readonly class PassportElementErrorFile implements PassportElementError
{
public function __construct(
public string $type,
public string $fileHash,
public string $message,
) {
}

public function getSource(): string
{
return 'file';
}

public function toRequestArray(): array
{
return [
'source' => $this->getSource(),
'type' => $this->type,
'file_hash' => $this->fileHash,
'message' => $this->message,
];
}
}
36 changes: 36 additions & 0 deletions src/Type/Passport/PassportElementErrorFiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Type\Passport;

/**
* @see https://core.telegram.org/bots/api#passportelementerrorfiles
*/
final readonly class PassportElementErrorFiles implements PassportElementError
{
/**
* @param string[] $fileHashes
*/
public function __construct(
public string $type,
public array $fileHashes,
public string $message,
) {
}

public function getSource(): string
{
return 'files';
}

public function toRequestArray(): array
{
return [
'source' => $this->getSource(),
'type' => $this->type,
'file_hashes' => $this->fileHashes,
'message' => $this->message,
];
}
}
33 changes: 33 additions & 0 deletions src/Type/Passport/PassportElementErrorFrontSide.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Type\Passport;

/**
* @see https://core.telegram.org/bots/api#passportelementerrorfrontside
*/
final readonly class PassportElementErrorFrontSide implements PassportElementError
{
public function __construct(
public string $type,
public string $fileHash,
public string $message,
) {
}

public function getSource(): string
{
return 'front_side';
}

public function toRequestArray(): array
{
return [
'source' => $this->getSource(),
'type' => $this->type,
'file_hash' => $this->fileHash,
'message' => $this->message,
];
}
}
33 changes: 33 additions & 0 deletions src/Type/Passport/PassportElementErrorReverseSide.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Type\Passport;

/**
* @see https://core.telegram.org/bots/api#passportelementerrorreverseside
*/
final readonly class PassportElementErrorReverseSide implements PassportElementError
{
public function __construct(
public string $type,
public string $fileHash,
public string $message,
) {
}

public function getSource(): string
{
return 'reverse_side';
}

public function toRequestArray(): array
{
return [
'source' => $this->getSource(),
'type' => $this->type,
'file_hash' => $this->fileHash,
'message' => $this->message,
];
}
}
33 changes: 33 additions & 0 deletions src/Type/Passport/PassportElementErrorSelfie.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Type\Passport;

/**
* @see https://core.telegram.org/bots/api#passportelementerrorselfie
*/
final readonly class PassportElementErrorSelfie implements PassportElementError
{
public function __construct(
public string $type,
public string $fileHash,
public string $message,
) {
}

public function getSource(): string
{
return 'selfie';
}

public function toRequestArray(): array
{
return [
'source' => $this->getSource(),
'type' => $this->type,
'file_hash' => $this->fileHash,
'message' => $this->message,
];
}
}
33 changes: 33 additions & 0 deletions src/Type/Passport/PassportElementErrorTranslationFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Type\Passport;

/**
* @see https://core.telegram.org/bots/api#passportelementerrortranslationfile
*/
final readonly class PassportElementErrorTranslationFile implements PassportElementError
{
public function __construct(
public string $type,
public string $fileHash,
public string $message,
) {
}

public function getSource(): string
{
return 'translation_file';
}

public function toRequestArray(): array
{
return [
'source' => $this->getSource(),
'type' => $this->type,
'file_hash' => $this->fileHash,
'message' => $this->message,
];
}
}
Loading

0 comments on commit 1edbbc5

Please sign in to comment.