PHP Class Longman\TelegramBot\Request

Exibir arquivo Open project: akalongman/php-telegram-bot Class Usage Examples

Public Methods

Method Description
answerCallbackQuery ( array $data ) : ServerResponse Use this method to send answers to callback queries sent from inline keyboards. On success, True is returned.
answerInlineQuery ( array $data ) : ServerResponse Use this method to send answers to an inline query. On success, True is returned.
downloadFile ( Longman\TelegramBot\Entities\File $file ) : boolean Download file
editMessageCaption ( array $data ) : ServerResponse Use this method to edit captions of messages sent by the bot or via the bot (for inline bots).
editMessageReplyMarkup ( array $data ) : ServerResponse Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots).
editMessageText ( array $data ) : ServerResponse Use this method to edit text and game messages sent by the bot or via the bot (for inline bots).
emptyResponse ( ) : ServerResponse Return an empty Server Response
execute ( string $action, array $data = [] ) : string Execute HTTP Request
forwardMessage ( array $data ) : ServerResponse Use this method to forward messages of any kind. On success, the sent Message is returned
generateGeneralFakeServerResponse ( array $data = [] ) : array Generate general fake server response
getChat ( array $data ) : ServerResponse 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.
getChatAdministrators ( array $data ) : ServerResponse Use this method to get a list of administrators in a chat.
getChatMember ( array $data ) : ServerResponse Use this method to get information about a member of a chat. Returns a ChatMember object on success.
getChatMembersCount ( array $data ) : ServerResponse Use this method to get the number of members in a chat. Returns Int on success.
getFile ( array $data ) : ServerResponse Use this method to get basic info about a file and prepare it for downloading. On success, a File object is returned.
getInput ( ) : string Set input from custom input or stdin and return it
getMe ( ) : ServerResponse Returns basic information about the bot in form of a User object
getUpdates ( array $data ) : ServerResponse Get updates
getUserProfilePhotos ( array $data ) : ServerResponse Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.
getWebhookInfo ( ) : ServerResponse Use this method to get current webhook status.
initialize ( Telegram $telegram ) Initialize
kickChatMember ( array $data ) : ServerResponse Use this method to kick a user from a group or a supergroup. Returns True on success.
leaveChat ( array $data ) : ServerResponse Use this method for your bot to leave a group, supergroup or channel. Returns True on success.
send ( string $action, array $data = [] ) : ServerResponse Send command
sendAudio ( array $data, string $file = null ) : ServerResponse Use this method to send audio files
sendChatAction ( array $data ) : ServerResponse Use this method when you need to tell the user that something is happening on the bot's side.
sendContact ( array $data ) : ServerResponse Use this method to send phone contacts. On success, the sent Message is returned.
sendDocument ( array $data, string $file = null ) : ServerResponse Use this method to send general files. On success, the sent Message is returned.
sendLocation ( array $data ) : ServerResponse Use this method to send point on the map. On success, the sent Message is returned.
sendMessage ( array $data ) : ServerResponse Use this method to send text messages. On success, the sent Message is returned
sendPhoto ( array $data, string $file = null ) : ServerResponse Use this method to send photos. On success, the sent Message is returned
sendSticker ( array $data, string $file = null ) : ServerResponse Use this method to send .webp stickers. On success, the sent Message is returned.
sendToActiveChats ( string $callback_function, array $data, boolean $send_groups = true, boolean $send_super_groups = true, boolean $send_users = true, string $date_from = null, string $date_to = null ) : array Send message to all active chats
sendVenue ( array $data ) : ServerResponse Use this method to send information about a venue. On success, the sent Message is returned.
sendVideo ( array $data, string $file = null ) : ServerResponse Use this method to send video files. On success, the sent Message is returned.
sendVoice ( array $data, string $file = null ) : ServerResponse Use this method to send audio files. On success, the sent Message is returned.
setWebhook ( string $url = '', string $file = null ) : ServerResponse Set webhook
unbanChatMember ( array $data ) : ServerResponse Use this method to unban a previously kicked user in a supergroup. Returns True on success.

Protected Methods

Method Description
encodeFile ( string $file ) : resource Encode file

Private Methods

Method Description
assignEncodedFile ( array &$data, string $field, string $file ) Assign an encoded file to a data array
ensureNonEmptyData ( array $data ) Make sure the data isn't empty, else throw an exception
ensureValidAction ( string $action ) Make sure the action is valid, else throw an exception
setUpRequestParams ( array $data ) : array Properly set up the request params

Method Details

answerCallbackQuery() public static method

The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.
public static answerCallbackQuery ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

answerInlineQuery() public static method

No more than 50 results per query are allowed.
public static answerInlineQuery ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

downloadFile() public static method

Download file
public static downloadFile ( Longman\TelegramBot\Entities\File $file ) : boolean
$file Longman\TelegramBot\Entities\File
return boolean

editMessageCaption() public static method

