|
|
|
@ -10,21 +10,42 @@
|
|
|
|
|
namespace TgBotLib;
|
|
|
|
|
|
|
|
|
|
use InvalidArgumentException;
|
|
|
|
|
use LogLib\Log;
|
|
|
|
|
use ReflectionClass;
|
|
|
|
|
use TgBotLib\Abstracts\Method;
|
|
|
|
|
use TgBotLib\Enums\Methods;
|
|
|
|
|
use TgBotLib\Enums\Types\ChatActionType;
|
|
|
|
|
use TgBotLib\Enums\Types\ParseMode;
|
|
|
|
|
use TgBotLib\Exceptions\TelegramException;
|
|
|
|
|
use TgBotLib\Objects\BotCommand;
|
|
|
|
|
use TgBotLib\Objects\BotCommandScope;
|
|
|
|
|
use TgBotLib\Objects\BotDescription;
|
|
|
|
|
use TgBotLib\Objects\BotName;
|
|
|
|
|
use TgBotLib\Objects\BotShortDescription;
|
|
|
|
|
use TgBotLib\Objects\BusinessConnection;
|
|
|
|
|
use TgBotLib\Objects\ChatFullInfo;
|
|
|
|
|
use TgBotLib\Objects\ChatInviteLink;
|
|
|
|
|
use TgBotLib\Objects\ChatMember;
|
|
|
|
|
use TgBotLib\Objects\ChatPermissions;
|
|
|
|
|
use TgBotLib\Objects\File;
|
|
|
|
|
use TgBotLib\Objects\ForceReply;
|
|
|
|
|
use TgBotLib\Objects\ForumTopic;
|
|
|
|
|
use TgBotLib\Objects\InlineKeyboardMarkup;
|
|
|
|
|
use TgBotLib\Objects\InputMedia;
|
|
|
|
|
use TgBotLib\Objects\InputPollOption;
|
|
|
|
|
use TgBotLib\Objects\LinkPreviewOptions;
|
|
|
|
|
use TgBotLib\Objects\MenuButton;
|
|
|
|
|
use TgBotLib\Objects\Message;
|
|
|
|
|
use TgBotLib\Objects\MessageEntity;
|
|
|
|
|
use TgBotLib\Objects\MessageId;
|
|
|
|
|
use TgBotLib\Objects\ReactionType;
|
|
|
|
|
use TgBotLib\Objects\ReplyKeyboardMarkup;
|
|
|
|
|
use TgBotLib\Objects\ReplyKeyboardRemove;
|
|
|
|
|
use TgBotLib\Objects\ReplyParameters;
|
|
|
|
|
use TgBotLib\Objects\Stickers\Sticker;
|
|
|
|
|
use TgBotLib\Objects\User;
|
|
|
|
|
use TgBotLib\Objects\UserChatBoosts;
|
|
|
|
|
use TgBotLib\Objects\UserProfilePhotos;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @method User getMe() A simple method for testing your bot's authentication token. Requires no parameters. Returns basic information about the bot in form of a User object.
|
|
|
|
@ -38,11 +59,83 @@
|
|
|
|
|
* @method Message sendPhoto(string|int $chat_id, string $photo, ?string $business_connection_id=null, ?int $message_thread_id=null, ?string $caption=null, ?string|ParseMode $parse_mode=null, ?MessageEntity[] $caption_entities=null, ?bool $show_caption_above_media=null, ?bool $disable_notification=null, ?bool $protect_content=null, ?string $message_effect_id=null, ?ReplyParameters $reply_parameters=null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup=null) Use this method to send photos. On success, the sent Message is returned.
|
|
|
|
|
* @method Message sendAudio(string|int $chat_id, string $audio, ?string $business_connection_id=null, ?int $message_thread_id=null, ?string $caption=null, ?string|ParseMode $parse_mode=null, ?MessageEntity[] $caption_entities=null, ?int $duration=null, ?string $performer=null, ?string $title=null, ?string $thumb=null, ?bool $disable_notification=null, ?bool $protect_content=null, ?string $message_effect_id=null, ?ReplyParameters $reply_parameters=null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup=null) Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .MP3 or .M4A format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.
|
|
|
|
|
* @method Message sendDocument(string|int $chat_id, string $document, ?int $message_thread_id=null, ?string $thumbnail=null, ?string $caption=null, ?string|ParseMode $parse_mode=null, ?MessageEntity[] $caption_entities=null, ?bool $disable_content_type_detection=null, ?bool $disable_notification=null, ?bool $protect_content=null, ?string $message_effect_id=null, ?ReplyParameters $reply_parameters=null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup=null) Use this method to send general files. On success, the sent Message is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.
|
|
|
|
|
* @method Message sendVideo(string|int $chat_id, string $video, ?int $business_connection_id=null, ?int $message_thread_id=null, ?int $duration=null, ?int $width=null, ?int $height=null, ?string $thumbnail=null, ?string $caption=null, ?string|ParseMode $parse_mode=null, ?MessageEntity[] $caption_entities=null, ?bool $show_caption_above_media=null, ?bool $has_spoiler=null, ?bool $supports_streaming=null, ?bool $disable_notification=null, ?bool $protect_content=null, ?string $message_effect_id=null, ?ReplyParameters $reply_parameters=null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup=null) Use this method to send video files, Telegram clients support MPEG4 videos (other formats may be sent as Document). On success, the sent Message is returned. Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.
|
|
|
|
|
* @method Message sendAnimation(string|int $chat_id, string $animation, ?string $business_connection_id=null, ?int $message_thread_id=null, ?int $duration=null, ?int $width=null, ?int $height=null, ?string $thumbnail=null, ?string $caption=null, ?string|ParseMode $parse_mode=null, ?MessageEntity[] $caption_entities=null, ?bool $show_caption_above_media=null, ?bool $has_spoiler=null, ?bool $disable_notification=null, ?bool $protect_content=null, ?string $message_effect_id=null, ?ReplyParameters $reply_parameters=null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup=null) Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future.
|
|
|
|
|
* @method Message sendVoice(string|int $chat_id, string $voice, ?string $business_connection_id=null, ?int $message_thread_id=null, ?string $caption=null, ?string|ParseMode $parse_mode=null, ?MessageEntity[] $caption_entities=null, ?int $duration=null, ?bool $disable_notification=null, ?bool $protect_content=null, ?string $message_effect_id=null, ?ReplyParameters $reply_parameters=null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup=null) Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .OGG file encoded with OPUS, or in .MP3 format, or in .M4A format (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.
|
|
|
|
|
* @method Message sendVideoNote(string|int $chat_id, string $video_note, ?string $business_connection_id=null, ?int $message_thread_id=null, ?int $duration=null, ?int $length=null, ?string $thumbnail=null, ?bool $disable_notification=null, ?bool $protect_content=null, ?string $message_effect_id=null, ?ReplyParameters $reply_parameters=null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup=null) As of v.4.0, Telegram clients support rounded square MPEG4 videos of up to 1 minute long. Use this method to send video messages. On success, the sent Message is returned.
|
|
|
|
|
* @method Message sendPaidMedia(string|int $chat_id, int $star_count, array $media, ?string $business_connection_id=null, ?string $payload=null, ?string $caption=null, ?string|ParseMode $parse_mode=null, ?MessageEntity[] $caption_entities=null, ?bool $show_caption_above_media=null, ?bool $disable_notification=null, ?bool $protect_content=null, ?ReplyParameters $reply_parameters=null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup=null) Use this method to send paid media. On success, the sent Message is returned.
|
|
|
|
|
* @method Message[] sendMediaGroup(string|int $chat_id, InputMedia\InputMediaAudio[]|InputMedia\InputMediaDocument[]|InputMedia\InputMediaPhoto[]|InputMedia\InputMediaVideo[] $media, ?string $business_connection_id=null, ?int $message_thread_id=null, ?bool $disable_notification=null, ?bool $protect_content=null, ?string $message_effect_id=null, ?ReplyParameters $reply_parameters=null) Use this method to send a group of photos, videos, documents or audios as an album. Documents and audio files can be only grouped in an album with messages of the same type. On success, an array of Messages that were sent is returned.
|
|
|
|
|
* @method Message sendLocation(string|int $chat_id, float $latitude, float $longitude, ?string $business_connection_id=null, ?int $message_thread_id=null, ?float $horizontal_accuracy=null, ?int $live_period=null, ?int $heading=null, ?int $proximity_alert_radius=null, ?bool $disable_notification=null, ?bool $protect_content=null, ?string $message_effect_id=null, ?ReplyParameters $reply_parameters=null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup=null) Use this method to send point on the map. On success, the sent Message is returned.
|
|
|
|
|
* @method Message sendVenue(string|int $chat_id, float $latitude, float $longitude, string $title, string $address, ?string $business_connection_id=null, ?int $message_thread_id=null, ?string $foursquare_id=null, ?string $foursquare_type=null, ?string $google_place_id=null, ?string $google_place_type=null, ?bool $disable_notification=null, ?bool $protect_content=null, ?string $message_effect_id=null, ?ReplyParameters $reply_parameters=null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup=null) Use this method to send information about a venue. On success, the sent Message is returned.
|
|
|
|
|
* @method Message sendContact(string|int $chat_id, string $phone_number, string $first_name, ?string $last_name=null, ?string $vcard=null, ?string $business_connection_id=null, ?int $message_thread_id=null, ?bool $disable_notification=null, ?bool $protect_content=null, ?string $message_effect_id=null, ?ReplyParameters $reply_parameters=null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup=null) Use this method to send phone contacts. On success, the sent Message is returned.
|
|
|
|
|
* @method Message sendPoll(string|int $chat_id, string $question, InputPollOption[] $options, ?string $business_connection_id=null, ?int $message_thread_id=null, string|ParseMode|null $question_parse_mode=null, ?MessageEntity[] $question_entities=null, ?bool $is_anonymous=null, ?string $type=null, ?bool $allows_multiple_answers=null, ?int $correct_option_id=null, ?string $explanation=null, string|ParseMode|null $explanation_parse_mode=null, ?array $explanation_entities=null, ?int $open_period=null, ?int $close_date=null, ?bool $is_closed=null, ?bool $disable_notification=null, ?bool $protect_content=null, ?string $message_effect_id=null, ?ReplyParameters $reply_parameters=null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup=null) Use this method to send a native poll. On success, the sent Message is returned.
|
|
|
|
|
* @method Message sendDice(string|int $chat_id, ?string $business_connection_id=null, ?int $message_thread_id=null, ?string $emoji=null, ?bool $disable_notification=null, ?bool $protect_content=null, ?string $message_effect_id=null, ?ReplyParameters $reply_parameters=null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup=null) Use this method to send an animated emoji that will display a random value. On success, the sent Message is returned.
|
|
|
|
|
* @method bool sendChatAction(string|int $chat_id, ChatActionType|string $action, ?string $business_connection_id=null, ?int $message_thread_id=null) Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Returns True on success.
|
|
|
|
|
* @method bool setMessageReaction(string|int $chat_id, int $message_id, ?ReactionType[] $reaction=null, ?bool $is_big=null) Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Bots can't use paid reactions. Returns True on success.
|
|
|
|
|
* @method UserProfilePhotos getUserProfilePhotos(int $user_id, ?int $offset=null, ?int $limit=null) Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.
|
|
|
|
|
* @method File getFile(string $file_id) Use this method to get basic information about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. On success, a File object is returned. The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>, where <file_path> is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile again.
|
|
|
|
|
* @method bool banChatMember(string|int $chat_id, int $user_id, ?int $until_date=null, ?bool $revoke_messages=null) Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
|
|
|
|
|
* @method bool unbanChatMember(string|int $chat_id, int $user_id, ?bool $only_if_banned=null) Use this method to unban a previously banned user in a supergroup or channel. The user will not return to the group or channel automatically, but will be able to join via link, etc. The bot must be an administrator for this to work. By default, this method guarantees that after the call the user is not a member of the chat, but will be able to join it. So if the user is a member of the chat they will also be removed from the chat. If you don't want this, use the parameter only_if_banned. Returns True on success.
|
|
|
|
|
* @method bool restrictChatMember(string|int $chat_id, int $user_id, ChatPermissions $permissions, ?bool $use_independent_chat_permissions=null, ?int $until_date=null) Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate administrator rights. Pass True for all permissions to lift restrictions from a user. Returns True on success.
|
|
|
|
|
* @method bool promoteChatMember(string|int $chat_id, int $user_id, ?bool $is_anonymous=null, ?bool $can_manage_chat=null, ?bool $can_delete_messages=null, ?bool $can_manage_video_chats=null, ?bool $can_restrict_members=null, ?bool $can_promote_members=null, ?bool $can_change_info=null, ?bool $can_invite_users=null, ?bool $can_post_stories=null, ?bool $can_edit_stories=null, ?bool $can_delete_stories=null, ?bool $can_post_messages=null, ?bool $can_edit_messages=null, ?bool $can_pin_messages=null, ?bool $can_manage_topics=null) Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Pass False for all boolean parameters to demote a user. Returns True on success.
|
|
|
|
|
* @method bool setChatAdministratorCustomTitle(string|int $chat_id, int $user_id, string $custom_title) Use this method to set a custom title for an administrator in a supergroup promoted by the bot. Returns True on success.
|
|
|
|
|
* @method bool banChatSenderChat(string|int $chat_id, int $sender_chat_id) Use this method to ban a channel chat in a supergroup or a channel. Until the chat is unbanned, the owner of the banned chat won't be able to send messages on behalf of any of their channels. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.
|
|
|
|
|
* @method bool unbanChatSenderChat(string|int $chat_id, int $sender_chat_id) Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns True on success.
|
|
|
|
|
* @method bool setChatPermissions(string|int $chat_id, ChatPermissions $permissions, ?bool $use_independent_chat_permissions=null) Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members administrator rights. Returns True on success.
|
|
|
|
|
* @method string exportChatInviteLink(string|int $chat_id) Use this method to generate a new primary invite link for a chat; any previously generated primary link is revoked. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the new invite link as String on success.
|
|
|
|
|
* @method ChatInviteLink createChatInviteLink(string|int $chat_id, ?string $name=null, ?int $expire_date=null, ?int $member_limit=null, ?bool $creates_join_request=null) Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. The link can be revoked using the method revokeChatInviteLink. Returns the new invite link as ChatInviteLink object.
|
|
|
|
|
* @method ChatInviteLink editChatInviteLink(string|int $chat_id, string $invite_link, ?string $name=null, ?int $expire_date=null, ?int $member_limit=null, ?bool $creates_join_request=null) Use this method to edit a non-primary invite link created by the bot. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the edited invite link as a ChatInviteLink object.
|
|
|
|
|
* @method ChatInviteLink createChatSubscriptionInviteLink(string|int $chat_id, int $subscription_period, int $subscription_price, ?string $name=null,) Use this method to create a subscription invite link for a channel chat. The bot must have the can_invite_users administrator rights. The link can be edited using the method editChatSubscriptionInviteLink or revoked using the method revokeChatInviteLink. Returns the new invite link as a ChatInviteLink object.
|
|
|
|
|
* @method ChatInviteLink editChatSubscriptionInviteLink(string|int $chat_id, string $invite_link, ?string $name=null) Use this method to edit a subscription invite link created by the bot. The bot must have the can_invite_users administrator rights. Returns the edited invite link as a ChatInviteLink object.
|
|
|
|
|
* @method ChatInviteLink revokeChatInviteLink(string|int $chat_id, string $invite_link) Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is automatically generated. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the revoked invite link as ChatInviteLink object.
|
|
|
|
|
* @method bool approveChatJoinRequest(string|int $chat_id, int $user_id) Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. Returns True on success.
|
|
|
|
|
* @method bool setChatPhoto(string|int $chat_id, string $photo) Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
|
|
|
|
|
* @method bool deleteChatPhoto(string|int $chat_id) Use this method to delete a chat photo. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
|
|
|
|
|
* @method bool setChatTitle(string|int $chat_id, string $title) Use this method to change the title of a chat. Titles can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
|
|
|
|
|
* @method bool setChatDescription(string|int $chat_id, string $description = null) Use this method to change the description of a group, a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
|
|
|
|
|
* @method bool pinChatMessage(string|int $chat_id, int $message_id, string $business_connection_id = null, bool $disable_notification = null) Use this method to add a message to the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. Returns True on success.
|
|
|
|
|
* @method bool unpinChatMessage(string|int $chat_id, string $business_connection_id = null, int $message_id = null) Use this method to remove a message from the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. Returns True on success.
|
|
|
|
|
* @method bool unpinAllChatMessages(string|int $chat_id) Use this method to clear the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. Returns True on success.
|
|
|
|
|
* @method bool leaveChat(string|int $chat_id) Use this method for your bot to leave a group, supergroup or channel. Returns True on success.
|
|
|
|
|
* @method ChatFullInfo getChat(string|int $chat_id) Use this method to get up-to-date information about the chat. Returns a ChatFullInfo object on success.
|
|
|
|
|
* @method ChatMember[] getChatAdministrators(string|int $chat_id) Use this method to get a list of administrators in a chat, which aren't bots. Returns an array of ChatMember objects.
|
|
|
|
|
* @method int getChatMemberCount(string|int $chat_id) Use this method to get the number of members in a chat. Returns int on success.
|
|
|
|
|
* @method ChatMember getChatMember(string|int $chat_id, int $user_id) Use this method to get information about a member of a chat. The method is only guaranteed to work for other users if the bot is an administrator in the chat. Returns a ChatMember object on success.
|
|
|
|
|
* @method bool setChatStickerSet(string|int $chat_id, string $sticker_set_name) Use this method to set a new group sticker set for a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success.
|
|
|
|
|
* @method bool deleteChatStickerSet(string|int $chat_id) Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success.
|
|
|
|
|
* @method Sticker[] getForumTopicIconStickers() Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user. Requires no parameters. Returns an array of Sticker objects.
|
|
|
|
|
* @method ForumTopic createForumTopic(string|int $chat_id, string $name, int $icon_color = null, string $icon_custom_emoji_id = null) Use this method to create a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns information about the created topic as a ForumTopic object.
|
|
|
|
|
* @method bool editForumTopic(string|int $chat_id, int $message_thread_id, string $name = null, string $icon_custom_emoji_id = null) Use this method to edit the name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
|
|
|
|
|
* @method bool closeForumTopic(string|int $chat_id, int $message_thread_id) Use this method to close an open topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
|
|
|
|
|
* @method bool reopenForumTopic(string|int $chat_id, int $message_thread_id) Use this method to reopen a closed topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
|
|
|
|
|
* @method bool deleteForumTopic(string|int $chat_id, int $message_thread_id) Use this method to delete a forum topic along with all its messages in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_delete_messages administrator rights. Returns True on success.
|
|
|
|
|
* @method bool unpinAllForumTopicMessages(string|int $chat_id, int $message_thread_id) Use this method to clear the list of pinned messages in a forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success.
|
|
|
|
|
* @method bool editGeneralForumTopic(string|int $chat_id, string $name) Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.
|
|
|
|
|
* @method bool closeGeneralForumTopic(string|int $chat_id) Use this method to close an open 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.
|
|
|
|
|
* @method bool reopenGeneralForumTopic(string|int $chat_id) Use this method to reopen a closed 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. The topic will be automatically unhidden if it was hidden. Returns True on success.
|
|
|
|
|
* @method bool hideGeneralForumTopic(string|int $chat_id) Use this method to hide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. The topic will be automatically closed if it was open. Returns True on success.
|
|
|
|
|
* @method bool unhideGeneralForumTopic(string|int $chat_id) Use this method to unhide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.
|
|
|
|
|
* @method bool unpinAllGeneralForumTopicMessages(string|int $chat_id) Use this method to clear the list of pinned messages in a General forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success.
|
|
|
|
|
* @method bool answerCallbackQuery(string $callback_query_id, string $text = null, bool $show_alert = false, string $url = null, int $cache_time = 0) Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On success, True is returned. Alternatively, the user can be redirected to the specified Game URL. For this option to work, you must first create a game for your bot via @BotFather and accept the terms. Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.
|
|
|
|
|
* @method UserChatBoosts getUserChatBoosts(string|int $chat_id, int $user_id) Use this method to get the list of boosts added to a chat by a user. Requires administrator rights in the chat. Returns a UserChatBoosts object.
|
|
|
|
|
* @method BusinessConnection getBusinessConnection(string $business_connection_id) Use this method to get information about the connection of the bot with a business account. Returns a BusinessConnection object on success.
|
|
|
|
|
* @method bool setMyCommands(array $commands, BotCommandScope $scope=null, string $language_code=null) Use this method to change the list of the bot's commands. Returns True on success.
|
|
|
|
|
* @method bool deleteMyCommands(BotCommandScope $scope = null, string $language_code = null) Use this method to delete the list of the bot's commands for the given scope and user language. After deletion, higher level commands will be shown to affected users. Returns True on success.
|
|
|
|
|
* @method BotCommand[] getMyCommands(BotCommandScope $scope = null, string $language_code = "") Use this method to get the current list of the bot's commands for the given scope and user language. Returns an array of BotCommand objects. If commands aren't set, an empty list is returned.
|
|
|
|
|
* @method bool setMyName(string $name = "", string $language_code = "") Use this method to change the bot's name. Returns True on success.
|
|
|
|
|
* @method BotName getMyName(string $language_code) Use this method to get the current bot name for the given user language. Returns BotName on success.
|
|
|
|
|
* @method bool setMyDescription(?string $description=null, ?string $language_code=null) Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty. Returns True on success.
|
|
|
|
|
* @method BotDescription getMyDescription(?string $language_code=null) Use this method to get the current bot description for the given user language. Returns BotDescription on success.
|
|
|
|
|
* @method bool setMyShortDescription(string $short_description , string $language_code = "") Use this method to change the bot's short description, which is shown on the bot's profile page and is sent together with the link when users share the bot. Returns True on success.
|
|
|
|
|
* @method BotShortDescription getMyShortDescription(string $language_code) Use this method to get the current bot short description for the given user language. Returns BotShortDescription on success.
|
|
|
|
|
* @method bool setChatMenuButton(int $chat_id=null, MenuButton $menu_button=null) Use this method to change the bot's menu button in a private chat, or the default menu button. Returns True on success.
|
|
|
|
|
* @throws TelegramException if the method execution fails.
|
|
|
|
|
*/
|
|
|
|
|
class Bot
|
|
|
|
|
{
|
|
|
|
|
private string $token;
|
|
|
|
|
private string $endpoint;
|
|
|
|
|
private bool $auto_retry;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructs a new Bot instance
|
|
|
|
@ -54,6 +147,7 @@
|
|
|
|
|
{
|
|
|
|
|
$this->token = $token;
|
|
|
|
|
$this->endpoint = $endpoint;
|
|
|
|
|
$this->auto_retry = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -104,6 +198,30 @@
|
|
|
|
|
return $this->endpoint;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the auto-retry flag.
|
|
|
|
|
* If set to true, the bot will automatically retry the request only due to a "Too Many Requests" error.
|
|
|
|
|
* the bot will attempt to parse the amount of time to wait and retry the request, this will make
|
|
|
|
|
* method calls block for a longer period of time than usual if the error persists.
|
|
|
|
|
*
|
|
|
|
|
* @param bool $auto_retry The new auto-retry flag to be set.
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function setAutoRetry(bool $auto_retry): void
|
|
|
|
|
{
|
|
|
|
|
$this->auto_retry = $auto_retry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves the auto-retry flag.
|
|
|
|
|
*
|
|
|
|
|
* @return bool The auto-retry flag
|
|
|
|
|
*/
|
|
|
|
|
public function getAutoRetry(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->auto_retry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sends a request by executing the specified method with the given parameters.
|
|
|
|
|
*
|
|
|
|
@ -120,8 +238,32 @@
|
|
|
|
|
throw new InvalidArgumentException('Invalid method name');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return $method->execute($this, $parameters);
|
|
|
|
|
}
|
|
|
|
|
catch(TelegramException $e)
|
|
|
|
|
{
|
|
|
|
|
if($e->getCode() === 429 && $this->auto_retry)
|
|
|
|
|
{
|
|
|
|
|
if (preg_match('/retry after (\d+)/', $e->getMessage(), $matches))
|
|
|
|
|
{
|
|
|
|
|
$waitTime = (int) $matches[1];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$waitTime = 5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log::warning('net.nosial.tgbotlib', "Too Many Requests error, retrying in {$waitTime} seconds");
|
|
|
|
|
sleep($waitTime);
|
|
|
|
|
|
|
|
|
|
return $method->execute($this, $parameters);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handles all undefined method calls.
|
|
|
|
@ -149,6 +291,7 @@
|
|
|
|
|
* @param string $methodName The method name being called.
|
|
|
|
|
* @param array $arguments The arguments passed to the method.
|
|
|
|
|
* @return array The associative array of parameters.
|
|
|
|
|
* @throws TelegramException
|
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
|
*/
|
|
|
|
|
private function parseArguments(string $methodName, array $arguments): array
|
|
|
|
|