Commit d1442fe9 authored by RedScorp's avatar RedScorp

for UTF-8 characters in the class definition and commands

parent 3b97af62
<?php <?php
/** /**
* This file is part of the TelegramBot package. * This file is part of the TelegramBot package.
* *
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com> * (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Longman\TelegramBot; namespace Longman\TelegramBot;
define('BASE_PATH', __DIR__); define('BASE_PATH', __DIR__);
define('BASE_COMMANDS_PATH', BASE_PATH . '/Commands'); define('BASE_COMMANDS_PATH', BASE_PATH . '/Commands');
use Longman\TelegramBot\Entities\Update; use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Exception\TelegramException;
/** /**
* @package Telegram * @package Telegram
* @author Avtandil Kikabidze <akalongman@gmail.com> * @author Avtandil Kikabidze <akalongman@gmail.com>
* @copyright Avtandil Kikabidze <akalongman@gmail.com> * @copyright Avtandil Kikabidze <akalongman@gmail.com>
* @license http://opensource.org/licenses/mit-license.php The MIT License (MIT) * @license http://opensource.org/licenses/mit-license.php The MIT License (MIT)
* @link http://www.github.com/akalongman/php-telegram-bot * @link http://www.github.com/akalongman/php-telegram-bot
*/ */
class Telegram class Telegram
{ {
/** /**
* Version * Version
* *
* @var string * @var string
*/ */
protected $version = '0.30.0'; protected $version = '0.30.0';
/** /**
* Telegram API key * Telegram API key
* *
* @var string * @var string
*/ */
protected $api_key = ''; protected $api_key = '';
/** /**
* Telegram Bot name * Telegram Bot name
* *
* @var string * @var string
*/ */
protected $bot_name = ''; protected $bot_name = '';
/** /**
* Raw request data (json) for webhook methods * Raw request data (json) for webhook methods
* *
* @var string * @var string
*/ */
protected $input; protected $input;
/** /**
* Custom commands paths * Custom commands paths
* *
* @var array * @var array
*/ */
protected $commands_paths = []; protected $commands_paths = [];
/** /**
* Current Update object * Current Update object
* *
* @var Entities\Update * @var Entities\Update
*/ */
protected $update; protected $update;
/** /**
* Log verbose curl output * Log verbose curl output
* *
* @var bool * @var bool
*/ */
protected $log_requests; protected $log_requests;
/** /**
* Log path * Log path
* *
* @var string * @var string
*/ */
protected $log_path; protected $log_path;
/** /**
* Upload path * Upload path
* *
* @var string * @var string
*/ */
protected $upload_path; protected $upload_path;
/** /**
* Download path * Download path
* *
* @var string * @var string
*/ */
protected $download_path; protected $download_path;
/** /**
* Log verbosity * Log verbosity
* *
* @var int * @var int
*/ */
protected $log_verbosity = 1; protected $log_verbosity = 1;
/** /**
* MySQL integration * MySQL integration
* *
* @var boolean * @var boolean
*/ */
protected $mysql_enabled = false; protected $mysql_enabled = false;
/** /**
* PDO object * PDO object
* *
* @var \PDO * @var \PDO
*/ */
protected $pdo; protected $pdo;
/** /**
* Commands config * Commands config
* *
* @var array * @var array
*/ */
protected $commands_config = []; protected $commands_config = [];
/** /**
* Admins list * Admins list
* *
* @var array * @var array
*/ */
protected $admins_list = []; protected $admins_list = [];
/** /**
* ServerResponse of the last Command execution * ServerResponse of the last Command execution
* *
* @var Entities\ServerResponse * @var Entities\ServerResponse
*/ */
protected $last_command_response; protected $last_command_response;
/** /**
* Constructor * Constructor
* *
* @param string $api_key * @param string $api_key
* @param string $bot_name * @param string $bot_name
*/ */
public function __construct($api_key, $bot_name) public function __construct($api_key, $bot_name)
{ {
if (empty($api_key)) { if (empty($api_key)) {
throw new TelegramException('API KEY not defined!'); throw new TelegramException('API KEY not defined!');
} }
if (empty($bot_name)) { if (empty($bot_name)) {
throw new TelegramException('Bot Username not defined!'); throw new TelegramException('Bot Username not defined!');
} }
$this->api_key = $api_key; $this->api_key = $api_key;
$this->bot_name = $bot_name; $this->bot_name = $bot_name;
//Set default download and upload path //Set default download and upload path
$this->setDownloadPath(BASE_PATH . '/../Download'); $this->setDownloadPath(BASE_PATH . '/../Download');
$this->setUploadPath(BASE_PATH . '/../Upload'); $this->setUploadPath(BASE_PATH . '/../Upload');
//Add default system commands path //Add default system commands path
$this->addCommandsPath(BASE_COMMANDS_PATH . '/SystemCommands'); $this->addCommandsPath(BASE_COMMANDS_PATH . '/SystemCommands');
Request::initialize($this); Request::initialize($this);
} }
/** /**
* Initialize Database connection * Initialize Database connection
* *
* @param array $credential * @param array $credential
* @param string $table_prefix * @param string $table_prefix
* *
* @return Telegram * @return Telegram
*/ */
public function enableMySql(array $credential, $table_prefix = null) public function enableMySql(array $credential, $table_prefix = null)
{ {
$this->pdo = DB::initialize($credential, $this, $table_prefix); $this->pdo = DB::initialize($credential, $this, $table_prefix);
ConversationDB::initializeConversation(); ConversationDB::initializeConversation();
$this->mysql_enabled = true; $this->mysql_enabled = true;
return $this; return $this;
} }
/** /**
* Initialize Database external connection * Initialize Database external connection
* *
* @param PDO $external_pdo_connection PDO database object * @param PDO $external_pdo_connection PDO database object
* @param string $table_prefix * @param string $table_prefix
*/ */
public function enableExternalMysql($external_pdo_connection, $table_prefix = null) public function enableExternalMysql($external_pdo_connection, $table_prefix = null)
{ {
$this->pdo = DB::externalInitialize($external_pdo_connection, $this, $table_prefix); $this->pdo = DB::externalInitialize($external_pdo_connection, $this, $table_prefix);
ConversationDB::initializeConversation(); ConversationDB::initializeConversation();
$this->mysql_enabled = true; $this->mysql_enabled = true;
} }
/** /**
* Get commands list * Get commands list
* *
* @return array $commands * @return array $commands
*/ */
public function getCommandsList() public function getCommandsList()
{ {
$commands = []; $commands = [];
foreach ($this->commands_paths as $path) { foreach ($this->commands_paths as $path) {
try { try {
//Get all "*Command.php" files //Get all "*Command.php" files
$files = new \RegexIterator( $files = new \RegexIterator(
new \RecursiveIteratorIterator( new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($path) new \RecursiveDirectoryIterator($path)
), ),
'/^.+Command.php$/' '/^.+Command.php$/'
); );
foreach ($files as $file) { foreach ($files as $file) {
//Remove "Command.php" from filename //Remove "Command.php" from filename
$command = $this->sanitizeCommand(substr($file->getFilename(), 0, -11)); $command = $this->sanitizeCommand(substr($file->getFilename(), 0, -11));
$command_name = strtolower($command); $command_name = strtolower($command);
if (array_key_exists($command_name, $commands)) { if (array_key_exists($command_name, $commands)) {
continue; continue;
} }
require_once $file->getPathname(); require_once $file->getPathname();
$command_obj = $this->getCommandObject($command); $command_obj = $this->getCommandObject($command);
if ($command_obj instanceof Commands\Command) { if ($command_obj instanceof Commands\Command) {
$commands[$command_name] = $command_obj; $commands[$command_name] = $command_obj;
} }
} }
} catch (\Exception $e) { } catch (\Exception $e) {
throw new TelegramException('Error getting commands from path: ' . $path); throw new TelegramException('Error getting commands from path: ' . $path);
} }
} }
return $commands; return $commands;
} }
/** /**
* Get an object instance of the passed command * Get an object instance of the passed command
* *
* @param string $command * @param string $command
* *
* @return Entities\Command|null * @return Entities\Command|null
*/ */
public function getCommandObject($command) public function getCommandObject($command)
{ {
$which = ['System']; $which = ['System'];
($this->isAdmin()) && $which[] = 'Admin'; ($this->isAdmin()) && $which[] = 'Admin';
$which[] = 'User'; $which[] = 'User';
foreach ($which as $auth) { foreach ($which as $auth) {
$command_namespace = __NAMESPACE__ . '\\Commands\\' . $auth . 'Commands\\' . ucfirst($command) . 'Command'; // $command_namespace = __NAMESPACE__ . '\\Commands\\' . $auth . 'Commands\\' . ucfirst($command) . 'Command';
if (class_exists($command_namespace)) { $command_namespace = __NAMESPACE__ . '\\Commands\\' . $auth . 'Commands\\' . $this->mb_ucfirst($command) . 'Command';
return new $command_namespace($this, $this->update); if (class_exists($command_namespace)) {
} return new $command_namespace($this, $this->update);
} }
}
return null;
} return null;
}
/**
* Set log requests /**
* * Set log requests
* 0 don't store *
* 1 store the Curl verbose output with Telegram updates * 0 don't store
* * 1 store the Curl verbose output with Telegram updates
* @param bool $log_requests *
* * @param bool $log_requests
* @return Telegram *
*/ * @return Telegram
public function setLogRequests($log_requests) */
{ public function setLogRequests($log_requests)
$this->log_requests = $log_requests; {
return $this; $this->log_requests = $log_requests;
} return $this;
}
/**
* Get log requests /**
* * Get log requests
* @return bool *
*/ * @return bool
public function getLogRequests() */
{ public function getLogRequests()
return $this->log_requests; {
} return $this->log_requests;
}
/**
* Set log path /**
* * Set log path
* @param string $log_path *
* * @param string $log_path
* @return \Longman\TelegramBot\Telegram *
*/ * @return \Longman\TelegramBot\Telegram
public function setLogPath($log_path) */
{ public function setLogPath($log_path)
$this->log_path = $log_path; {
return $this; $this->log_path = $log_path;
} return $this;
}
/**
* Get log path /**
* * Get log path
* @return string *
*/ * @return string
public function getLogPath() */
{ public function getLogPath()
return $this->log_path; {
} return $this->log_path;
}
/**
* Set log Verbosity /**
* * Set log Verbosity
* @param int $log_verbosity *
* * @param int $log_verbosity
* 1 only incoming updates from webhook and getUpdates *
* 3 incoming updates from webhook and getUpdates and curl request info and response * 1 only incoming updates from webhook and getUpdates
* * 3 incoming updates from webhook and getUpdates and curl request info and response
* @return \Longman\TelegramBot\Telegram *
*/ * @return \Longman\TelegramBot\Telegram
public function setLogVerbosity($log_verbosity) */
{ public function setLogVerbosity($log_verbosity)
$this->log_verbosity = $log_verbosity; {
return $this; $this->log_verbosity = $log_verbosity;
} return $this;
}
/**
* Get log verbosity /**
* * Get log verbosity
* @return int *
*/ * @return int
public function getLogVerbosity() */
{ public function getLogVerbosity()
return $this->log_verbosity; {
} return $this->log_verbosity;
}
/**
* Set custom input string for debug purposes /**
* * Set custom input string for debug purposes
* @param string $input (json format) *
* * @param string $input (json format)
* @return \Longman\TelegramBot\Telegram *
*/ * @return \Longman\TelegramBot\Telegram
public function setCustomInput($input) */
{ public function setCustomInput($input)
$this->input = $input; {
return $this; $this->input = $input;
} return $this;
}
/**
* Get custom input string for debug purposes /**
* * Get custom input string for debug purposes
* @return string *
*/ * @return string
public function getCustomInput() */
{ public function getCustomInput()
return $this->input; {
} return $this->input;
}
/**
* Get the ServerResponse of the last Command execution /**
* * Get the ServerResponse of the last Command execution
* @return Entities\ServerResponse *
*/ * @return Entities\ServerResponse
public function getLastCommandResponse() */
{ public function getLastCommandResponse()
return $this->last_command_response; {
} return $this->last_command_response;
}
/**
* Handle getUpdates method /**
* * Handle getUpdates method
* @param int|null $limit *
* @param int|null $timeout * @param int|null $limit
* * @param int|null $timeout
* @return \Longman\TelegramBot\Entities\ServerResponse *
*/ * @return \Longman\TelegramBot\Entities\ServerResponse
public function handleGetUpdates($limit = null, $timeout = null) */
{ public function handleGetUpdates($limit = null, $timeout = null)
//DB Query {
$last_update = DB::selectTelegramUpdate(1); //DB Query
$last_update = DB::selectTelegramUpdate(1);
//As explained in the telegram bot api documentation
$offset = (isset($last_update[0]['id'])) ? $last_update[0]['id'] + 1 : null; //As explained in the telegram bot api documentation
$offset = (isset($last_update[0]['id'])) ? $last_update[0]['id'] + 1 : null;
$response = Request::getUpdates([
'offset' => $offset, $response = Request::getUpdates([
'limit' => $limit, 'offset' => $offset,
'timeout' => $timeout, 'limit' => $limit,
]); 'timeout' => $timeout,
]);
if ($response->isOk()) {
//Process all updates if ($response->isOk()) {
foreach ((array) $response->getResult() as $result) { //Process all updates
$this->processUpdate($result); foreach ((array) $response->getResult() as $result) {
} $this->processUpdate($result);
} }
}
return $response;
} return $response;
}
/**
* Handle bot request from webhook /**
* * Handle bot request from webhook
* @return bool *
*/ * @return bool
public function handle() */
{ public function handle()
$this->input = Request::getInput(); {
$this->input = Request::getInput();
if (empty($this->input)) {
throw new TelegramException('Input is empty!'); if (empty($this->input)) {
} throw new TelegramException('Input is empty!');
$post = json_decode($this->input, true); }
if (empty($post)) { $post = json_decode($this->input, true);
throw new TelegramException('Invalid JSON!'); if (empty($post)) {
} throw new TelegramException('Invalid JSON!');
}
return $this->processUpdate(new Update($post, $this->bot_name))->isOk();
} return $this->processUpdate(new Update($post, $this->bot_name))->isOk();
}
/**
* Get the command name from the command type /**
* * Get the command name from the command type
* @param string $type *
* * @param string $type
* @return string *
*/ * @return string
private function getCommandFromType($type) */
{ private function getCommandFromType($type)
return ucfirst(str_replace('_', '', $type)); {
} // return ucfirst(str_replace('_', '', $type));
return $this->mb_ucfirst(str_replace('_', '', $type));
/** }
* Process bot Update request
* /**
* @param Entities\Update $update * Process bot Update request
* *
* @return Entities\ServerResponse * @param Entities\Update $update
*/ *
public function processUpdate(Update $update) * @return Entities\ServerResponse
{ */
$this->update = $update; public function processUpdate(Update $update)
{
//If all else fails, it's a generic message. $this->update = $update;
$command = 'genericmessage';
//If all else fails, it's a generic message.
$update_type = $this->update->getUpdateType(); $command = 'genericmessage';
if (in_array($update_type, ['inline_query', 'chosen_inline_result'])) {
$command = $this->getCommandFromType($update_type); $update_type = $this->update->getUpdateType();
} elseif ($update_type === 'message') { if (in_array($update_type, ['inline_query', 'chosen_inline_result'])) {
$message = $this->update->getMessage(); $command = $this->getCommandFromType($update_type);
} elseif ($update_type === 'message') {
//Load admin commands $message = $this->update->getMessage();
if ($this->isAdmin()) {
$this->addCommandsPath(BASE_COMMANDS_PATH . '/AdminCommands', false); //Load admin commands
} if ($this->isAdmin()) {
$this->addCommandsPath(BASE_COMMANDS_PATH . '/AdminCommands', false);
$this->addCommandsPath(BASE_COMMANDS_PATH . '/UserCommands', false); }
$type = $message->getType(); $this->addCommandsPath(BASE_COMMANDS_PATH . '/UserCommands', false);
if ($type === 'command') {
$command = $message->getCommand(); $type = $message->getType();
} elseif (in_array($type, [ if ($type === 'command') {
'channel_chat_created', $command = $message->getCommand();
'delete_chat_photo', } elseif (in_array($type, [
'group_chat_created', 'channel_chat_created',
'left_chat_participant', 'delete_chat_photo',
'migrate_from_chat_id', 'group_chat_created',
'migrate_to_chat_id', 'left_chat_participant',
'new_chat_participant', 'migrate_from_chat_id',
'new_chat_photo', 'migrate_to_chat_id',
'new_chat_title', 'new_chat_participant',
'supergroup_chat_created', 'new_chat_photo',
])) { 'new_chat_title',
$command = $this->getCommandFromType($type); 'supergroup_chat_created',
} ])) {
} $command = $this->getCommandFromType($type);
}
//Make sure we have an up-to-date command list }
//This is necessary to "require" all the necessary command files!
$this->getCommandsList(); //Make sure we have an up-to-date command list
//This is necessary to "require" all the necessary command files!
DB::insertRequest($this->update); $this->getCommandsList();
return $this->executeCommand($command); DB::insertRequest($this->update);
}
return $this->executeCommand($command);
/** }
* Execute /command
* /**
* @param string $command * Execute /command
* *
* @return mixed * @param string $command
*/ *
public function executeCommand($command) * @return mixed
{ */
$command_obj = $this->getCommandObject($command); public function executeCommand($command)
{
if (!$command_obj || !$command_obj->isEnabled()) { $command_obj = $this->getCommandObject($command);
//Failsafe in case the Generic command can't be found
if ($command === 'Generic') { if (!$command_obj || !$command_obj->isEnabled()) {
throw new TelegramException('Generic command missing!'); //Failsafe in case the Generic command can't be found
} if ($command === 'Generic') {
throw new TelegramException('Generic command missing!');
//Handle a generic command or non existing one }
$this->last_command_response = $this->executeCommand('Generic');
} else { //Handle a generic command or non existing one
//execute() method is executed after preExecute() $this->last_command_response = $this->executeCommand('Generic');
//This is to prevent executing a DB query without a valid connection } else {
$this->last_command_response = $command_obj->preExecute(); //execute() method is executed after preExecute()
} //This is to prevent executing a DB query without a valid connection
$this->last_command_response = $command_obj->preExecute();
return $this->last_command_response; }
}
return $this->last_command_response;
/** }
* @todo Complete DocBlock
*/ /**
protected function sanitizeCommand($command) * @todo Complete DocBlock
{ */
return str_replace(' ', '', ucwords(str_replace('_', ' ', $command))); protected function sanitizeCommand($command)
} {
// return str_replace(' ', '', ucwords(str_replace('_', ' ', $command)));
/** return str_replace(' ', '', $this->mb_ucwords(str_replace('_', ' ', $command)));
* Enable Admin Account }
*
* @param array $admins_list List of admins /**
* * Enable Admin Account
* @return string *
*/ * @param array $admins_list List of admins
public function enableAdmins(array $admins_list) *
{ * @return string
foreach ($admins_list as $admin) { */
if ($admin > 0) { public function enableAdmins(array $admins_list)
$this->admins_list[] = $admin; {
} else { foreach ($admins_list as $admin) {
throw new TelegramException('Invalid value "' . $admin . '" for admin!'); if ($admin > 0) {
} $this->admins_list[] = $admin;
} } else {
throw new TelegramException('Invalid value "' . $admin . '" for admin!');
return $this; }
} }
/** return $this;
* Get list of admins }
*
* @return array /**
*/ * Get list of admins
public function getAdminList() *
{ * @return array
return $this->admins_list; */
} public function getAdminList()
{
/** return $this->admins_list;
* Check if the passed user is an admin }
*
* If no user id is passed, the current update is checked for a valid message sender. /**
* * Check if the passed user is an admin
* @param int|null $user_id *
* * If no user id is passed, the current update is checked for a valid message sender.
* @return bool *
*/ * @param int|null $user_id
public function isAdmin($user_id = null) *
{ * @return bool
if ($user_id === null && $this->update !== null) { */
if (($message = $this->update->getMessage()) && ($from = $message->getFrom())) { public function isAdmin($user_id = null)
$user_id = $from->getId(); {
} if ($user_id === null && $this->update !== null) {
} if (($message = $this->update->getMessage()) && ($from = $message->getFrom())) {
$user_id = $from->getId();
return ($user_id === null) ? false : in_array($user_id, $this->admins_list); }
} }
/** return ($user_id === null) ? false : in_array($user_id, $this->admins_list);
* Check if user required the db connection }
*
* @return bool /**
*/ * Check if user required the db connection
public function isDbEnabled() *
{ * @return bool
if ($this->mysql_enabled) { */
return true; public function isDbEnabled()
} else { {
return false; if ($this->mysql_enabled) {
} return true;
} } else {
return false;
/** }
* Add custom commands path }
*
* @param string $path Custom commands path /**
* @param bool $before If the path should be prepended or appended to the list * Add custom commands path
* *
* @return \Longman\TelegramBot\Telegram * @param string $path Custom commands path
*/ * @param bool $before If the path should be prepended or appended to the list
public function addCommandsPath($path, $before = true) *
{ * @return \Longman\TelegramBot\Telegram
if (!is_dir($path)) { */
throw new TelegramException('Commands path "' . $path . '" does not exist!'); public function addCommandsPath($path, $before = true)
} {
if (!in_array($path, $this->commands_paths)) { if (!is_dir($path)) {
if ($before) { throw new TelegramException('Commands path "' . $path . '" does not exist!');
array_unshift($this->commands_paths, $path); }
} else { if (!in_array($path, $this->commands_paths)) {
array_push($this->commands_paths, $path); if ($before) {
} array_unshift($this->commands_paths, $path);
} } else {
return $this; array_push($this->commands_paths, $path);
} }
}
/** return $this;
* Set custom upload path }
*
* @param string $path Custom upload path /**
* * Set custom upload path
* @return \Longman\TelegramBot\Telegram *
*/ * @param string $path Custom upload path
public function setUploadPath($path) *
{ * @return \Longman\TelegramBot\Telegram
$this->upload_path = $path; */
return $this; public function setUploadPath($path)
} {
$this->upload_path = $path;
/** return $this;
* Get custom upload path }
*
* @return string /**
*/ * Get custom upload path
public function getUploadPath() *
{ * @return string
return $this->upload_path; */
} public function getUploadPath()
{
/** return $this->upload_path;
* Set custom download path }
*
* @param string $path Custom download path /**
* * Set custom download path
* @return \Longman\TelegramBot\Telegram *
*/ * @param string $path Custom download path
public function setDownloadPath($path) *
{ * @return \Longman\TelegramBot\Telegram
$this->download_path = $path; */
return $this; public function setDownloadPath($path)
} {
$this->download_path = $path;
/** return $this;
* Get custom download path }
*
* @return string /**
*/ * Get custom download path
public function getDownloadPath() *
{ * @return string
return $this->download_path; */
} public function getDownloadPath()
{
/** return $this->download_path;
* Set command config }
*
* Provide further variables to a particular commands. /**
* For example you can add the channel name at the command /sendtochannel * Set command config
* Or you can add the api key for external service. *
* * Provide further variables to a particular commands.
* @param string $command * For example you can add the channel name at the command /sendtochannel
* @param array $config * Or you can add the api key for external service.
* *
* @return \Longman\TelegramBot\Telegram * @param string $command
*/ * @param array $config
public function setCommandConfig($command, array $config) *
{ * @return \Longman\TelegramBot\Telegram
$this->commands_config[$command] = $config; */
return $this; public function setCommandConfig($command, array $config)
} {
$this->commands_config[$command] = $config;
/** return $this;
* Get command config }
*
* @param string $command /**
* * Get command config
* @return array *
*/ * @param string $command
public function getCommandConfig($command) *
{ * @return array
return isset($this->commands_config[$command]) ? $this->commands_config[$command] : []; */
} public function getCommandConfig($command)
{
/** return isset($this->commands_config[$command]) ? $this->commands_config[$command] : [];
* Get API key }
*
* @return string /**
*/ * Get API key
public function getApiKey() *
{ * @return string
return $this->api_key; */
} public function getApiKey()
{
/** return $this->api_key;
* Get Bot name }
*
* @return string /**
*/ * Get Bot name
public function getBotName() *
{ * @return string
return $this->bot_name; */
} public function getBotName()
{
/** return $this->bot_name;
* Get Version }
*
* @return string /**
*/ * Get Version
public function getVersion() *
{ * @return string
return $this->version; */
} public function getVersion()
{
/** return $this->version;
* Set Webhook for bot }
*
* @param string $url /**
* @param string|null $path_certificate * Set Webhook for bot
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @param string $url
*/ * @param string|null $path_certificate
public function setWebHook($url, $path_certificate = null) *
{ * @return \Longman\TelegramBot\Entities\ServerResponse
if (empty($url)) { */
throw new TelegramException('Hook url is empty!'); public function setWebHook($url, $path_certificate = null)
} {
if (empty($url)) {
$result = Request::setWebhook($url, $path_certificate); throw new TelegramException('Hook url is empty!');
}
if (!$result->isOk()) {
throw new TelegramException( $result = Request::setWebhook($url, $path_certificate);
'Webhook was not set! Error: ' . $result->getErrorCode() . ' ' . $result->getDescription()
); if (!$result->isOk()) {
} throw new TelegramException(
'Webhook was not set! Error: ' . $result->getErrorCode() . ' ' . $result->getDescription()
return $result; );
} }
/** return $result;
* Unset Webhook for bot }
*
* @return \Longman\TelegramBot\Entities\ServerResponse /**
*/ * Unset Webhook for bot
public function unsetWebHook() *
{ * @return \Longman\TelegramBot\Entities\ServerResponse
$result = Request::setWebhook(); */
public function unsetWebHook()
if (!$result->isOk()) { {
throw new TelegramException( $result = Request::setWebhook();
'Webhook was not unset! Error: ' . $result->getErrorCode() . ' ' . $result->getDescription()
); if (!$result->isOk()) {
} throw new TelegramException(
'Webhook was not unset! Error: ' . $result->getErrorCode() . ' ' . $result->getDescription()
return $result; );
} }
}
return $result;
}
/**
* Replace function `ucwords` for UTF-8 characters in the class definition and commands
*
* @param string $str
* @param string $encoding (default = 'UTF-8')
*
* @return string
*/
protected function mb_ucwords($str, $encoding = 'UTF-8') {
return mb_convert_case($str, MB_CASE_TITLE, $encoding);
}
/**
* Replace function `ucfirst` for UTF-8 characters in the class definition and commands
*
* @param string $str
* @param string $encoding (default = 'UTF-8')
*
* @return string
*/
protected function mb_ucfirst($str, $encoding = 'UTF-8') {
return mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding) . mb_strtolower(mb_substr($str, 1, mb_strlen($str), $encoding), $encoding);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment