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
2 changes: 1 addition & 1 deletion src/Entities/LinkPreviewOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @method string getUrl() Optional. URL to use for the link preview. If empty, then the first URL found in the message text will be used
* @method bool getPreferSmallMedia() Optional. True, if the media in the link preview is supposed to be shrunk; ignored if the URL isn't explicitly specified or media size change isn't supported for the preview
* @method bool getPreferLargeMedia() Optional. True, if the media in the link preview is supposed to be enlarged; ignored if the URL isn't explicitly specified or media size change isn't supported for the preview
* @method bool getShowAboveText() Optional. True, if the link preview must be shown above the message text; otherwise, the link preview will be shown below the message text *
* @method bool getShowAboveText() Optional. True, if the link preview must be shown above the message text; otherwise, the link preview will be shown below the message text
*/
class LinkPreviewOptions extends Entity
{
Expand Down
11 changes: 11 additions & 0 deletions src/Entities/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@
* @method User getSenderBusinessBot() Optional. The bot that actually sent the message on behalf of the business account. Available only for outgoing messages sent on behalf of the business account.
* @method bool getIsFromOffline() Optional. True, if the message was sent by an offline user. Applicable to messages sent by the bot on behalf of a user to a fellow user in a private chat.
* @method ChatBackground getChatBackgroundSet() Optional. Service message: chat background set
*
* @method PaidMediaInfo getPaidMedia() Optional. Message is a paid media purchase, information about the paid media
* @method StarTransaction getTransaction() Optional. Message is a service message about a successful payment, information about the payment.
* @method WebAppInfo getWebApp() Optional. Service message: a Web App was launched for the user
*
* @method $this setPaidMedia(PaidMediaInfo $paidMedia) Optional. Message is a paid media purchase, information about the paid media
* @method $this setTransaction(StarTransaction $transaction) Optional. Message is a service message about a successful payment, information about the payment.
* @method $this setWebApp(WebAppInfo $webApp) Optional. Service message: a Web App was launched for the user
*/
class Message extends Entity implements MaybeInaccessibleMessage
{
Expand Down Expand Up @@ -183,6 +191,9 @@ protected function subEntities(): array
'web_app_data' => WebAppData::class,
'reply_markup' => InlineKeyboard::class,
'chat_background_set' => ChatBackground::class,
'paid_media' => PaidMediaInfo::class,
'transaction' => StarTransaction::class,
'web_app' => WebAppInfo::class,
];
}

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

namespace Longman\TelegramBot\Entities\PaidMedia;

use Longman\TelegramBot\Entities\Entity;

/**
* Class PaidMedia
*
* This object describes the paid media.
*
* @link https://core.telegram.org/bots/api#paidmedia
*
* @method string getType() Type of the paid media
*/
abstract class PaidMedia extends Entity
{
/**
* {@inheritdoc}
*/
public static function getFactory($data)
{
$type = $data['type'] ?? null;
switch ($type) {
case 'preview':
return new PaidMediaPreview($data);
case 'photo':
return new PaidMediaPhoto($data);
case 'video':
return new PaidMediaVideo($data);
default:
// return new static($data);
// throw new TelegramException('Unsupported paid media type: ' . $type);
// Return a base PaidMedia object or handle as an error
return new class($data) extends PaidMedia { protected function subEntities(): array { return [];}};
}
}
}
28 changes: 28 additions & 0 deletions src/Entities/PaidMedia/PaidMediaPhoto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Longman\TelegramBot\Entities\PaidMedia;

use Longman\TelegramBot\Entities\PhotoSize;

/**
* Class PaidMediaPhoto
*
* The paid media is a photo.
*
* @link https://core.telegram.org/bots/api#paidmediaphoto
*
* @method string getType() Type of the paid media, always “photo”
* @method PhotoSize[] getPhoto() The photo
*
* @method $this setType(string $type) Type of the paid media, always “photo”
* @method $this setPhoto(PhotoSize[] $photo) The photo
*/
class PaidMediaPhoto extends PaidMedia
{
protected function subEntities(): array
{
return [
'photo' => [PhotoSize::class],
];
}
}
30 changes: 30 additions & 0 deletions src/Entities/PaidMedia/PaidMediaPreview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Longman\TelegramBot\Entities\PaidMedia;

use Longman\TelegramBot\Entities\PhotoSize;

/**
* Class PaidMediaPreview
*
* The paid media is a preview of a media album.
*
* @link https://core.telegram.org/bots/api#paidmediapreview
*
* @method string getType() Type of the paid media, always “preview”
* @method int getWidth() Optional. Media width as defined by the sender
* @method int getHeight() Optional. Media height as defined by the sender
* @method int getDuration() Optional. Duration of the media in seconds as defined by the sender
*
* @method $this setType(string $type) Type of the paid media, always “preview”
* @method $this setWidth(int $width) Optional. Media width as defined by the sender
* @method $this setHeight(int $height) Optional. Media height as defined by the sender
* @method $this setDuration(int $duration) Optional. Duration of the media in seconds as defined by the sender
*/
class PaidMediaPreview extends PaidMedia
{
protected function subEntities(): array
{
return [];
}
}
29 changes: 29 additions & 0 deletions src/Entities/PaidMedia/PaidMediaVideo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Longman\TelegramBot\Entities\PaidMedia;

