PHP Class Telegram\Bot\Api

Inheritance: use trait Telegram\Bot\Events\EmitsEvents
Mostrar archivo Open project: irazasyed/telegram-bot-sdk Class Usage Examples

Protected Properties

Property Type Description
$accessToken Telegram Bot API Access Token.
$client The Telegram client service.
$commandBus Telegram Command Bus.
$connectTimeOut integer Connection timeout of the request in seconds.
$container IoC Container
$isAsyncRequest Indicates if the request to Telegram will be asynchronous (non-blocking).
$lastResponse Stores the last request made to Telegram Bot API.
$timeOut integer Timeout of the request in seconds.

Public Methods

Method Description
__call ( $method, $arguments ) : boolean | TelegramResponse | Telegram\Bot\Objects\UnknownObject Magic method to process any "get" requests.
__construct ( string $token = null, boolean $async = false, Telegram\Bot\HttpClients\HttpClientInterface $httpClientHandler = null ) Instantiates a new Telegram super-class object.
answerCallbackQuery ( array $params ) : boolean Send answers to callback queries sent from inline keyboards.
answerInlineQuery ( array $params = [] ) : boolean Use this method to send answers to an inline query.
commandsHandler ( boolean $webhook = false ) : Update | Update[] Processes Inbound Commands.
detectMessageType ( Update | Message $object ) : string | null Detect Message Type Based on Update or Message Object.
editMessageCaption ( array $params ) : Message | boolean Edit captions of messages sent by the bot or via the bot (for inline bots).
editMessageReplyMarkup ( array $params ) : Message | boolean Edit only the reply markup of messages sent by the bot or via the bot (for inline bots).
editMessageText ( array $params ) : Message | boolean Edit text messages sent by the bot or via the bot (for inline bots).
forceReply ( array $params = [] ) : Keyboard Display a reply interface to the user (act as if the user has selected the bot‘s message and tapped ’Reply').
forwardMessage ( array $params ) : Message Forward messages of any kind.
getAccessToken ( ) : string Returns Telegram Bot API Access Token.
getChat ( array $params ) : Telegram\Bot\Objects\Chat 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,
getChatAdministrators ( array $params ) : ChatMember[] Get a list of administrators in a chat.
getChatMember ( array $params ) : ChatMember Get information about a member of a chat.
getChatMembersCount ( array $params ) : integer Get the number of members in a chat
getClient ( ) : Telegram\Bot\TelegramClient Returns the TelegramClient service.
getCommandBus ( ) : CommandBus Returns SDK's Command Bus.
getConnectTimeOut ( ) : integer
getContainer ( ) : Illuminate\Contracts\Container\Container Get the IoC Container.
getFile ( array $params ) : Telegram\Bot\Objects\File Returns basic info about a file and prepare it for downloading.
getLastResponse ( ) : TelegramResponse Returns the last response returned from API request.
getMe ( ) : Telegram\Bot\Objects\User A simple method for testing your bot's auth token.
getTimeOut ( ) : integer
getUpdates ( array $params = [], boolean $shouldEmitEvents = true ) : Update[] Use this method to receive incoming updates using long polling.
getUserProfilePhotos ( array $params ) : Telegram\Bot\Objects\UserProfilePhotos Returns a list of profile pictures for a user.
getWebhookUpdate ( $shouldEmitEvent = true ) : Update Returns a webhook update sent by Telegram.
getWebhookUpdates ( boolean $shouldEmitEvent = true ) : Update Alias for getWebhookUpdate
hasContainer ( ) : boolean Check if IoC Container has been set.
isAsyncRequest ( ) : boolean Check if this is an asynchronous request (non-blocking).
isMessageType ( string $type, Update | Message $object ) Determine if a given type is the message.
kickChatMember ( array $params ) : boolean Kick a user from a group or a supergroup.
manager ( $config ) : BotsManager Invoke Bots Manager.
processCommand ( Update $update ) Check update object for a command and process.
removeWebhook ( ) : TelegramResponse Removes the outgoing webhook (if any).
replyKeyboardHide ( array $params = [] ) : string Hide the current custom keyboard and display the default letter-keyboard.
replyKeyboardMarkup ( array $params ) : string Builds a custom keyboard markup.
sendAudio ( array $params ) : Message Send regular audio files.
sendChatAction ( array $params ) : boolean Broadcast a Chat Action.
sendContact ( array $params ) : Message Send phone contacts.
sendDocument ( array $params ) : Message Send general files.
sendLocation ( array $params ) : Message Send point on the map.
sendMessage ( array $params ) : Message Send text messages.
sendPhoto ( array $params ) : Message Send Photos.
sendSticker ( array $params ) : Message Send .webp stickers.
sendVenue ( array $params ) : Message Send information about a venue.
sendVideo ( array $params ) : Message Send Video File, Telegram clients support mp4 videos (other formats may be sent as Document).
sendVoice ( array $params ) : Message Send voice audio files.
setAccessToken ( string $accessToken ) : Api Sets the bot access token to use with API requests.
setAsyncRequest ( boolean $isAsyncRequest ) : Api Make this request asynchronous (non-blocking).
setConnectTimeOut ( integer $connectTimeOut )
setContainer ( Illuminate\Contracts\Container\Container $container ) : void Set the IoC Container.
setTimeOut ( integer $timeOut )
setWebhook ( array $params ) : TelegramResponse Set a Webhook to receive incoming updates via an outgoing webhook.
triggerCommand ( string $name, Update $update ) : mixed Helper to Trigger Commands.
unbanChatMember ( array $params ) : boolean Unban a previously kicked user in a supergroup.

Protected Methods

Method Description
get ( string $endpoint, array $params = [] ) : TelegramResponse Sends a GET request to Telegram Bot API and returns the result.
isValidFileOrUrl ( string $name, string $contents ) : boolean Determines if the string passed to be uploaded is a valid file on the local file system, or a valid remote URL.
markUpdateAsRead ( $params ) : Update[] An alias for getUpdates that helps readability.
post ( string $endpoint, array $params = [], boolean $fileUpload = false ) : TelegramResponse Sends a POST request to Telegram Bot API and returns the result.
request ( string $method, string $endpoint, array $params = [] ) : Telegram\Bot\TelegramRequest Instantiates a new TelegramRequest entity.
sendRequest ( string $method, string $endpoint, array $params = [] ) : TelegramResponse Sends a request to Telegram Bot API and returns the result.
uploadFile ( string $endpoint, array $params = [] ) : TelegramResponse Sends a multipart/form-data request to Telegram Bot API and returns the result.

Method Details

__call() public method

Magic method to process any "get" requests.
public __call ( $method, $arguments ) : boolean | TelegramResponse | Telegram\Bot\Objects\UnknownObject
$method
$arguments
return boolean | TelegramResponse | Telegram\Bot\Objects\UnknownObject

__construct() public method

Instantiates a new Telegram super-class object.
public __construct ( string $token = null, boolean $async = false, Telegram\Bot\HttpClients\HttpClientInterface $httpClientHandler = null )
$token string The Telegram Bot API Access Token.
$async boolean (Optional) Indicates if the request to Telegram will be asynchronous (non-blocking).
$httpClientHandler Telegram\Bot\HttpClients\HttpClientInterface (Optional) Custom HTTP Client Handler.

answerCallbackQuery() public method

he answer will be displayed to the user as a notification at the top of the chat screen or as an alert. $params = [ 'callback_query_id' => '', 'text' => '', 'show_alert' => '', ];
public answerCallbackQuery ( array $params ) : boolean
$params array
return boolean

answerInlineQuery() public method

$params = [ 'inline_query_id' => '', 'results' => [], 'cache_time' => 0, 'is_personal' => false, 'next_offset' => '', 'switch_pm_text' => '', 'switch_pm_parameter' => '', ];
public answerInlineQuery ( array $params = [] ) : boolean
$params array
return boolean

commandsHandler() public method

Processes Inbound Commands.
public commandsHandler ( boolean $webhook = false ) : Update | Update[]
$webhook boolean
return Telegram\Bot\Objects\Update | Telegram\Bot\Objects\Update[]

detectMessageType() public method

Detect Message Type Based on Update or Message Object.
Deprecation: Call method detectType directly on Message object To be removed in next major version.
public detectMessageType ( Update | Message $object ) : string | null
$object Telegram\Bot\Objects\Update | Telegram\Bot\Objects\Message
return string | null

editMessageCaption() public method

$params = [ 'chat_id' => '', 'message_id' => '', 'inline_message_id' => '', 'caption' => '', 'reply_markup' => '', ];
public editMessageCaption ( array $params ) : Message | boolean
$params array
return Telegram\Bot\Objects\Message | boolean

editMessageReplyMarkup() public method

$params = [ 'chat_id' => '', 'message_id' => '', 'inline_message_id' => '', 'reply_markup' => '', ];
public editMessageReplyMarkup ( array $params ) : Message | boolean
$params array
return Telegram\Bot\Objects\Message | boolean

editMessageText() public method

$params = [ 'chat_id' => '', 'message_id' => '', 'inline_message_id' => '', 'text' => '', 'parse_mode' => '', 'disable_web_page_preview' => '', 'reply_markup' => '', ];
public editMessageText ( array $params ) : Message | boolean
$params array
return Telegram\Bot\Objects\Message | boolean

forceReply() public static method

$params = [ 'force_reply' => true, 'selective' => false, ];
Deprecation: Use Telegram\Bot\Keyboard\Keyboard::forceReply(array $params = []) instead. To be removed in next major version.
public static forceReply ( array $params = [] ) : Keyboard
$params array
return Telegram\Bot\Keyboard\Keyboard

forwardMessage() public method

$params = [ 'chat_id' => '', 'from_chat_id' => '', 'disable_notification' => '', 'message_id' => '', ];
public forwardMessage ( array $params ) : Message
$params array
return Telegram\Bot\Objects\Message

get() protected method

Sends a GET request to Telegram Bot API and returns the result.
protected get ( string $endpoint, array $params = [] ) : TelegramResponse
$endpoint string
$params array
return TelegramResponse

getAccessToken() public method

Returns Telegram Bot API Access Token.
public getAccessToken ( ) : string
return string

getChat() public method

$params = [ 'chat_id' => '', ];
public getChat ( array $params ) : Telegram\Bot\Objects\Chat
$params array
return Telegram\Bot\Objects\Chat

getChatAdministrators() public method

$params = [ 'chat_id' => '', ];
public getChatAdministrators ( array $params ) : ChatMember[]
$params array
return Telegram\Bot\Objects\ChatMember[]

getChatMember() public method

$params = [ 'chat_id' => '', 'user_id' => '', ];
public getChatMember ( array $params ) : ChatMember
$params array
return Telegram\Bot\Objects\ChatMember

getChatMembersCount() public method

$params = [ 'chat_id' => '', ];
public getChatMembersCount ( array $params ) : integer
$params array
return integer

getClient() public method

Returns the TelegramClient service.
public getClient ( ) : Telegram\Bot\TelegramClient
return Telegram\Bot\TelegramClient

getCommandBus() public method

Returns SDK's Command Bus.
public getCommandBus ( ) : CommandBus
return Telegram\Bot\Commands\CommandBus

getConnectTimeOut() public method

public getConnectTimeOut ( ) : integer
return integer

getContainer() public method

Get the IoC Container.
public getContainer ( ) : Illuminate\Contracts\Container\Container
return Illuminate\Contracts\Container\Container

getFile() public method

$params = [ 'file_id' => '', ]; The file can then be downloaded via the link https://api.telegram.org/file/bot/, where is taken from the response.
public getFile ( array $params ) : Telegram\Bot\Objects\File
$params array
return Telegram\Bot\Objects\File

getLastResponse() public method

Returns the last response returned from API request.
public getLastResponse ( ) : TelegramResponse
return TelegramResponse

getMe() public method

Returns basic information about the bot in form of a User object.
public getMe ( ) : Telegram\Bot\Objects\User
return Telegram\Bot\Objects\User

getTimeOut() public method

public getTimeOut ( ) : integer
return integer

getUpdates() public method

$params = [ 'offset' => '', 'limit' => '', 'timeout' => '', ];
public getUpdates ( array $params = [], boolean $shouldEmitEvents = true ) : Update[]
$params array
$shouldEmitEvents boolean
return Telegram\Bot\Objects\Update[]

getUserProfilePhotos() public method

$params = [ 'user_id' => '', 'offset' => '', 'limit' => '', ];
public getUserProfilePhotos ( array $params ) : Telegram\Bot\Objects\UserProfilePhotos
$params array
return Telegram\Bot\Objects\UserProfilePhotos

getWebhookUpdate() public method

Works only if you set a webhook.
See also: setWebhook
public getWebhookUpdate ( $shouldEmitEvent = true ) : Update
return Telegram\Bot\Objects\Update

getWebhookUpdates() public method

Alias for getWebhookUpdate
Deprecation: Call method getWebhookUpdate (note lack of letter s at end) To be removed in next major version.
public getWebhookUpdates ( boolean $shouldEmitEvent = true ) : Update
$shouldEmitEvent boolean
return Telegram\Bot\Objects\Update

hasContainer() public method

Check if IoC Container has been set.
public hasContainer ( ) : boolean
return boolean

isAsyncRequest() public method

Check if this is an asynchronous request (non-blocking).
public isAsyncRequest ( ) : boolean
return boolean

isMessageType() public method

Determine if a given type is the message.
Deprecation: Call method isType directly on Message object To be removed in next major version.
public isMessageType ( string $type, Update | Message $object )
$type string
$object Telegram\Bot\Objects\Update | Telegram\Bot\Objects\Message

isValidFileOrUrl() protected method

Determines if the string passed to be uploaded is a valid file on the local file system, or a valid remote URL.
protected isValidFileOrUrl ( string $name, string $contents ) : boolean
$name string
$contents string
return boolean

kickChatMember() public 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. $params = [ 'chat_id' => '', 'user_id' => '', ];
public kickChatMember ( array $params ) : boolean
$params array
return boolean

manager() public static method

Invoke Bots Manager.
public static manager ( $config ) : BotsManager
$config
return BotsManager

markUpdateAsRead() protected method

An alias for getUpdates that helps readability.
protected markUpdateAsRead ( $params ) : Update[]
$params
return Telegram\Bot\Objects\Update[]

post() protected method

Sends a POST request to Telegram Bot API and returns the result.
protected post ( string $endpoint, array $params = [], boolean $fileUpload = false ) : TelegramResponse
$endpoint string
$params array
$fileUpload boolean Set true if a file is being uploaded.
return TelegramResponse

processCommand() public method

Check update object for a command and process.
public processCommand ( Update $update )
$update Telegram\Bot\Objects\Update

removeWebhook() public method

Removes the outgoing webhook (if any).
public removeWebhook ( ) : TelegramResponse
return TelegramResponse

replyKeyboardHide() public static method

$params = [ 'hide_keyboard' => true, 'selective' => false, ];
Deprecation: Use Telegram\Bot\Keyboard\Keyboard::hide(array $params = []) instead. To be removed in next major version.
public static replyKeyboardHide ( array $params = [] ) : string
$params array
return string

replyKeyboardMarkup() public method

$params = [ 'keyboard' => '', 'resize_keyboard' => '', 'one_time_keyboard' => '', 'selective' => '', ];
Deprecation: Use Telegram\Bot\Keyboard\Keyboard::make(array $params = []) instead. To be removed in next major version.
public replyKeyboardMarkup ( array $params ) : string
$params array
return string

request() protected method

Instantiates a new TelegramRequest entity.
protected request ( string $method, string $endpoint, array $params = [] ) : Telegram\Bot\TelegramRequest
$method string
$endpoint string
$params array
return Telegram\Bot\TelegramRequest

sendAudio() public method

$params = [ 'chat_id' => '', 'audio' => '', 'duration' => '', 'performer' => '', 'title' => '', 'disable_notification' => '', 'reply_to_message_id' => '', 'reply_markup' => '', ];
public sendAudio ( array $params ) : Message
$params array
return Telegram\Bot\Objects\Message

sendChatAction() public method

$params = [ 'chat_id' => '', 'action' => '', ];
public sendChatAction ( array $params ) : boolean
$params array
return boolean

sendContact() public method

$params = [ 'chat_id' => '', 'phone_number' => '', 'first_name' => '', 'last_name' => '', 'disable_notification' => '', 'reply_to_message_id' => '', 'reply_markup' => '', ];
public sendContact ( array $params ) : Message
$params array
return Telegram\Bot\Objects\Message

sendDocument() public method

$params = [ 'chat_id' => '', 'document' => '', 'caption' => '', 'disable_notification' => '', 'reply_to_message_id' => '', 'reply_markup' => '', ];
public sendDocument ( array $params ) : Message
$params array
return Telegram\Bot\Objects\Message

sendLocation() public method

$params = [ 'chat_id' => '', 'latitude' => '', 'longitude' => '', 'disable_notification' => '', 'reply_to_message_id' => '', 'reply_markup' => '', ];
public sendLocation ( array $params ) : Message
$params array
return Telegram\Bot\Objects\Message

sendMessage() public method

$params = [ 'chat_id' => '', 'text' => '', 'parse_mode' => '', 'disable_web_page_preview' => '', 'disable_notification' => '', 'reply_to_message_id' => '', 'reply_markup' => '', ];
public sendMessage ( array $params ) : Message
$params array
return Telegram\Bot\Objects\Message

sendPhoto() public method

$params = [ 'chat_id' => '', 'photo' => '', 'caption' => '', 'disable_notification' => '', 'reply_to_message_id' => '', 'reply_markup' => '', ];
public sendPhoto ( array $params ) : Message
$params array
return Telegram\Bot\Objects\Message

sendRequest() protected method

Sends a request to Telegram Bot API and returns the result.
protected sendRequest ( string $method, string $endpoint, array $params = [] ) : TelegramResponse
$method string
$endpoint string
$params array
return TelegramResponse

sendSticker() public method

$params = [ 'chat_id' => '', 'sticker' => '', 'disable_notification' => '', 'reply_to_message_id' => '', 'reply_markup' => '', ];
public sendSticker ( array $params ) : Message
$params array
return Telegram\Bot\Objects\Message

sendVenue() public method

$params = [ 'chat_id' => '', 'latitude' => '', 'longitude' => '', 'title' => '', 'address' => '', 'foursquare_id' => '', 'disable_notification' => '', 'reply_to_message_id' => '', 'reply_markup' => '', ];
public sendVenue ( array $params ) : Message
$params array
return Telegram\Bot\Objects\Message

sendVideo() public method

$params = [ 'chat_id' => '', 'video' => '', 'duration' => '', 'width' => '', 'height' => '', 'caption' => '', 'disable_notification' => '', 'reply_to_message_id' => '', 'reply_markup' => '', ];
See also: sendDocument
public sendVideo ( array $params ) : Message
$params array
return Telegram\Bot\Objects\Message

sendVoice() public method

$params = [ 'chat_id' => '', 'voice' => '', 'duration' => '', 'disable_notification' => '', 'reply_to_message_id' => '', 'reply_markup' => '', ];
public sendVoice ( array $params ) : Message
$params array
return Telegram\Bot\Objects\Message

setAccessToken() public method

Sets the bot access token to use with API requests.
public setAccessToken ( string $accessToken ) : Api
$accessToken string The bot access token to save.
return Api

setAsyncRequest() public method

Make this request asynchronous (non-blocking).
public setAsyncRequest ( boolean $isAsyncRequest ) : Api
$isAsyncRequest boolean
return Api

setConnectTimeOut() public method

public setConnectTimeOut ( integer $connectTimeOut )
$connectTimeOut integer

setContainer() public static method

Set the IoC Container.
public static setContainer ( Illuminate\Contracts\Container\Container $container ) : void
$container Illuminate\Contracts\Container\Container Container instance
return void

setTimeOut() public method

public setTimeOut ( integer $timeOut )
$timeOut integer

setWebhook() public method

$params = [ 'url' => '', 'certificate' => '', ];
public setWebhook ( array $params ) : TelegramResponse
$params array
return TelegramResponse

triggerCommand() public method

Helper to Trigger Commands.
public triggerCommand ( string $name, Update $update ) : mixed
$name string Command Name
$update Telegram\Bot\Objects\Update Update Object
return mixed

unbanChatMember() public 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. $params = [ 'chat_id' => '', 'user_id' => '', ];
public unbanChatMember ( array $params ) : boolean
$params array
return boolean

uploadFile() protected method

Used primarily for file uploads.
protected uploadFile ( string $endpoint, array $params = [] ) : TelegramResponse
$endpoint string
$params array
return TelegramResponse

Property Details

$accessToken protected_oe property

Telegram Bot API Access Token.
protected $accessToken

$client protected_oe property

The Telegram client service.
protected $client

$commandBus protected_oe property

Telegram Command Bus.
protected $commandBus

$connectTimeOut protected_oe property

Connection timeout of the request in seconds.
protected int $connectTimeOut
return integer

$container protected_oe static_oe property

IoC Container
protected static $container

$isAsyncRequest protected_oe property

Indicates if the request to Telegram will be asynchronous (non-blocking).
protected $isAsyncRequest

$lastResponse protected_oe property

Stores the last request made to Telegram Bot API.
protected $lastResponse

$timeOut protected_oe property

Timeout of the request in seconds.
protected int $timeOut
return integer