PHP Class Longman\TelegramBot\Telegram

Datei anzeigen Open project: akalongman/php-telegram-bot Class Usage Examples

Protected Properties

Property Type Description
$admins_list array Admins list
$api_key string Telegram API key
$bot_name string Telegram Bot name
$botan_enabled boolean Botan.io integration
$commands_config array Commands config
$commands_paths array Custom commands paths
$download_path string Download path
$input string Raw request data (json) for webhook methods
$last_command_response Longman\TelegramBot\Entities\ServerResponse ServerResponse of the last Command execution
$mysql_enabled boolean MySQL integration
$pdo PDO PDO object
$update Longman\TelegramBot\Entities\Update Current Update object
$upload_path string Upload path
$version string Version

Public Methods

Method Description
__construct ( string $api_key, string $bot_name ) Telegram constructor.
addCommandsPath ( string $path, boolean $before = true ) : Telegram Add a single custom commands path
addCommandsPaths ( array $paths, boolean $before = true ) : Telegram Add multiple custom commands paths
enableAdmin ( integer $admin_id ) : Telegram Enable a single Admin account
enableAdmins ( array $admin_ids ) : Telegram Enable a list of Admin Accounts
enableBotan ( $token ) : Telegram Enable Botan.io integration
enableExternalMySql ( PD\PDO $external_pdo_connection, string $table_prefix = null ) : Telegram Initialize Database external connection
enableMySql ( array $credential, string $table_prefix = null, string $encoding = 'utf8mb4' ) : Telegram Initialize Database connection
executeCommand ( string $command ) : mixed Execute /command
getAdminList ( ) : array Get list of admins
getApiKey ( ) : string Get API key
getBotName ( ) : string Get Bot name
getCommandConfig ( string $command ) : array Get command config
getCommandObject ( string $command ) : Command | null Get an object instance of the passed command
getCommandsList ( ) : array Get commands list
getCustomInput ( ) : string Get custom input string for debug purposes
getDownloadPath ( ) : string Get custom download path
getLastCommandResponse ( ) : ServerResponse Get the ServerResponse of the last Command execution
getUploadPath ( ) : string Get custom upload path
getVersion ( ) : string Get Version
handle ( ) : boolean Handle bot request from webhook
handleGetUpdates ( integer | null $limit = null, integer | null $timeout = null ) : ServerResponse Handle getUpdates method
isAdmin ( integer | null $user_id = null ) : boolean Check if the passed user is an admin
isDbEnabled ( ) : boolean Check if user required the db connection
processUpdate ( Update $update ) : ServerResponse Process bot Update request
setCommandConfig ( string $command, array $config ) : Telegram Set command config
setCustomInput ( string $input ) : Telegram Set custom input string for debug purposes
setDownloadPath ( string $path ) : Telegram Set custom download path
setUploadPath ( string $path ) : Telegram Set custom upload path
setWebHook ( string $url, string | null $path_certificate = null ) : ServerResponse Set Webhook for bot
unsetWebHook ( ) : mixed Unset Webhook for bot

Protected Methods

Method Description
sanitizeCommand ( string $command ) : string Sanitize Command
ucfirstUnicode ( string $str, string $encoding = 'UTF-8' ) : string Replace function ucfirst for UTF-8 characters in the class definition and commands
ucwordsUnicode ( string $str, string $encoding = 'UTF-8' ) : string Replace function ucwords for UTF-8 characters in the class definition and commands

Private Methods

Method Description
getCommandFromType ( string $type ) : string Get the command name from the command type

Method Details

__construct() public method

Telegram constructor.
public __construct ( string $api_key, string $bot_name )
$api_key string
$bot_name string

addCommandsPath() public method

Add a single custom commands path
public addCommandsPath ( string $path, boolean $before = true ) : Telegram
$path string Custom commands path to add
$before boolean If the path should be prepended or appended to the list
return Telegram

addCommandsPaths() public method

Add multiple custom commands paths
public addCommandsPaths ( array $paths, boolean $before = true ) : Telegram
$paths array Custom commands paths to add
$before boolean If the paths should be prepended or appended to the list
return Telegram

enableAdmin() public method

Enable a single Admin account
public enableAdmin ( integer $admin_id ) : Telegram
$admin_id integer Single admin id
return Telegram

enableAdmins() public method

Enable a list of Admin Accounts
public enableAdmins ( array $admin_ids ) : Telegram
$admin_ids array List of admin ids
return Telegram

enableBotan() public method

Enable Botan.io integration
public enableBotan ( $token ) : Telegram
$token
return Telegram

enableExternalMySql() public method

Initialize Database external connection
public enableExternalMySql ( PD\PDO $external_pdo_connection, string $table_prefix = null ) : Telegram
$external_pdo_connection PD\PDO PDO database object
$table_prefix string
return Telegram

enableMySql() public method

Initialize Database connection
public enableMySql ( array $credential, string $table_prefix = null, string $encoding = 'utf8mb4' ) : Telegram
$credential array
$table_prefix string
$encoding string
return Telegram

