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.

Api
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.

removeCommand( string $name)

Remove Telegram Command to the Command Bus.

removeCommands( array $names)

Remove Telegram Commands from the Command Bus.

getCommands()

Returns list of available commands.

getMe()

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

sendMessage( array $params)

Send text messages.

forwardMessage( array $params)

Forward messages of any kind.

sendPhoto( array $params)

Send Photos.

sendAudio( array $params)

Send regular audio files.

sendDocument( array $params)

Send general files.

sendSticker( array $params)

Send .webp stickers.

sendVideo( array $params)

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

sendVoice( array $params)

Send voice audio files.

sendLocation( array $params)

Send point on the map.

sendChatAction( array $params)

Broadcast a Chat Action.

getUserProfilePhotos( array $params)

Returns a list of profile pictures for a user.

getFile( array $params)

Returns basic info about a file and prepare it for downloading.

setWebhook( array $params)

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( array $params = array())

Use this method to receive incoming updates using long polling.

string
replyKeyboardMarkup( array $params)

Builds a custom keyboard markup.

static  string
replyKeyboardHide( array $params = array())

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

static  string
forceReply( array $params = array())

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|Message $object)

Determine if a given type is the message.

string|null
detectMessageType( Update|Message $object)

Detect Message Type Based on Update or Message Object.

__call($method, $arguments)

Magic method to process any "get" requests.

static  void
setContainer( Container $container)

Set the IoC Container.

Container
getContainer()

Get the IoC Container.

boolean
hasContainer()

Check if IoC Container has been set.

int
getTimeOut()

No description

$this
setTimeOut( int $timeOut)

No description

int
getConnectTimeOut()

No description

$this
setConnectTimeOut( int $connectTimeOut)

No description

Details

at line 88
__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 118
TelegramClient getClient()

Returns the TelegramClient service.

Return Value

TelegramClient

at line 128
string getAccessToken()

Returns Telegram Bot API Access Token.

Return Value

string

at line 138
TelegramResponse getLastResponse()

Returns the last response returned from API request.

Return Value

TelegramResponse

at line 152
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 170
Api setAsyncRequest( bool $isAsyncRequest)

Make this request asynchronous (non-blocking).

Parameters

bool $isAsyncRequest

Return Value

Api

at line 182
bool isAsyncRequest()

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

Return Value

bool

at line 192
CommandBus getCommandBus()

Returns SDK's Command Bus.

Return Value

CommandBus

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

Add Telegram Command to the Command Bus.

Parameters

CommandInterface|string $command

Return Value

CommandBus

at line 220
CommandBus addCommands( array $commands)

Add Telegram Commands to the Command Bus.

Parameters

array $commands

Return Value

CommandBus

at line 232
CommandBus removeCommand( string $name)

Remove Telegram Command to the Command Bus.

Parameters

string $name

Return Value

CommandBus

at line 244
CommandBus removeCommands( array $names)

Remove Telegram Commands from the Command Bus.

Parameters

array $names

Return Value

CommandBus

at line 254
Command[] getCommands()

Returns list of available commands.

Return Value

Command[]

at line 267
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 301
Message sendMessage( array $params)

Send text messages.

$params = [ 'chatid' => '', 'text' => '', 'parsemode' => '', 'disablewebpagepreview' => '', 'replytomessageid' => '', 'reply_markup' => '', ];

Parameters

array $params

Return Value

Message

at line 329
Message forwardMessage( array $params)

Forward messages of any kind.

$params = [ 'chatid' => '', 'fromchatid' => '', 'messageid' => '', ];

Parameters

array $params

Return Value

Message

at line 361
Message sendPhoto( array $params)

Send Photos.

$params = [ 'chatid' => '', 'photo' => '', 'caption' => '', 'replytomessageid' => '', 'reply_markup' => '', ];

Parameters

array $params

Return Value

Message

at line 395
Message sendAudio( array $params)

Send regular audio files.

$params = [ 'chatid' => '', 'audio' => '', 'duration' => '', 'performer' => '', 'title' => '', 'replytomessageid' => '', 'reply_markup' => '', ];

Parameters

array $params

Return Value

Message

at line 423
Message sendDocument( array $params)

Send general files.

$params = [ 'chatid' => '', 'document' => '', 'replytomessageid' => '', 'reply_markup' => '', ];

Parameters

array $params

Return Value

Message

