Created
October 18, 2024 06:30
-
-
Save 1stevengrant/995b8736457091b70fc532f43c96963f to your computer and use it in GitHub Desktop.
Revisions
-
1stevengrant created this gist
Oct 18, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ <?php namespace App\Services; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; class TelegramService { public function __construct( private string $botToken = '', private string $chatId = '' ) { $this->botToken = $this->botToken ?: config('services.telegram.token'); $this->chatId = $this->chatId ?: config('services.telegram.chat_id'); } public function sendMessage($message): bool { $response = Http::post("https://api.telegram.org/bot{$this->botToken}/sendMessage", [ 'chat_id' => $this->chatId, 'text' => $message, ]); if ($response->successful()) { Log::info("Telegram message sent successfully"); return true; } else { Log::error("Failed to send Telegram message: " . $response->body()); return false; } } }