executeCommand() public method

Execute /command
public executeCommand ( string $command ) : mixed
$command string
return mixed

getAdminList() public method

Get list of admins
public getAdminList ( ) : array
return array

getApiKey() public method

Get API key
public getApiKey ( ) : string
return string

getBotName() public method

Get Bot name
public getBotName ( ) : string
return string

getCommandConfig() public method

Get command config
public getCommandConfig ( string $command ) : array
$command string
return array

getCommandObject() public method

Get an object instance of the passed command
public getCommandObject ( string $command ) : Command | null
$command string
return Longman\TelegramBot\Commands\Command | null

getCommandsList() public method

Get commands list
public getCommandsList ( ) : array
return array $commands

getCustomInput() public method

Get custom input string for debug purposes
public getCustomInput ( ) : string
return string

getDownloadPath() public method

Get custom download path
public getDownloadPath ( ) : string
return string

getLastCommandResponse() public method

Get the ServerResponse of the last Command execution
public getLastCommandResponse ( ) : ServerResponse
return Longman\TelegramBot\Entities\ServerResponse

getUploadPath() public method

Get custom upload path
public getUploadPath ( ) : string
return string

getVersion() public method

Get Version
public getVersion ( ) : string
return string

handle() public method

Handle bot request from webhook
public handle ( ) : boolean
return boolean

handleGetUpdates() public method

Handle getUpdates method
public handleGetUpdates ( integer | null $limit = null, integer | null $timeout = null ) : ServerResponse
$limit integer | null
$timeout integer | null
return Longman\TelegramBot\Entities\ServerResponse

isAdmin() public method

If no user id is passed, the current update is checked for a valid message sender.
public isAdmin ( integer | null $user_id = null ) : boolean
$user_id integer | null
return boolean

isDbEnabled() public method

Check if user required the db connection
public isDbEnabled ( ) : boolean
return boolean

processUpdate() public method

Process bot Update request
public processUpdate ( Update $update ) : ServerResponse
$update Longman\TelegramBot\Entities\Update
return Longman\TelegramBot\Entities\ServerResponse

sanitizeCommand() protected method

Sanitize Command
protected sanitizeCommand ( string $command ) : string
$command string
return string

setCommandConfig() public method

Provide further variables to a particular commands. For example you can add the channel name at the command /sendtochannel Or you can add the api key for external service.
public setCommandConfig ( string $command, array $config ) : Telegram
$command string
$config array
return Telegram

setCustomInput() public method

Set custom input string for debug purposes
public setCustomInput ( string $input ) : Telegram
$input string (json format)
return Telegram

setDownloadPath() public method

Set custom download path
public setDownloadPath ( string $path ) : Telegram
$path string Custom download path
return Telegram

setUploadPath() public method

Set custom upload path
public setUploadPath ( string $path ) : Telegram
$path string Custom upload path
return Telegram

setWebHook() public method

Set Webhook for bot
public setWebHook ( string $url, string | null $path_certificate = null ) : ServerResponse
$url string
$path_certificate string | null
return Longman\TelegramBot\Entities\ServerResponse

ucfirstUnicode() protected method

Replace function ucfirst for UTF-8 characters in the class definition and commands
protected ucfirstUnicode ( string $str, string $encoding = 'UTF-8' ) : string
$str string
$encoding string (default = 'UTF-8')
return string

ucwordsUnicode() protected method

Replace function ucwords for UTF-8 characters in the class definition and commands
protected ucwordsUnicode ( string $str, string $encoding = 'UTF-8' ) : string
$str string
$encoding string (default = 'UTF-8')
return string

unsetWebHook() public method

Unset Webhook for bot
public unsetWebHook ( ) : mixed
return mixed

Property Details

$admins_list protected_oe property

Admins list
protected array $admins_list
return array

$api_key protected_oe property

Telegram API key
protected string $api_key
return string

$bot_name protected_oe property

Telegram Bot name
protected string $bot_name
return string

$botan_enabled protected_oe property

Botan.io integration
protected bool $botan_enabled
return boolean

$commands_config protected_oe property

Commands config
protected array $commands_config
return array

$commands_paths protected_oe property

Custom commands paths
protected array $commands_paths
return array

$download_path protected_oe property

Download path
protected string $download_path
return string

$input protected_oe property

Raw request data (json) for webhook methods
protected string $input
return string

$last_command_response protected_oe property

ServerResponse of the last Command execution
protected ServerResponse,Longman\TelegramBot\Entities $last_command_response
return Longman\TelegramBot\Entities\ServerResponse

$mysql_enabled protected_oe property

MySQL integration
protected bool $mysql_enabled
return boolean

$pdo protected_oe property

PDO object
protected PDO $pdo
return PDO

$update protected_oe property

Current Update object
protected Update,Longman\TelegramBot\Entities $update
return Longman\TelegramBot\Entities\Update

$upload_path protected_oe property

Upload path
protected string $upload_path
return string

$version protected_oe property

Version
protected string $version
return string