Commit 0d59d04b authored by Armando Lüscher's avatar Armando Lüscher Committed by GitHub

Merge pull request #551 from noplanman/bot_api_3.1

Bot API 3.1
parents 13ffcc1e cce002be
......@@ -6,7 +6,9 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
## [Unreleased]
### Added
- Callbacks can be added to be executed when callback queries are called.
- New Bot API 3.1 changes (#550).
### Changed
- [:exclamation:][unreleased-bc-request-class-refactor] Big refactor of the `Request` class, removing most custom method implementations.
### Deprecated
### Removed
### Fixed
......@@ -122,6 +124,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
### Deprecated
- Move `hideKeyboard` to `removeKeyboard`.
[unreleased-bc-request-class-refactor]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#request-class-refactor
[0.45.0-bc-remove-deprecated-methods]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#remove-deprecated-methods
[0.45.0-bc-chats-params-array]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#chats-params-array
[0.45.0-bc-up-download-directory]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#up-download-directory
......
......@@ -22,6 +22,9 @@ namespace Longman\TelegramBot\Entities;
* @property string $first_name Optional. First name of the other party in a private chat
* @property string $last_name Optional. Last name of the other party in a private chat
* @property bool $all_members_are_administrators Optional. True if a group has ‘All Members Are Admins’ enabled.
* @property ChatPhoto $photo Optional. Chat photo. Returned only in getChat.
* @property string $description Optional. Description, for supergroups and channel chats. Returned only in getChat.
* @property string $invite_link Optional. Chat invite link, for supergroups and channel chats. Returned only in getChat.
* @method int getId() Unique identifier for this chat. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
* @method string getType() Type of chat, can be either "private ", "group", "supergroup" or "channel"
* @method string getTitle() Optional. Title, for channels and group chats
......@@ -29,9 +32,22 @@ namespace Longman\TelegramBot\Entities;
* @method string getFirstName() Optional. First name of the other party in a private chat
* @method string getLastName() Optional. Last name of the other party in a private chat
* @method bool getAllMembersAreAdministrators() Optional. True if a group has ‘All Members Are Admins’ enabled.
* @method ChatPhoto getPhoto() Optional. Chat photo. Returned only in getChat.
* @method string getDescription() Optional. Description, for supergroups and channel chats. Returned only in getChat.
* @method string getInviteLink() Optional. Chat invite link, for supergroups and channel chats. Returned only in getChat.
*/
class Chat extends Entity
{
/**
* {@inheritdoc}
*/
public function subEntities()
{
return [
'photo' => ChatPhoto::class,
];
}
public function __construct($data)
{
parent::__construct($data);
......
......@@ -15,8 +15,22 @@ namespace Longman\TelegramBot\Entities;
*
* @link https://core.telegram.org/bots/api#chatmember
*
* @method User getUser() Information about the user.
* @method string getStatus() The member's status in the chat. Can be "creator", "administrator", "member", "left" or "kicked"
* @method User getUser() Information about the user
* @method string getStatus() The member's status in the chat. Can be “creator”, “administrator”, “member”, “restricted”, “left” or “kicked”
* @method int getUntilDate() Optional. Restricted and kicked only. Date when restrictions will be lifted for this user, unix time
* @method bool getCanBeEdited() Optional. Administrators only. True, if the bot is allowed to edit administrator privileges of that user
* @method bool getCanChangeInfo() Optional. Administrators only. True, if the administrator can change the chat title, photo and other settings
* @method bool getCanPostMessages() Optional. Administrators only. True, if the administrator can post in the channel, channels only
* @method bool getCanEditMessages() Optional. Administrators only. True, if the administrator can edit messages of other users, channels only
* @method bool getCanDeleteMessages() Optional. Administrators only. True, if the administrator can delete messages of other users
* @method bool getCanInviteUsers() Optional. Administrators only. True, if the administrator can invite new users to the chat
* @method bool getCanRestrictMembers() Optional. Administrators only. True, if the administrator can restrict, ban or unban chat members
* @method bool getCanPinMessages() Optional. Administrators only. True, if the administrator can pin messages, supergroups only
* @method bool getCanPromoteMembers() Optional. Administrators only. True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user)
* @method bool getCanSendMessages() Optional. Restricted only. True, if the user can send text messages, contacts, locations and venues
* @method bool getCanSendMediaMessages() Optional. Restricted only. True, if the user can send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages
* @method bool getCanSendOtherMessages() Optional. Restricted only. True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages
* @method bool getCanAddWebPagePreviews() Optional. Restricted only. True, if user may add web page previews to his messages, implies can_send_media_messages
*/
class ChatMember extends Entity
{
......
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
/**
* Class ChatPhoto
*
* @link https://core.telegram.org/bots/api#chatphoto
*
* @method string getSmallFileId() Unique file identifier of small(160x160) chat photo. This file_id can be used only for photo download.
* @method string getBigFileId() Unique file identifier of big(640x640) chat photo. This file_id can be used only for photo download.
*/
class ChatPhoto extends Entity
{
}
......@@ -16,6 +16,51 @@ use Longman\TelegramBot\Entities\File;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class Request
*
* @method static ServerResponse getUpdates(array $data) Use this method to receive incoming updates using long polling (wiki). An Array of Update objects is returned.
* @method static ServerResponse setWebhook(array $data) Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. Returns true.
* @method static ServerResponse deleteWebhook() Use this method to remove webhook integration if you decide to switch back to getUpdates. Returns True on success. Requires no parameters.
* @method static ServerResponse getWebhookInfo() Use this method to get current webhook status. Requires no parameters. On success, returns a WebhookInfo object. If the bot is using getUpdates, will return an object with the url field empty.
* @method static ServerResponse getMe() A simple method for testing your bot's auth token. Requires no parameters. Returns basic information about the bot in form of a User object.
* @method static ServerResponse forwardMessage(array $data) Use this method to forward messages of any kind. On success, the sent Message is returned.
* @method static ServerResponse sendPhoto(array $data) Use this method to send photos. On success, the sent Message is returned.
* @method static ServerResponse sendAudio(array $data) 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 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 static ServerResponse sendDocument(array $data) 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 static ServerResponse sendSticker(array $data) Use this method to send .webp stickers. On success, the sent Message is returned.
* @method static ServerResponse sendVideo(array $data) Use this method to send video files, Telegram clients support mp4 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 static ServerResponse sendVoice(array $data) 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 (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 static ServerResponse sendVideoNote(array $data) Use this method to send video messages. On success, the sent Message is returned.
* @method static ServerResponse sendLocation(array $data) Use this method to send point on the map. On success, the sent Message is returned.
* @method static ServerResponse sendVenue(array $data) Use this method to send information about a venue. On success, the sent Message is returned.
* @method static ServerResponse sendContact(array $data) Use this method to send phone contacts. On success, the sent Message is returned.
* @method static ServerResponse sendChatAction(array $data) 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 static ServerResponse getUserProfilePhotos(array $data) Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.
* @method static ServerResponse getFile(array $data) Use this method to get basic info 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 static ServerResponse kickChatMember(array $data) Use this method to kick a user from a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the group 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 admin rights. Returns True on success.
* @method static ServerResponse unbanChatMember(array $data) Use this method to unban a previously kicked 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. Returns True on success.
* @method static ServerResponse restrictChatMember(array $data) 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 admin rights. Pass True for all boolean parameters to lift restrictions from a user. Returns True on success.
* @method static ServerResponse promoteChatMember(array $data) 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 admin rights. Pass False for all boolean parameters to demote a user. Returns True on success.
* @method static ServerResponse exportChatInviteLink(array $data) Use this method to export an invite link to a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns exported invite link as String on success.
* @method static ServerResponse setChatPhoto(array $data) 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 admin rights. Returns True on success.
* @method static ServerResponse deleteChatPhoto(array $data) 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 admin rights. Returns True on success.
* @method static ServerResponse setChatTitle(array $data) 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 admin rights. Returns True on success.
* @method static ServerResponse setChatDescription(array $data) Use this method to change the description of a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
* @method static ServerResponse pinChatMessage(array $data) Use this method to pin a message in a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
* @method static ServerResponse unpinChatMessage(array $data) Use this method to unpin a message in a supergroup chat. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
* @method static ServerResponse leaveChat(array $data) Use this method for your bot to leave a group, supergroup or channel. Returns True on success.
* @method static ServerResponse getChat(array $data) Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). Returns a Chat object on success.
* @method static ServerResponse getChatAdministrators(array $data) Use this method to get a list of administrators in a chat. On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned.
* @method static ServerResponse getChatMembersCount(array $data) Use this method to get the number of members in a chat. Returns Int on success.
* @method static ServerResponse getChatMember(array $data) Use this method to get information about a member of a chat. Returns a ChatMember object on success.
* @method static ServerResponse answerCallbackQuery(array $data) 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.
* @method static ServerResponse answerInlineQuery(array $data) Use this method to send answers to an inline query. On success, True is returned.
* @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 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 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.
* @method static ServerResponse deleteMessage(array $data) Use this method to delete a message, including service messages, with certain limitations. Returns True on success.
*/
class Request
{
/**
......@@ -63,12 +108,17 @@ class Request
/**
* Available actions to send
*
* This is basically the list of all methods listed on the official API documentation.
*
* @link https://core.telegram.org/bots/api
*
* @var array
*/
private static $actions = [
'getUpdates',
'setWebhook',
'deleteWebhook',
'getWebhookInfo',
'getMe',
'sendMessage',
'forwardMessage',
......@@ -78,6 +128,7 @@ class Request
'sendSticker',
'sendVideo',
'sendVoice',
'sendVideoNote',
'sendLocation',
'sendVenue',
'sendContact',
......@@ -85,21 +136,42 @@ class Request
'getUserProfilePhotos',
'getFile',
'kickChatMember',
'leaveChat',
'unbanChatMember',
'restrictChatMember',
'promoteChatMember',
'exportChatInviteLink',
'setChatPhoto',
'deleteChatPhoto',
'setChatTitle',
'setChatDescription',
'pinChatMessage',
'unpinChatMessage',
'leaveChat',
'getChat',
'getChatAdministrators',
'getChatMember',
'getChatMembersCount',
'getChatMember',
'answerCallbackQuery',
'answerInlineQuery',
'editMessageText',
'editMessageCaption',
'editMessageReplyMarkup',
'getWebhookInfo',
'deleteMessage',
];
/**
* Some methods need a dummy param due to certain cURL issues.
*
* @see Request::addDummyParamIfNecessary()
*
* @var array
*/
private static $actions_need_dummy_param = [
'deleteWebhook',
'getWebhookInfo',
'getMe',
];
/**
* Initialize
*
......@@ -147,12 +219,12 @@ class Request
}
// Make sure we have a string to work with.
if (is_string($input)) {
self::$input = $input;
} else {
if (!is_string($input)) {
throw new TelegramException('Input must be a string!');
}
self::$input = $input;
TelegramLog::update(self::$input);
return self::$input;
......@@ -318,9 +390,9 @@ class Request
* @return resource
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
protected static function encodeFile($file)
public static function encodeFile($file)
{
$fp = fopen($file, 'r');
$fp = fopen($file, 'rb');
if ($fp === false) {
throw new TelegramException('Cannot open "' . $file . '" for reading');
}
......@@ -332,6 +404,7 @@ class Request
* Send command
*
* @todo Fake response doesn't need json encoding?
* @todo Write debug entry on failure
*
* @param string $action
* @param array $data
......@@ -342,6 +415,7 @@ class Request
public static function send($action, array $data = [])
{
self::ensureValidAction($action);
self::addDummyParamIfNecessary($action, $data);
$bot_username = self::$telegram->getBotUsername();
......@@ -365,62 +439,52 @@ class Request
}
/**
* Make sure the data isn't empty, else throw an exception
* Add a dummy parameter if the passed action requires it.
*
* @param array $data
* If a method doesn't require parameters, we need to add a dummy one anyway,
* because of some cURL version failed POST request without parameters.
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
private static function ensureNonEmptyData(array $data)
{
if (count($data) === 0) {
throw new TelegramException('Data is empty!');
}
}
/**
* Make sure the action is valid, else throw an exception
* @link https://github.com/php-telegram-bot/core/pull/228
*
* @param string $action
* @todo Would be nice to find a better solution for this!
*
* @throws \Longman\TelegramBot\Exception\TelegramException
* @param string $action
* @param array $data
*/
private static function ensureValidAction($action)
protected static function addDummyParamIfNecessary($action, array &$data)
{
if (!in_array($action, self::$actions, true)) {
throw new TelegramException('The action "' . $action . '" doesn\'t exist!');
if (in_array($action, self::$actions_need_dummy_param, true)) {
// Can be anything, using a single letter to minimise request size.
$data = ['d'];
}
}
/**
* Assign an encoded file to a data array
* Make sure the data isn't empty, else throw an exception
*
* @param array $data
* @param string $field
* @param string $file
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
private static function assignEncodedFile(&$data, $field, $file)
private static function ensureNonEmptyData(array $data)
{
if ($file !== null && $file !== '') {
$data[$field] = self::encodeFile($file);
if (count($data) === 0) {
throw new TelegramException('Data is empty!');
}
}
/**
* Returns basic information about the bot in form of a User object
* Make sure the action is valid, else throw an exception
*
* @link https://core.telegram.org/bots/api#getme
* @param string $action
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function getMe()
private static function ensureValidAction($action)
{
// Added fake parameter, because of some cURL version failed POST request without parameters
// see https://github.com/php-telegram-bot/core/pull/228
return self::send('getMe', ['whoami']);
if (!in_array($action, self::$actions, true)) {
throw new TelegramException('The action "' . $action . '" doesn\'t exist!');
}
}
/**
......@@ -450,499 +514,20 @@ class Request
}
/**
* Use this method to forward messages of any kind. On success, the sent Message is returned
*
* @link https://core.telegram.org/bots/api#forwardmessage
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function forwardMessage(array $data)
{
return self::send('forwardMessage', $data);
}
/**
* Use this method to send photos. On success, the sent Message is returned
*
* @link https://core.telegram.org/bots/api#sendphoto
*
* @param array $data
* @param string $file
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function sendPhoto(array $data, $file = null)
{
self::assignEncodedFile($data, 'photo', $file);
return self::send('sendPhoto', $data);
}
/**
* Use this method to send audio files
*
* Your audio must be in the .mp3 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.
* For sending voice messages, use the sendVoice method instead.
*
* @link https://core.telegram.org/bots/api#sendaudio
*
* @param array $data
* @param string $file
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function sendAudio(array $data, $file = null)
{
self::assignEncodedFile($data, 'audio', $file);
return self::send('sendAudio', $data);
}
/**
* 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.
*
* @link https://core.telegram.org/bots/api#senddocument
*
* @param array $data
* @param string $file
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function sendDocument(array $data, $file = null)
{
self::assignEncodedFile($data, 'document', $file);
return self::send('sendDocument', $data);
}
/**
* Use this method to send .webp stickers. On success, the sent Message is returned.
*
* @link https://core.telegram.org/bots/api#sendsticker
*
* @param array $data
* @param string $file
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function sendSticker(array $data, $file = null)
{
self::assignEncodedFile($data, 'sticker', $file);
return self::send('sendSticker', $data);
}
/**
* Use this method to send video files. On success, the sent Message is returned.
*
* Telegram clients support mp4 videos (other formats may be sent as Document).
* Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.
*
* @link https://core.telegram.org/bots/api#sendvideo
*
* @param array $data
* @param string $file
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function sendVideo(array $data, $file = null)
{
self::assignEncodedFile($data, 'video', $file);
return self::send('sendVideo', $data);
}
/**
* Use this method to send audio files. On success, the sent Message is returned.
*
* Telegram clients will display the file as a playable voice message.
* For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document).
* Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.
*
* @link https://core.telegram.org/bots/api#sendvoice
*
* @param array $data
* @param string $file
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function sendVoice(array $data, $file = null)
{
self::assignEncodedFile($data, 'voice', $file);
return self::send('sendVoice', $data);
}
/**
* Use this method to send point on the map. On success, the sent Message is returned.
*
* @link https://core.telegram.org/bots/api#sendlocation
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function sendLocation(array $data)
{
return self::send('sendLocation', $data);
}
/**
* Use this method to send information about a venue. On success, the sent Message is returned.
*
* @link https://core.telegram.org/bots/api#sendvenue
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function sendVenue(array $data)
{
return self::send('sendVenue', $data);
}
/**
* Use this method to send phone contacts. On success, the sent Message is returned.
*
* @link https://core.telegram.org/bots/api#sendcontact
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function sendContact(array $data)
{
return self::send('sendContact', $data);
}
/**
* 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)
*
* @link https://core.telegram.org/bots/api#sendchataction
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function sendChatAction(array $data)
{
return self::send('sendChatAction', $data);
}
/**
* Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function getUserProfilePhotos(array $data)
{
return self::send('getUserProfilePhotos', $data);
}
/**
* Use this method to get basic info about a file and prepare it for downloading. On success, a File object is returned.
*
* For the moment, bots can download files of up to 20MB in size.
* 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.
*
* @link https://core.telegram.org/bots/api#getfile
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function getFile(array $data)
{
return self::send('getFile', $data);
}
/**
* Use this method to kick a user from a group or a supergroup. Returns True on success.
*
* In the case of supergroups, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first.
* The bot must be an administrator in the group for this to work.
*
* @link https://core.telegram.org/bots/api#kickchatmember
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function kickChatMember(array $data)
{
return self::send('kickChatMember', $data);
}
/**
* Use this method for your bot to leave a group, supergroup or channel. Returns True on success.
*
* @link https://core.telegram.org/bots/api#leavechat
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function leaveChat(array $data)
{
return self::send('leaveChat', $data);
}
/**
* Use this method to unban a previously kicked user in a supergroup. Returns True on success.
*
* The user will not return to the group automatically, but will be able to join via link, etc.
* The bot must be an administrator in the group for this to work.
*
* @link https://core.telegram.org/bots/api#unbanchatmember
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function unbanChatMember(array $data)
{
return self::send('unbanChatMember', $data);
}
/**
* Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). Returns a Chat object on success.
*
* @todo add get response in ServerResponse.php?
*
* @link https://core.telegram.org/bots/api#getchat
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function getChat(array $data)
{
return self::send('getChat', $data);
}
/**
* Use this method to get a list of administrators in a chat.
*
* On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots.
* If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned.
*
* @todo add get response in ServerResponse.php?
*
* @link https://core.telegram.org/bots/api#getchatadministrators
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function getChatAdministrators(array $data)
{
return self::send('getChatAdministrators', $data);
}
/**
* Use this method to get the number of members in a chat. Returns Int on success.
*
* @todo add get response in ServerResponse.php?
*
* @link https://core.telegram.org/bots/api#getchatmemberscount
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function getChatMembersCount(array $data)
{
return self::send('getChatMembersCount', $data);
}
/**
* Use this method to get information about a member of a chat. Returns a ChatMember object on success.
*
* @todo add get response in ServerResponse.php?
*
* @link https://core.telegram.org/bots/api#getchatmember
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function getChatMember(array $data)
{
return self::send('getChatMember', $data);
}
/**
* Use this method to send answers to callback queries sent from inline keyboards. On success, True is returned.
*
* The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.
*
* @link https://core.telegram.org/bots/api#answercallbackquery
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function answerCallbackQuery(array $data)
{
return self::send('answerCallbackQuery', $data);
}
/**
* Get updates
*
* @link https://core.telegram.org/bots/api#getupdates
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function getUpdates(array $data)
{
return self::send('getUpdates', $data);
}
/**
* Set webhook
*
* @link https://core.telegram.org/bots/api#setwebhook
*
* @param string $url
* @param array $data Optional parameters.
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function setWebhook($url = '', array $data = [])
{
$data = array_intersect_key($data, array_flip([
'certificate',
'max_connections',
'allowed_updates',
]));
$data['url'] = $url;
if (isset($data['certificate'])) {
self::assignEncodedFile($data, 'certificate', $data['certificate']);
}
return self::send('setWebhook', $data);
}
/**
* Delete webhook
*
* @link https://core.telegram.org/bots/api#deletewebhook
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function deleteWebhook()
{
// Must send some arbitrary data for this to work for now...
return self::send('deleteWebhook', ['delete']);
}
/**
* 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.
*
* @link https://core.telegram.org/bots/api#editmessagetext
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function editMessageText(array $data)
{
return self::send('editMessageText', $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.
*
* @link https://core.telegram.org/bots/api#editmessagecaption
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function editMessageCaption(array $data)
{
return self::send('editMessageCaption', $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.
*
* @link https://core.telegram.org/bots/api#editmessagereplymarkup
* Any statically called method should be relayed to the `send` method.
*
* @param string $action
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function editMessageReplyMarkup(array $data)
public static function __callStatic($action, array $data)
{
return self::send('editMessageReplyMarkup', $data);
}
// Make sure to add the action being called as the first parameter to be passed.
array_unshift($data, $action);
/**
* Use this method to send answers to an inline query. On success, True is returned.
*
* No more than 50 results per query are allowed.
*
* @link https://core.telegram.org/bots/api#answerinlinequery
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function answerInlineQuery(array $data)
{
return self::send('answerInlineQuery', $data);
return call_user_func_array('static::send', $data);
}
/**
......@@ -992,20 +577,6 @@ class Request
return $results;
}
/**
* Use this method to get current webhook status.
*
* @link https://core.telegram.org/bots/api#getwebhookinfo
*
* @return Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function getWebhookInfo()
{
// Must send some arbitrary data for this to work for now...
return self::send('getWebhookInfo', ['info']);
}
/**
* Enable request limiter
*
......@@ -1055,12 +626,15 @@ class Request
'sendSticker',
'sendVideo',
'sendVoice',
'sendVideoNote',
'sendLocation',
'sendVenue',
'sendContact',
'editMessageText',
'editMessageCaption',
'editMessageReplyMarkup',
'setChatTitle',
'setChatDescription',
];
$chat_id = isset($data['chat_id']) ? $data['chat_id'] : null;
......@@ -1092,39 +666,4 @@ class Request
}
}
}
/**
* Use this method to delete either bot's messages or messages of other users if the bot is admin of the group.
*
* On success, true is returned.
*
* @link https://core.telegram.org/bots/api#deletemessage
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function deleteMessage(array $data)
{
return self::send('deleteMessage', $data);
}
/**
* Use this method to send video notes. On success, the sent Message is returned.
*
* @link https://core.telegram.org/bots/api#sendvideonote
*
* @param array $data
* @param string $file
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function sendVideoNote(array $data, $file = null)
{
self::assignEncodedFile($data, 'video_note', $file);
return self::send('sendVideoNote', $data);
}
}
......@@ -787,7 +787,19 @@ class Telegram
throw new TelegramException('Hook url is empty!');
}
$result = Request::setWebhook($url, $data);
$data = array_intersect_key($data, array_flip([
'certificate',
'max_connections',
'allowed_updates',
]));
$data['url'] = $url;
// If the certificate is passed as a path, encode and add the file to the data array.
if (!empty($data['certificate']) && is_string($data['certificate'])) {
$data['certificate'] = Request::encodeFile($data['certificate']);
}
$result = Request::setWebhook($data);
if (!$result->isOk()) {
throw new TelegramException(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment