Add EditMessageText
This commit is contained in:
parent
e0543413e3
commit
d0519193eb
2 changed files with 88 additions and 0 deletions
|
@ -27,6 +27,7 @@
|
|||
use TgBotLib\Methods\EditChatSubscriptionInviteLink;
|
||||
use TgBotLib\Methods\EditForumTopic;
|
||||
use TgBotLib\Methods\EditGeneralForumTopic;
|
||||
use TgBotLib\Methods\EditMessageText;
|
||||
use TgBotLib\Methods\ExportChatInviteLink;
|
||||
use TgBotLib\Methods\ForwardMessage;
|
||||
use TgBotLib\Methods\ForwardMessages;
|
||||
|
@ -186,6 +187,7 @@
|
|||
case GET_CHAT_MENU_BUTTON = 'getChatMenuButton';
|
||||
case SET_MY_DEFAULT_ADMINISTRATOR_RIGHTS = 'setMyDefaultAdministratorRights';
|
||||
case GET_MY_DEFAULT_ADMINISTRATOR_RIGHTS = 'getMyDefaultAdministratorRights';
|
||||
case EDIT_MESSAGE_TEXT = 'editMessageText';
|
||||
|
||||
/**
|
||||
* Executes a command on the provided bot with the given parameters.
|
||||
|
@ -288,6 +290,7 @@
|
|||
self::GET_CHAT_MENU_BUTTON => GetChatMenuButton::execute($bot, $parameters),
|
||||
self::SET_MY_DEFAULT_ADMINISTRATOR_RIGHTS => SetMyDefaultAdministratorRights::execute($bot, $parameters),
|
||||
self::GET_MY_DEFAULT_ADMINISTRATOR_RIGHTS => GetMyDefaultAdministratorRights::execute($bot, $parameters),
|
||||
self::EDIT_MESSAGE_TEXT => EditMessageText::execute($bot, $parameters),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
85
src/TgBotLib/Methods/EditMessageText.php
Normal file
85
src/TgBotLib/Methods/EditMessageText.php
Normal file
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
namespace TgBotLib\Methods;
|
||||
|
||||
use TgBotLib\Abstracts\Method;
|
||||
use TgBotLib\Bot;
|
||||
use TgBotLib\Enums\Methods;
|
||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||
use TgBotLib\Objects\Message;
|
||||
use TgBotLib\Objects\MessageEntity;
|
||||
|
||||
class EditMessageText extends Method
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function execute(Bot $bot, array $parameters = []): Message
|
||||
{
|
||||
if(isset($parameters['entities']) && is_array($parameters['entities']))
|
||||
{
|
||||
$entities = [];
|
||||
|
||||
foreach($parameters['entities'] as $entity)
|
||||
{
|
||||
if($entity instanceof MessageEntity)
|
||||
{
|
||||
$entities[] = $entity->toArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
$entities[] = $entity;
|
||||
}
|
||||
}
|
||||
|
||||
$parameters['entities'] = $entities;
|
||||
}
|
||||
|
||||
if (isset($parameters['reply_markup']))
|
||||
{
|
||||
if ($parameters['reply_markup'] instanceof ObjectTypeInterface)
|
||||
{
|
||||
$parameters['reply_markup'] = json_encode($parameters['reply_markup']->toArray());
|
||||
}
|
||||
elseif (is_array($parameters['reply_markup']))
|
||||
{
|
||||
$parameters['reply_markup'] = json_encode($parameters['reply_markup']);
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($parameters['link_preview_options']) && $parameters['link_preview_options'] instanceof ObjectTypeInterface)
|
||||
{
|
||||
$parameters['link_preview_options'] = $parameters['link_preview_options']->toArray();
|
||||
}
|
||||
|
||||
return Message::fromArray(self::executeCurl(self::buildPost($bot, Methods::EDIT_MESSAGE_TEXT->value, $parameters)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function getRequiredParameters(): ?array
|
||||
{
|
||||
return [
|
||||
'text'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function getOptionalParameters(): ?array
|
||||
{
|
||||
return [
|
||||
'business_connection_id',
|
||||
'chat_id',
|
||||
'message_id',
|
||||
'inline_message_id',
|
||||
'parse_mode',
|
||||
'entities',
|
||||
'link_preview_options',
|
||||
'reply_markup'
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue