Updated Bot
This commit is contained in:
parent
0f7e2641e7
commit
bf0b8268de
1 changed files with 70 additions and 34 deletions
|
@ -1,45 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace TgBotLib;
|
||||
/**
|
||||
* Constructs a new Bot instance.
|
||||
*
|
||||
* @param string $token The bot token provided by BotFather.
|
||||
* @param string $endpoint The API endpoint to use.
|
||||
*/
|
||||
|
||||
class Bot
|
||||
{
|
||||
private string $token;
|
||||
private string $endpoint;
|
||||
namespace TgBotLib;
|
||||
|
||||
public function __construct(string $token, string $endpoint='https://api.telegram.org')
|
||||
class Bot
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue