Commit ca48e792 authored by Jack'lul's avatar Jack'lul

Rename variables 'bot_name' and similar to 'bot_username' to prevent confusion

parent b2ec9768
......@@ -14,7 +14,7 @@ require __DIR__ . '/vendor/autoload.php';
// Add you bot's API key and name
$API_KEY = 'your_bot_api_key';
$BOT_NAME = 'username_bot';
$BOT_USERNAME = 'username_bot';
// Define a path for your custom commands
//$commands_path = __DIR__ . '/Commands/';
......@@ -29,7 +29,7 @@ $mysql_credentials = [
try {
// Create Telegram API object
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_USERNAME);
// Error, Debug and Raw Update logging
//Longman\TelegramBot\TelegramLog::initialize($your_external_monolog_instance);
......
......@@ -13,7 +13,7 @@ require __DIR__ . '/vendor/autoload.php';
// Add you bot's API key and name
$API_KEY = 'your_bot_api_key';
$BOT_NAME = 'username_bot';
$BOT_USERNAME = 'username_bot';
// Define a path for your custom commands
//$commands_path = __DIR__ . '/Commands/';
......@@ -28,7 +28,7 @@ $BOT_NAME = 'username_bot';
try {
// Create Telegram API object
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_USERNAME);
// Error, Debug and Raw Update logging
//Longman\TelegramBot\TelegramLog::initialize($your_external_monolog_instance);
......
......@@ -3,11 +3,12 @@
require __DIR__ . '/vendor/autoload.php';
$API_KEY = 'your_bot_api_key';
$BOT_NAME = 'username_bot';
$BOT_USERNAME = 'username_bot';
$hook_url = 'https://yourdomain/path/to/hook.php';
try {
// Create Telegram API object
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_USERNAME);
// Set webhook
$result = $telegram->setWebhook($hook_url);
......
......@@ -3,10 +3,11 @@
require __DIR__ . '/vendor/autoload.php';
$API_KEY = 'your_bot_api_key';
$BOT_NAME = 'username_bot';
$BOT_USERNAME = 'username_bot';
try {
// Create Telegram API object
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_USERNAME);
// Delete webhook
$result = $telegram->deleteWebhook();
......
......@@ -29,14 +29,14 @@ abstract class Entity
/**
* Entity constructor.
*
* @todo Get rid of the $bot_name, it shouldn't be here!
* @todo Get rid of the $bot_username, it shouldn't be here!
*
* @param array $data
* @param string $bot_name
* @param string $bot_username
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct($data, $bot_name = '')
public function __construct($data, $bot_username = '')
{
//Make sure we're not raw_data inception-ing
if (array_key_exists('raw_data', $data)) {
......@@ -47,7 +47,7 @@ abstract class Entity
$data['raw_data'] = $data;
}
$data['bot_name'] = $bot_name;
$data['bot_username'] = $bot_username;
$this->assignMemberVariables($data);
$this->validate();
}
......@@ -142,7 +142,7 @@ abstract class Entity
$sub_entities = $this->subEntities();
if (isset($sub_entities[$property_name])) {
return new $sub_entities[$property_name]($property, $this->getProperty('bot_name'));
return new $sub_entities[$property_name]($property, $this->getProperty('bot_username'));
}
return $property;
......
......@@ -79,11 +79,11 @@ class Message extends Entity
* Message constructor
*
* @param array $data
* @param string $bot_name
* @param string $bot_username
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data, $bot_name = '')
public function __construct(array $data, $bot_username = '')
{
//Retro-compatibility
if (isset($data['new_chat_participant'])) {
......@@ -95,7 +95,7 @@ class Message extends Entity
unset($data['left_chat_participant']);
}
parent::__construct($data, $bot_name);
parent::__construct($data, $bot_username);
}
/**
......
......@@ -21,16 +21,16 @@ class ReplyToMessage extends Message
* ReplyToMessage constructor.
*
* @param array $data
* @param string $bot_name
* @param string $bot_username
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data, $bot_name = '')
public function __construct(array $data, $bot_username = '')
{
//As explained in the documentation
//Reply to message can't contain other reply to message entities
unset($data['reply_to_message']);
parent::__construct($data, $bot_name);
parent::__construct($data, $bot_username);
}
}
......@@ -26,11 +26,11 @@ class ServerResponse extends Entity
* ServerResponse constructor.
*
* @param array $data
* @param string $bot_name
* @param string $bot_username
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data, $bot_name)
public function __construct(array $data, $bot_username)
{
// Make sure we don't double-save the raw_data
unset($data['raw_data']);
......@@ -41,13 +41,13 @@ class ServerResponse extends Entity
if ($is_ok && is_array($result)) {
if ($this->isAssoc($result)) {
$data['result'] = $this->createResultObject($result, $bot_name);
$data['result'] = $this->createResultObject($result, $bot_username);
} else {
$data['result'] = $this->createResultObjects($result, $bot_name);
$data['result'] = $this->createResultObjects($result, $bot_username);
}
}
parent::__construct($data, $bot_name);
parent::__construct($data, $bot_username);
}
/**
......@@ -88,12 +88,12 @@ class ServerResponse extends Entity
* Create and return the object of the received result
*
* @param array $result
* @param string $bot_name
* @param string $bot_username
*
* @return \Longman\TelegramBot\Entities\Chat|\Longman\TelegramBot\Entities\ChatMember|\Longman\TelegramBot\Entities\File|\Longman\TelegramBot\Entities\Message|\Longman\TelegramBot\Entities\User|\Longman\TelegramBot\Entities\UserProfilePhotos|\Longman\TelegramBot\Entities\WebhookInfo
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
private function createResultObject($result, $bot_name)
private function createResultObject($result, $bot_username)
{
// We don't need to save the raw_data of the response object!
$result['raw_data'] = null;
......@@ -115,19 +115,19 @@ class ServerResponse extends Entity
}
//Response from sendMessage
return new Message($result, $bot_name);
return new Message($result, $bot_username);
}
/**
* Create and return the objects array of the received result
*
* @param array $result
* @param string $bot_name
* @param string $bot_username
*
* @return null|\Longman\TelegramBot\Entities\ChatMember[]|\Longman\TelegramBot\Entities\Update[]
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
private function createResultObjects($result, $bot_name)
private function createResultObjects($result, $bot_username)
{
$results = [];
if (isset($result[0]['user'])) {
......@@ -144,7 +144,7 @@ class ServerResponse extends Entity
// We don't need to save the raw_data of the response object!
$update['raw_data'] = null;
$results[] = new Update($update, $bot_name);
$results[] = new Update($update, $bot_username);
}
}
......
......@@ -315,12 +315,12 @@ class Request
{
self::ensureValidAction($action);
$bot_name = self::$telegram->getBotName();
$bot_username = self::$telegram->getBotUsername();
if (defined('PHPUNIT_TESTSUITE')) {
$fake_response = self::generateGeneralFakeServerResponse($data);
return new ServerResponse($fake_response, $bot_name);
return new ServerResponse($fake_response, $bot_username);
}
self::ensureNonEmptyData($data);
......@@ -333,7 +333,7 @@ class Request
throw new TelegramException('Telegram returned an invalid response! Please review your bot name and API key.');
}
return new ServerResponse($response, $bot_name);
return new ServerResponse($response, $bot_username);
}
/**
......
......@@ -40,11 +40,11 @@ class Telegram
protected $api_key = '';
/**
* Telegram Bot name
* Telegram Bot username
*
* @var string
*/
protected $bot_name = '';
protected $bot_username = '';
/**
* Telegram Bot id
......@@ -134,22 +134,22 @@ class Telegram
* Telegram constructor.
*
* @param string $api_key
* @param string $bot_name
* @param string $bot_username
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct($api_key, $bot_name)
public function __construct($api_key, $bot_username)
{
if (empty($api_key)) {
throw new TelegramException('API KEY not defined!');
}
if (empty($bot_name)) {
if (empty($bot_username)) {
throw new TelegramException('Bot Username not defined!');
}
$this->api_key = $api_key;
$this->bot_name = $bot_name;
$this->bot_username = $bot_username;
preg_match("/([0-9]*)\:.*/", $this->api_key, $matches);
$this->bot_id = $matches[1];
......@@ -319,7 +319,7 @@ class Telegram
'ok' => false,
'description' => 'getUpdates needs MySQL connection!',
],
$this->bot_name
$this->bot_username
);
}
......@@ -369,7 +369,7 @@ class Telegram
throw new TelegramException('Invalid JSON!');
}
if ($response = $this->processUpdate(new Update($post, $this->bot_name))) {
if ($response = $this->processUpdate(new Update($post, $this->bot_username))) {
return $response->isOk();
}
......@@ -733,9 +733,21 @@ class Telegram
*
* @return string
*/
public function getBotUsername()
{
return $this->bot_username;
}
/**
* Get Bot name
* @todo: Left for backwards compatibility, remove in the future
*
* @return string
*/
public function getBotName()
{
return $this->bot_name;
TelegramLog::debug('Usage of deprecated method getBotName() detected, please use getBotUsername() instead!');
return $this->getBotUsername();
}
/**
......
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