Skip to content

Commit

Permalink
New methods (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik authored Jun 3, 2024
1 parent 6a02d8f commit 5ab88f1
Show file tree
Hide file tree
Showing 51 changed files with 1,881 additions and 40 deletions.
44 changes: 44 additions & 0 deletions src/Method/DeleteMyCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;
use Vjik\TelegramBot\Api\Type\BotCommandScope;

/**
* @see https://core.telegram.org/bots/api#deletemycommands
*/
final readonly class DeleteMyCommands implements TelegramRequestWithResultPreparingInterface
{
public function __construct(
private ?BotCommandScope $scope = null,
private ?string $languageCode = null,
) {
}

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

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

public function getData(): array
{
return array_filter([
'scope' => $this->scope?->toRequestArray(),
'language_code' => $this->languageCode,
]);
}

public function prepareResult(mixed $result): true
{
return true;
}
}
43 changes: 43 additions & 0 deletions src/Method/GetChatMenuButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;
use Vjik\TelegramBot\Api\Type\MenuButton;
use Vjik\TelegramBot\Api\Type\MenuButtonFactory;

/**
* @see https://core.telegram.org/bots/api#getchatmenubutton
*/
final readonly class GetChatMenuButton implements TelegramRequestWithResultPreparingInterface
{
public function __construct(
private ?int $chatId = null,
) {
}

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

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

public function getData(): array
{
return array_filter([
'chat_id' => $this->chatId,
]);
}

public function prepareResult(mixed $result): MenuButton
{
return MenuButtonFactory::fromTelegramResult($result);
}
}
53 changes: 53 additions & 0 deletions src/Method/GetMyCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;
use Vjik\TelegramBot\Api\Type\BotCommand;
use Vjik\TelegramBot\Api\Type\BotCommandScope;

/**
* @see https://core.telegram.org/bots/api#getmycommands
*/
final readonly class GetMyCommands implements TelegramRequestWithResultPreparingInterface
{
public function __construct(
private ?BotCommandScope $scope = null,
private ?string $languageCode = null,
) {
}

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

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

public function getData(): array
{
return array_filter([
'scope' => $this->scope?->toRequestArray(),
'language_code' => $this->languageCode,
]);
}

/**
* @return BotCommand[]
*/
public function prepareResult(mixed $result): array
{
ValueHelper::assertArrayResult($result);
return array_map(
static fn($item) => BotCommand::fromTelegramResult($item),
$result
);
}
}
42 changes: 42 additions & 0 deletions src/Method/GetMyDescription.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;
use Vjik\TelegramBot\Api\Type\BotDescription;

/**
* @see https://core.telegram.org/bots/api#getmydescription
*/
final readonly class GetMyDescription implements TelegramRequestWithResultPreparingInterface
{
public function __construct(
private ?string $languageCode = null,
) {
}

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

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

public function getData(): array
{
return array_filter([
'language_code' => $this->languageCode,
]);
}

public function prepareResult(mixed $result): BotDescription
{
return BotDescription::fromTelegramResult($result);
}
}
42 changes: 42 additions & 0 deletions src/Method/GetMyName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;
use Vjik\TelegramBot\Api\Type\BotName;

/**
* @see https://core.telegram.org/bots/api#getmyname
*/
final readonly class GetMyName implements TelegramRequestWithResultPreparingInterface
{
public function __construct(
private ?string $languageCode = null,
) {
}

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

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

public function getData(): array
{
return array_filter([
'language_code' => $this->languageCode,
]);
}

public function prepareResult(mixed $result): BotName
{
return BotName::fromTelegramResult($result);
}
}
42 changes: 42 additions & 0 deletions src/Method/GetMyShortDescription.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;
use Vjik\TelegramBot\Api\Type\BotShortDescription;

/**
* @see https://core.telegram.org/bots/api#getmyshortdescription
*/
final readonly class GetMyShortDescription implements TelegramRequestWithResultPreparingInterface
{
public function __construct(
private ?string $languageCode = null,
) {
}

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

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

public function getData(): array
{
return array_filter([
'language_code' => $this->languageCode,
]);
}

public function prepareResult(mixed $result): BotShortDescription
{
return BotShortDescription::fromTelegramResult($result);
}
}
73 changes: 73 additions & 0 deletions src/Method/SendLocation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;
use Vjik\TelegramBot\Api\Type\ForceReply;
use Vjik\TelegramBot\Api\Type\InlineKeyboardMarkup;
use Vjik\TelegramBot\Api\Type\Message;
use Vjik\TelegramBot\Api\Type\ReplyKeyboardMarkup;
use Vjik\TelegramBot\Api\Type\ReplyKeyboardRemove;
use Vjik\TelegramBot\Api\Type\ReplyParameters;

/**
* @see https://core.telegram.org/bots/api#sendlocation
*/
final readonly class SendLocation implements TelegramRequestWithResultPreparingInterface
{
public function __construct(
private int|string $chatId,
private float $latitude,
private float $longitude,
private ?string $businessConnectionId = null,
private ?int $messageThreadId = null,
private ?float $horizontalAccuracy = null,
private ?int $livePeriod = null,
private ?int $heading = null,
private ?int $proximityAlertRadius = null,
private ?bool $disableNotification = null,
private ?bool $protectContent = null,
private ?string $messageEffectId = null,
private ?ReplyParameters $replyParameters = null,
private InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup = null,
) {
}

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

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

public function getData(): array
{
return array_filter([
'business_connection_id' => $this->businessConnectionId,
'chat_id' => $this->chatId,
'message_thread_id' => $this->messageThreadId,
'latitude' => $this->latitude,
'longitude' => $this->longitude,
'horizontal_accuracy' => $this->horizontalAccuracy,
'live_period' => $this->livePeriod,
'heading' => $this->heading,
'proximity_alert_radius' => $this->proximityAlertRadius,
'disable_notification' => $this->disableNotification,
'protect_content' => $this->protectContent,
'message_effect_id' => $this->messageEffectId,
'reply_parameters' => $this->replyParameters?->toRequestArray(),
'reply_markup' => $this->replyMarkup?->toRequestArray(),
]);
}

public function prepareResult(mixed $result): Message
{
return Message::fromTelegramResult($result);
}
}
Loading

0 comments on commit 5ab88f1

Please sign in to comment.