use Longman\TelegramBot\Entities\PhotoSize;
use Longman\TelegramBot\Entities\Video;

/**
* Class PaidMediaVideo
*
* The paid media is a video.
*
* @link https://core.telegram.org/bots/api#paidmediavideo
*
* @method string getType() Type of the paid media, always “video”
* @method Video getVideo() The video
*
* @method $this setType(string $type) Type of the paid media, always “video”
* @method $this setVideo(Video $video) The video
*/
class PaidMediaVideo extends PaidMedia
{
protected function subEntities(): array
{
return [
'video' => Video::class,
];
}
}
28 changes: 28 additions & 0 deletions src/Entities/PaidMediaInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Longman\TelegramBot\Entities;

use Longman\TelegramBot\Entities\PaidMedia\PaidMedia;

/**
* Class PaidMediaInfo
*
* Describes the paid media.
*
* @link https://core.telegram.org/bots/api#paidmediainfo
*
* @method int getStarCount() The number of Telegram Stars that must be paid to buy access to the media
* @method PaidMedia[] getPaidMedia() The paid media
*
* @method $this setStarCount(int $starCount) The number of Telegram Stars that must be paid to buy access to the media
* @method $this setPaidMedia(PaidMedia[] $paidMedia) The paid media
*/
class PaidMediaInfo extends Entity
{
protected function subEntities(): array
{
return [
'paid_media' => [PaidMedia::class],
];
}
}
35 changes: 35 additions & 0 deletions src/Entities/StarTransaction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Longman\TelegramBot\Entities;

use Longman\TelegramBot\Entities\User;

/**
* Class StarTransaction
*
* Describes a Telegram Star transaction.
*
* @link https://core.telegram.org/bots/api#startransaction
*
* @method string getId() Unique identifier of the transaction. Coincides with the identifer of the original transaction for refund transactions.
* @method int getAmount() Number of Telegram Stars transferred by the transaction
* @method int getDate() Date the transaction was created in Unix time
* @method User getSource() Optional. Source of the transaction. Can be a user, a bot, or an app. Null for refund transactions.
* @method User getReceiver() Optional. Receiver of the transaction. Can be a user, a bot, or an app. Null for refund transactions.
*
* @method $this setId(string $id) Unique identifier of the transaction. Coincides with the identifer of the original transaction for refund transactions.
* @method $this setAmount(int $amount) Number of Telegram Stars transferred by the transaction
* @method $this setDate(int $date) Date the transaction was created in Unix time
* @method $this setSource(User $source) Optional. Source of the transaction. Can be a user, a bot, or an app. Null for refund transactions.
* @method $this setReceiver(User $receiver) Optional. Receiver of the transaction. Can be a user, a bot, or an app. Null for refund transactions.
*/
class StarTransaction extends Entity
{
protected function subEntities(): array
{
return [
'source' => User::class,
'receiver' => User::class,
];
}
}
24 changes: 24 additions & 0 deletions src/Entities/StarTransactions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Longman\TelegramBot\Entities;