On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
public static editMessageCaption ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

editMessageReplyMarkup() public static method

On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
public static editMessageReplyMarkup ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

editMessageText() public static method

On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
public static editMessageText ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

emptyResponse() public static method

No request to telegram are sent, this function is used in commands that don't need to fire a message after execution
public static emptyResponse ( ) : ServerResponse
return Longman\TelegramBot\Entities\ServerResponse

encodeFile() protected static method

Encode file
protected static encodeFile ( string $file ) : resource
$file string
return resource

execute() public static method

Execute HTTP Request
public static execute ( string $action, array $data = [] ) : string
$action string Action to execute
$data array Data to attach to the execution
return string Result of the HTTP Request

forwardMessage() public static method

Use this method to forward messages of any kind. On success, the sent Message is returned
public static forwardMessage ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

generateGeneralFakeServerResponse() public static method

Generate general fake server response
public static generateGeneralFakeServerResponse ( array $data = [] ) : array
$data array Data to add to fake response
return array Fake response data

getChat() public static method

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.
public static getChat ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

getChatAdministrators() public static method

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.
public static getChatAdministrators ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

getChatMember() public static method

Use this method to get information about a member of a chat. Returns a ChatMember object on success.
public static getChatMember ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

getChatMembersCount() public static method

Use this method to get the number of members in a chat. Returns Int on success.
public static getChatMembersCount ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

getFile() public static method

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/, where 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.
public static getFile ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

getInput() public static method

Set input from custom input or stdin and return it
public static getInput ( ) : string
return string

getMe() public static method

Returns basic information about the bot in form of a User object
public static getMe ( ) : ServerResponse
return Longman\TelegramBot\Entities\ServerResponse

getUpdates() public static method

Get updates
public static getUpdates ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

getUserProfilePhotos() public static method

Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.
public static getUserProfilePhotos ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

getWebhookInfo() public static method

Use this method to get current webhook status.
public static getWebhookInfo ( ) : ServerResponse
return Longman\TelegramBot\Entities\ServerResponse

initialize() public static method

Initialize
public static initialize ( Telegram $telegram )
$telegram Telegram

kickChatMember() public static method

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.
public static kickChatMember ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

leaveChat() public static method

Use this method for your bot to leave a group, supergroup or channel. Returns True on success.
public static leaveChat ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

send() public static method

Send command
public static send ( string $action, array $data = [] ) : ServerResponse
$action string
$data array
return Longman\TelegramBot\Entities\ServerResponse

sendAudio() public static method

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.
public static sendAudio ( array $data, string $file = null ) : ServerResponse
$data array
$file string
return Longman\TelegramBot\Entities\ServerResponse

sendChatAction() public static method

The status is set for 5 seconds or less. (when a message arrives from your bot, Telegram clients clear its typing status)
public static sendChatAction ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

sendContact() public static method

Use this method to send phone contacts. On success, the sent Message is returned.
public static sendContact ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

sendDocument() public static method

Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.
public static sendDocument ( array $data, string $file = null ) : ServerResponse
$data array
$file string
return Longman\TelegramBot\Entities\ServerResponse

sendLocation() public static method

Use this method to send point on the map. On success, the sent Message is returned.
public static sendLocation ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

sendMessage() public static method

Use this method to send text messages. On success, the sent Message is returned
public static sendMessage ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

sendPhoto() public static method

Use this method to send photos. On success, the sent Message is returned
public static sendPhoto ( array $data, string $file = null ) : ServerResponse
$data array
$file string
return Longman\TelegramBot\Entities\ServerResponse

sendSticker() public static method

Use this method to send .webp stickers. On success, the sent Message is returned.
public static sendSticker ( array $data, string $file = null ) : ServerResponse
$data array
$file string
return Longman\TelegramBot\Entities\ServerResponse

sendToActiveChats() public static method

Send message to all active chats
public static sendToActiveChats ( string $callback_function, array $data, boolean $send_groups = true, boolean $send_super_groups = true, boolean $send_users = true, string $date_from = null, string $date_to = null ) : array
$callback_function string
$data array
$send_groups boolean
$send_super_groups boolean
$send_users boolean
$date_from string
$date_to string
return array

sendVenue() public static method

Use this method to send information about a venue. On success, the sent Message is returned.
public static sendVenue ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse

sendVideo() public static method

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.
public static sendVideo ( array $data, string $file = null ) : ServerResponse
$data array
$file string
return Longman\TelegramBot\Entities\ServerResponse

sendVoice() public static method

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.
public static sendVoice ( array $data, string $file = null ) : ServerResponse
$data array
$file string
return Longman\TelegramBot\Entities\ServerResponse

setWebhook() public static method

Set webhook
public static setWebhook ( string $url = '', string $file = null ) : ServerResponse
$url string
$file string
return Longman\TelegramBot\Entities\ServerResponse

unbanChatMember() public static method

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.
public static unbanChatMember ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse