class Api (View source)

Class Api

Constants

VERSION

BOT_TOKEN_ENV_NAME

Methods

__construct( string $token = null, bool $async = false, string|HttpClientInterface $http_client_handler = null)

Instantiates a new Telegram super-class object.

getClient()

Returns the TelegramClient service.

string
getAccessToken()

Returns Telegram Bot API Access Token.

getLastResponse()

Returns the last response returned from API request.

Api
setAccessToken( string $accessToken)

Sets the bot access token to use with API requests.

setAsyncRequest( bool $isAsyncRequest)

Make this request asynchronous (non-blocking).

bool
isAsyncRequest()

Check if this is an asynchronous request (non-blocking).

getCommandBus()

Returns SDK's Command Bus.

addCommand( CommandInterface|string $command)

Add Telegram Command to the Command Bus.

addCommands( array $commands)

Add Telegram Commands to the Command Bus.

array
getCommands()

Returns list of available commands.

getMe()

A simple method for testing your bot's auth token.

sendMessage( int $chat_id, string $text, bool $disable_web_page_preview = false, int $reply_to_message_id = null, string $reply_markup = null)

Send text messages.

forwardMessage( int $chat_id, int $from_chat_id, int $message_id)

Forward messages of any kind.

sendPhoto( int $chat_id, string $photo, string $caption = null, int $reply_to_message_id = null, string $reply_markup = null)

Send Photos.

sendAudio( int $chat_id, string $audio, int $duration = null, string $performer = null, string $title = null, int $reply_to_message_id = null, string $reply_markup = null)

Send regular audio files.

sendVoice( int $chat_id, string $voice, int $duration = null, int $reply_to_message_id = null, string $reply_markup = null)

Send voice audio files.

sendDocument( int $chat_id, string $document, int $reply_to_message_id = null, string $reply_markup = null)

Send general files.

sendSticker( int $chat_id, string $sticker, int $reply_to_message_id = null, string $reply_markup = null)

Send .webp stickers.

sendVideo( int $chat_id, string $video, int $duration = null, string $caption = null, int $reply_to_message_id = null, string $reply_markup = null)

Send Video File, Telegram clients support mp4 videos (other formats may be sent as Document).

sendLocation( int $chat_id, float $latitude, float $longitude, int $reply_to_message_id = null, string $reply_markup = null)

Send point on the map.

sendChatAction( int $chat_id, string $action)

Broadcast a Chat Action.

getUserProfilePhotos( int $user_id, int $offset = null, int $limit = null)

Returns a list of profile pictures for a user.

setWebhook( string $url, string $certificate = null)

Set a Webhook to receive incoming updates via an outgoing webhook.

getWebhookUpdates()

Returns webhook updates sent by Telegram.

removeWebhook()

Removes the outgoing webhook (if any).

Update[]
getUpdates( int|null $offset = null, int|null $limit = null, int|null $timeout = null)

Use this method to receive incoming updates using long polling.

string
replyKeyboardMarkup( array $keyboard, bool $resize_keyboard = false, bool $one_time_keyboard = false, bool $selective = false)

Builds a custom keyboard markup.

static  string
replyKeyboardHide( bool $selective = false)

Hide the current custom keyboard and display the default letter-keyboard.

static  string
forceReply( bool $selective = false)

