From bf0b8268de562efeb98aac2b543ea072a4fe9a90 Mon Sep 17 00:00:00 2001 From: netkas Date: Sun, 6 Oct 2024 16:13:03 -0400 Subject: [PATCH] Updated Bot --- src/TgBotLib/Bot.php | 104 +++++++++++++++++++++++++++++-------------- 1 file changed, 70 insertions(+), 34 deletions(-) diff --git a/src/TgBotLib/Bot.php b/src/TgBotLib/Bot.php index 800eebe..02adbec 100644 --- a/src/TgBotLib/Bot.php +++ b/src/TgBotLib/Bot.php @@ -1,45 +1,81 @@ token = $token; - $this->endpoint = $endpoint; - } + private string $token; + private string $endpoint; - public function setToken(string $token): void - { - $this->token = $token; - } - - public function getToken(): string - { - return $this->token; - } - - public function setEndpoint(string $endpoint): void - { - $this->endpoint = $endpoint; - } - - public function getEndpoint(string $method=null): string - { - if($method) + /** + * Constructs a new Bot instance + * + * @param string $token The bot token provided by BotFather + * @param string $endpoint The API endpoint to use + */ + public function __construct(string $token, string $endpoint='https://api.telegram.org') { - return sprintf('%s/bot%s/%s', $this->endpoint, $this->token, $method); + $this->token = $token; + $this->endpoint = $endpoint; } - return $this->endpoint; - } + /** + * Sets the token for the bot. + * + * @param string $token The bot token provided by BotFather + * @return void + */ + public function setToken(string $token): void + { + $this->token = $token; + } - public function sendRequest(string $method, array $parameters=[]): array - { + /** + * Retrieves the bot's token + * + * @return string The bot token + */ + public function getToken(): string + { + return $this->token; + } - } -} \ No newline at end of file + /** + * Sets the API endpoint. + * + * @param string $endpoint The new API endpoint to be set. + * @return void + */ + public function setEndpoint(string $endpoint): void + { + $this->endpoint = $endpoint; + } + + /** + * Retrieves the API endpoint or constructs a specific method endpoint + * + * @param string|null $method Optional method name to append to the endpoint + * @return string The complete API endpoint URL + */ + public function getEndpoint(string $method=null): string + { + if($method) + { + return sprintf('%s/bot%s/%s', $this->endpoint, $this->token, $method); + } + + return $this->endpoint; + } + + public function sendRequest(string $method, array $parameters=[]): array + { + + } + } \ No newline at end of file