Skip to content

Commit

Permalink
use const; add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKrisKrisu committed Jul 30, 2024
1 parent 40db0df commit 9a1c573
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/Services/TelegramService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
class TelegramService
{

const TELEGRAM_API_URL = 'https://api.telegram.org/bot';

private string $chatId;
private string $token;

Expand All @@ -18,13 +20,16 @@ public function __construct(string $chatId, string $token) {
public static function isAdminActive(): bool {
return config('services.telegram.admin.active');
}

public static function admin(): self {
return new self(config('services.telegram.admin.chat_id'), config('services.telegram.admin.token'));
}

/**
* @return int Telegram Message ID
*/
public function sendMessage(string $text, string $parseMode = 'HTML'): int {
$response = Http::post('https://api.telegram.org/bot' . $this->token . '/sendMessage', [
$response = Http::post(self::TELEGRAM_API_URL . $this->token . '/sendMessage', [
'chat_id' => $this->chatId,
'text' => $text,
'parse_mode' => $parseMode,
Expand All @@ -33,7 +38,7 @@ public function sendMessage(string $text, string $parseMode = 'HTML'): int {
}

public function deleteMessage(int $messageId): void {
Http::post('https://api.telegram.org/bot' . $this->token . '/deleteMessage', [
Http::post(self::TELEGRAM_API_URL . $this->token . '/deleteMessage', [
'chat_id' => $this->chatId,
'message_id' => $messageId,
]);
Expand Down

0 comments on commit 9a1c573

Please sign in to comment.