Display a reply interface to the user (act as if the user has selected the bot‘s message and tapped ’Reply').

commandsHandler( bool $webhook = false)

Processes Inbound Commands.

bool
isMessageType( string $type, Update $update)

Determine if a given type is the message.

string|null
detectMessageType( Update $update)

Detect Message Type Based on Update Object.

__call($method, $arguments)

Magic method to process any "get" requests.

Details

at line 70
__construct( string $token = null, bool $async = false, string|HttpClientInterface $http_client_handler = null)

Instantiates a new Telegram super-class object.

Parameters

string $token The Telegram Bot API Access Token.
bool $async (Optional) Indicates if the request to Telegram will be asynchronous (non-blocking).
string|HttpClientInterface $http_client_handler (Optional) Custom HTTP Client Handler.

Exceptions

TelegramSDKException

at line 100
TelegramClient getClient()

Returns the TelegramClient service.

Return Value

TelegramClient

at line 110
string getAccessToken()

Returns Telegram Bot API Access Token.

Return Value

string

at line 120
TelegramResponse getLastResponse()

Returns the last response returned from API request.

Return Value

TelegramResponse

at line 134
Api setAccessToken( string $accessToken)

Sets the bot access token to use with API requests.

Parameters

string $accessToken The bot access token to save.

Return Value

Api

Exceptions

InvalidArgumentException

at line 152
TelegramRequest setAsyncRequest( bool $isAsyncRequest)

Make this request asynchronous (non-blocking).

Parameters

bool $isAsyncRequest

Return Value

TelegramRequest

at line 164
bool isAsyncRequest()

Check if this is an asynchronous request (non-blocking).

Return Value

bool

at line 174
CommandBus getCommandBus()

Returns SDK's Command Bus.

Return Value

CommandBus

at line 190
CommandBus addCommand( CommandInterface|string $command)

Add Telegram Command to the Command Bus.

Parameters

CommandInterface|string $command

Return Value

CommandBus

at line 202
CommandBus addCommands( array $commands)

Add Telegram Commands to the Command Bus.

Parameters

array $commands

Return Value

CommandBus

at line 212
array getCommands()

Returns list of available commands.

Return Value

array

at line 225
User getMe()

A simple method for testing your bot's auth token.

Returns basic information about the bot in form of a User object.

Return Value

User

at line 245
Message sendMessage( int $chat_id, string $text, bool $disable_web_page_preview = false, int $reply_to_message_id = null, string $reply_markup = null)

Send text messages.

Parameters

int $chat_id
string $text
bool $disable_web_page_preview
int $reply_to_message_id
string $reply_markup

Return Value

Message

at line 269
Message forwardMessage( int $chat_id, int $from_chat_id, int $message_id)

Forward messages of any kind.

Parameters

int $chat_id
int $from_chat_id
int $message_id

Return Value

Message

at line 290
Message sendPhoto( int $chat_id, string $photo, string $caption = null, int $reply_to_message_id = null, string $reply_markup = null)

Send Photos.

Parameters

int $chat_id
string $photo
string $caption
int $reply_to_message_id
string $reply_markup

Return Value

Message

at line 312
Message sendAudio( int $chat_id, string $audio, int $duration = null, string $performer = null, string $title = null, int $reply_to_message_id = null, string $reply_markup = null)

Send regular audio files.

Parameters

int $chat_id
string $audio
int $duration
string $performer
string $title
int $reply_to_message_id
string $reply_markup

Return Value

Message

at line 339
Message sendVoice( int $chat_id, string $voice, int $duration = null, int $reply_to_message_id = null, string $reply_markup = null)

Send voice audio files.

Parameters

int $chat_id
string $voice
int $duration
int $reply_to_message_id
string $reply_markup

Return Value

Message

at line 358
Message sendDocument( int $chat_id, string $document, int $reply_to_message_id = null, string $reply_markup = null)

Send general files.

Parameters

int $chat_id
string $document
int $reply_to_message_id
string $reply_markup

Return Value

Message

at line 379
Message sendSticker( int $chat_id, string $sticker, int $reply_to_message_id = null, string $reply_markup = null)

Send .webp stickers.

Parameters

int $chat_id
string $sticker
int $reply_to_message_id
string $reply_markup

Return Value

Message

Exceptions

TelegramSDKException

at line 405
Message sendVideo( int $chat_id, string $video, int $duration = null, string $caption = null, int $reply_to_message_id = null, string $reply_markup = null)

Send Video File, Telegram clients support mp4 videos (other formats may be sent as Document).

Parameters

int $chat_id
string $video
int $duration
string $caption
int $reply_to_message_id
string $reply_markup

Return Value

Message

See also

sendDocument

at line 431
Message sendLocation( int $chat_id, float $latitude, float $longitude, int $reply_to_message_id = null, string $reply_markup = null)

Send point on the map.

Parameters

int $chat_id
float $latitude
float $longitude
int $reply_to_message_id
string $reply_markup

Return Value

Message

at line 451
TelegramResponse sendChatAction( int $chat_id, string $action)

Broadcast a Chat Action.

Parameters

int $chat_id
string $action

Return Value

TelegramResponse

Exceptions

TelegramSDKException

at line 482
UserProfilePhotos getUserProfilePhotos( int $user_id, int $offset = null, int $limit = null)

Returns a list of profile pictures for a user.

Parameters

int $user_id
int $offset
int $limit

Return Value

UserProfilePhotos

at line 501
TelegramResponse setWebhook( string $url, string $certificate = null)

Set a Webhook to receive incoming updates via an outgoing webhook.

Parameters

string $url HTTPS url to send updates to.
string $certificate Upload your public key certificate so that the root certificate in use can be checked.

Return Value

TelegramResponse

Exceptions

TelegramSDKException

at line 522
Update getWebhookUpdates()

Returns webhook updates sent by Telegram.

Works only if you set a webhook.

Return Value

Update

See also

setWebhook

at line 534
TelegramResponse removeWebhook()

Removes the outgoing webhook (if any).

Return Value

TelegramResponse

at line 552
Update[] getUpdates( int|null $offset = null, int|null $limit = null, int|null $timeout = null)

Use this method to receive incoming updates using long polling.

Parameters

int|null $offset
int|null $limit
int|null $timeout

Return Value

Update[]

at line 577
string replyKeyboardMarkup( array $keyboard, bool $resize_keyboard = false, bool $one_time_keyboard = false, bool $selective = false)

Builds a custom keyboard markup.

Parameters

array $keyboard
bool $resize_keyboard
bool $one_time_keyboard
bool $selective

Return Value

string

at line 595
static string replyKeyboardHide( bool $selective = false)

Hide the current custom keyboard and display the default letter-keyboard.

Parameters

bool $selective

Return Value

string

at line 611
static string forceReply( bool $selective = false)

Display a reply interface to the user (act as if the user has selected the bot‘s message and tapped ’Reply').

Parameters

bool $selective

Return Value

string

at line 625
Update|Update[] commandsHandler( bool $webhook = false)

Processes Inbound Commands.

Parameters

bool $webhook

Return Value

Update|Update[]

at line 673
bool isMessageType( string $type, Update $update)

Determine if a given type is the message.

Parameters

string $type
Update $update

Return Value

bool

at line 689
string|null detectMessageType( Update $update)

Detect Message Type Based on Update Object.

Parameters

Update $update

Return Value

string|null

at line 825
bool|TelegramResponse __call($method, $arguments)

Magic method to process any "get" requests.

Parameters

$method
$arguments

Return Value

bool|TelegramResponse