/**
* Class StarTransactions
*
* Contains a list of Telegram Star transactions.
*
* @link https://core.telegram.org/bots/api#startransactions
*
* @method StarTransaction[] getTransactions() The list of transactions
*
* @method $this setTransactions(StarTransaction[] $transactions) The list of transactions
*/
class StarTransactions extends Entity
{
protected function subEntities(): array
{
return [
'transactions' => [StarTransaction::class],
];
}
}
3 changes: 3 additions & 0 deletions src/Entities/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* @method Message getBusinessMessage() Optional. New message from a connected business account
* @method Message getEditedBusinessMessage() Optional. New version of a message from a connected business account
* @method BusinessMessagesDeleted getDeletedBusinessMessages() Optional. Messages were deleted from a connected business account
* @method StarTransaction getTransaction() Optional. New incoming transaction; for bots only
*/
class Update extends Entity
{
Expand All @@ -67,6 +68,7 @@ class Update extends Entity
public const TYPE_BUSINESS_MESSAGE = 'business_message';
public const TYPE_EDITED_BUSINESS_MESSAGE = 'edited_business_message';
public const TYPE_DELETED_BUSINESS_MESSAGES = 'deleted_business_messages';
public const TYPE_TRANSACTION = 'transaction';

/**
* {@inheritdoc}
Expand Down Expand Up @@ -96,6 +98,7 @@ protected function subEntities(): array
self::TYPE_BUSINESS_MESSAGE => Message::class,
self::TYPE_EDITED_BUSINESS_MESSAGE => Message::class,
self::TYPE_DELETED_BUSINESS_MESSAGES => BusinessMessagesDeleted::class,
self::TYPE_TRANSACTION => StarTransaction::class,
];
}

Expand Down
3 changes: 3 additions & 0 deletions src/Entities/WebAppInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
* @method string getUrl() An HTTPS URL of a Web App to be opened with additional data as specified in Initializing Web Apps
*
* @method $this setUrl(string $url) An HTTPS URL of a Web App to be opened with additional data as specified in Initializing Web Apps
*
* @method bool getAllowWritingToPm() Optional. If true, a Web App can be opened from a link pressed in a bot's message always in full size, even if the Web App is not designed to support full size layout. Ignored for inline keyboard buttons.
* @method $this setAllowWritingToPm(bool $allowWritingToPm) Optional. If true, a Web App can be opened from a link pressed in a bot's message always in full size, even if the Web App is not designed to support full size layout. Ignored for inline keyboard buttons.
*/
class WebAppInfo extends Entity
{
Expand Down
66 changes: 62 additions & 4 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
* @method static ServerResponse getChatMenuButton(array $data) Use this method to get the current value of the bot's menu button in a private chat, or the default menu button. Returns MenuButton on success.
* @method static ServerResponse setMyDefaultAdministratorRights(array $data) Use this method to change the default administrator rights requested by the bot when it's added as an administrator to groups or channels. These rights will be suggested to users, but they are are free to modify the list before adding the bot. Returns True on success.
* @method static ServerResponse getMyDefaultAdministratorRights(array $data) Use this method to get the current default administrator rights of the bot. Returns ChatAdministratorRights on success.
* @method static ServerResponse editMessageText(array $data) Use this method to edit text and game messages sent by the bot or via the bot (for inline bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
* @method static ServerResponse editMessageText(array $data) Use this method to edit text and game messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned.
* @method static ServerResponse editMessageCaption(array $data) Use this method to edit captions of messages sent by the bot or via the bot (for inline bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
* @method static ServerResponse editMessageMedia(array $data) Use this method to edit audio, document, photo, or video messages. On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.
* @method static ServerResponse editMessageReplyMarkup(array $data) Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
Expand Down Expand Up @@ -329,6 +329,8 @@ class Request
'setGameScore',
'getGameHighScores',
'getBusinessConnection',
'sendPaidMedia',
'getStarTransactions',
];

/**
Expand Down Expand Up @@ -815,11 +817,25 @@ private static function ensureValidAction(string $action): void
*
* @link https://core.telegram.org/bots/api#sendmessage
*
* @todo Splitting formatted text may break the message.
*
* @param array $data
* @param array $data {
* @var int|string $chat_id
* @var string $text
* @var string $parse_mode
* @var Entities\MessageEntity[] $entities
* @var Entities\LinkPreviewOptions $link_preview_options Optional. Link preview generation options for the message
* @var bool $disable_notification
* @var bool $protect_content
* @var int $reply_to_message_id
* @var bool $allow_sending_without_reply
* @var Entities\InlineKeyboard|Entities\ReplyKeyboard|Entities\ReplyKeyboardRemove|Entities\ForceReply $reply_markup
* @var string $business_connection_id Optional. Unique identifier of the business connection on behalf of which the message will be sent
* @var int $message_thread_id Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @var bool $disable_web_page_preview Optional. Disables link previews for links in this message (deprecated, use link_preview_options instead)
* }
* @param array|null $extras
*
* @todo Splitting formatted text may break the message.
*
* @return ServerResponse
* @throws TelegramException
*/
Expand Down Expand Up @@ -1007,4 +1023,46 @@ public static function kickChatMember(array $data = []): ServerResponse
{
return static::banChatMember($data);
}

/**
* Use this method to send paid media. On success, the sent Message is returned.
*
* @link https://core.telegram.org/bots/api#sendpaidmedia
*
* @param array $data
* @return ServerResponse
* @throws TelegramException
*/
public static function sendPaidMedia(array $data): ServerResponse
{
return static::send('sendPaidMedia', $data);
}

/**
* Returns the bot's Telegram Star transactions in chronological order.
*
* @link https://core.telegram.org/bots/api#getstartransactions
*
* @param array $data
* @return ServerResponse
* @throws TelegramException
*/
public static function getStarTransactions(array $data): ServerResponse
{
return static::send('getStarTransactions', $data);
}

/**
* Use this method to change the bot's menu button in a private chat, or the default menu button.
*
* @link https://core.telegram.org/bots/api#setchatmenubutton
*
* @param array $data
* @return ServerResponse
* @throws TelegramException
*/
public static function setChatMenuButton(array $data): ServerResponse
{
return static::send('setChatMenuButton', $data);
}
}
2 changes: 1 addition & 1 deletion src/Telegram.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Telegram
*
* @var string
*/
protected $version = '1.0.4';
protected $version = '1.0.5';

/** @var PredisClient|null */
private $redis_connection;
Expand Down