at line 453
Message sendSticker( array $params)

Send .webp stickers.

$params = [ 'chatid' => '', 'sticker' => '', 'replytomessageid' => '', 'reply_markup' => '', ];

Parameters

array $params

Return Value

Message

Exceptions

TelegramSDKException

at line 490
Message sendVideo( array $params)

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

$params = [ 'chatid' => '', 'video' => '', 'duration' => '', 'caption' => '', 'replytomessageid' => '', 'reply_markup' => '', ];

Parameters

array $params

Return Value

Message

See also

sendDocument

at line 520
Message sendVoice( array $params)

Send voice audio files.

$params = [ 'chatid' => '', 'voice' => '', 'duration' => '', 'replytomessageid' => '', 'reply_markup' => '', ];

Parameters

array $params

Return Value

Message

at line 550
Message sendLocation( array $params)

Send point on the map.

$params = [ 'chatid' => '', 'latitude' => '', 'longitude' => '', 'replytomessageid' => '', 'reply_markup' => '', ];

Parameters

array $params

Return Value

Message

at line 578
TelegramResponse sendChatAction( array $params)

Broadcast a Chat Action.

$params = [ 'chat_id' => '', 'action' => '', ];

Parameters

array $params

Return Value

TelegramResponse

Exceptions

TelegramSDKException

at line 619
UserProfilePhotos getUserProfilePhotos( array $params)

Returns a list of profile pictures for a user.

$params = [ 'user_id' => '', 'offset' => '', 'limit' => '', ];

Parameters

array $params

Return Value

UserProfilePhotos

at line 647
File getFile( array $params)

Returns basic info about a file and prepare it for downloading.

$params = [ 'file_id' => '', ];

The file can then be downloaded via the link https://api.telegram.org/file/bot/, where is taken from the response.

Parameters

array $params

Return Value

File

at line 676
TelegramResponse setWebhook( array $params)

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

$params = [ 'url' => '', 'certificate' => '', ];

Parameters

array $params

Return Value

TelegramResponse

Exceptions

TelegramSDKException

at line 697
Update getWebhookUpdates()

Returns webhook updates sent by Telegram.

Works only if you set a webhook.

Return Value

Update

See also

setWebhook

at line 709
TelegramResponse removeWebhook()

Removes the outgoing webhook (if any).

Return Value

TelegramResponse

at line 737
Update[] getUpdates( array $params = array())

Use this method to receive incoming updates using long polling.

$params = [ 'offset' => '', 'limit' => '', 'timeout' => '', ];

Parameters

array $params

Return Value

Update[]

at line 775
string replyKeyboardMarkup( array $params)

Builds a custom keyboard markup.

$params = [ 'keyboard' => '', 'resizekeyboard' => '', 'onetime_keyboard' => '', 'selective' => '', ];

Parameters

array $params

Return Value

string

at line 799
static string replyKeyboardHide( array $params = array())

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

$params = [ 'hide_keyboard' => true, 'selective' => false, ];

Parameters

array $params

Return Value

string

at line 823
static string forceReply( array $params = array())

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

$params = [ 'force_reply' => true, 'selective' => false, ];

Parameters

array $params

Return Value

string

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

Processes Inbound Commands.

Parameters

bool $webhook

Return Value

Update|Update[]

at line 885
bool isMessageType( string $type, Update|Message $object)

Determine if a given type is the message.

Parameters

string $type
Update|Message $object

Return Value

bool

at line 905
string|null detectMessageType( Update|Message $object)

Detect Message Type Based on Update or Message Object.

Parameters

Update|Message $object

Return Value

string|null

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

Magic method to process any "get" requests.

Parameters

$method
$arguments

Return Value

bool|TelegramResponse

at line 1076
static void setContainer( Container $container)

Set the IoC Container.

Parameters

Container $container Container instance

Return Value

void

at line 1086
Container getContainer()

Get the IoC Container.

Return Value

Container

at line 1096
boolean hasContainer()

Check if IoC Container has been set.

Return Value

boolean

at line 1104
int getTimeOut()

Return Value

int

at line 1114
$this setTimeOut( int $timeOut)

Parameters

int $timeOut

Return Value

$this

at line 1124
int getConnectTimeOut()

Return Value

int

at line 1134
$this setConnectTimeOut( int $connectTimeOut)

Parameters

int $connectTimeOut

Return Value

$this