PHP Class Telegram\Bot\Api

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

Protected Properties

Свойство 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.

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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 méthode

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

__construct() public méthode

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 méthode

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
Résultat boolean

answerInlineQuery() public méthode

$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
Résultat boolean

commandsHandler() public méthode

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

detectMessageType() public méthode

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
Résultat string | null

editMessageCaption() public méthode

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

editMessageReplyMarkup() public méthode

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

editMessageText() public méthode

$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
Résultat Telegram\Bot\Objects\Message | boolean

forceReply() public static méthode

$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
Résultat Telegram\Bot\Keyboard\Keyboard

forwardMessage() public méthode

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

get() protected méthode

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

getAccessToken() public méthode

Returns Telegram Bot API Access Token.
public getAccessToken ( ) : string
Résultat string

getChat() public méthode

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

getChatAdministrators() public méthode

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

getChatMember() public méthode

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

getChatMembersCount() public méthode

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

getClient() public méthode

Returns the TelegramClient service.
public getClient ( ) : Telegram\Bot\TelegramClient
Résultat Telegram\Bot\TelegramClient

getCommandBus() public méthode

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

getConnectTimeOut() public méthode

public getConnectTimeOut ( ) : integer
Résultat integer

getContainer() public méthode

Get the IoC Container.
public getContainer ( ) : Illuminate\Contracts\Container\Container
Résultat Illuminate\Contracts\Container\Container

getFile() public méthode

$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
Résultat Telegram\Bot\Objects\File

getLastResponse() public méthode

Returns the last response returned from API request.
public getLastResponse ( ) : TelegramResponse
Résultat TelegramResponse

getMe() public méthode

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

getTimeOut() public méthode

public getTimeOut ( ) : integer
Résultat integer

getUpdates() public méthode

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

getUserProfilePhotos() public méthode

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

getWebhookUpdate() public méthode

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

getWebhookUpdates() public méthode

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
Résultat Telegram\Bot\Objects\Update

hasContainer() public méthode

Check if IoC Container has been set.
public hasContainer ( ) : boolean
Résultat boolean

isAsyncRequest() public méthode

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

isMessageType() public méthode

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 méthode

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
Résultat boolean

kickChatMember() public méthode

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
Résultat boolean

manager() public static méthode

Invoke Bots Manager.
public static manager ( $config ) : BotsManager
$config
Résultat BotsManager

markUpdateAsRead() protected méthode

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

post() protected méthode

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.
Résultat TelegramResponse

processCommand() public méthode

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

removeWebhook() public méthode

Removes the outgoing webhook (if any).
public removeWebhook ( ) : TelegramResponse
Résultat TelegramResponse

replyKeyboardHide() public static méthode

$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
Résultat string

replyKeyboardMarkup() public méthode

$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
Résultat string

request() protected méthode

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

sendAudio() public méthode

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

sendChatAction() public méthode

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

sendContact() public méthode

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

sendDocument() public méthode

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

sendLocation() public méthode

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

sendMessage() public méthode

$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
Résultat Telegram\Bot\Objects\Message

sendPhoto() public méthode

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

sendRequest() protected méthode

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
Résultat TelegramResponse

sendSticker() public méthode

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

sendVenue() public méthode

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

sendVideo() public méthode

$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
Résultat Telegram\Bot\Objects\Message

sendVoice() public méthode

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

setAccessToken() public méthode

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

setAsyncRequest() public méthode

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

setConnectTimeOut() public méthode

public setConnectTimeOut ( integer $connectTimeOut )
$connectTimeOut integer

setContainer() public static méthode

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

setTimeOut() public méthode

public setTimeOut ( integer $timeOut )
$timeOut integer

setWebhook() public méthode

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

triggerCommand() public méthode

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

unbanChatMember() public méthode

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
Résultat boolean

uploadFile() protected méthode

Used primarily for file uploads.
protected uploadFile ( string $endpoint, array $params = [] ) : TelegramResponse
$endpoint string
$params array
Résultat 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
Résultat 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
Résultat integer