Skip to content

Added release info messages to chats #280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added release info messages to chats
  • Loading branch information
bald-cat committed Mar 30, 2025
commit 6b08230470ba64b5d2c581f4833795e36c8c068c
40 changes: 40 additions & 0 deletions app/Http/Controllers/GithubWebHookController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Http\Controllers;

use App\Services\Telegram\TelegramBot;
use Illuminate\Http\Request;

class GithubWebHookController extends Controller
{
/**
* Handle incoming Telegram webhook requests.
*
* @param \Illuminate\Http\Request $request
* @param TelegramBot $telegramBot
*
* @return void
* @throws \Throwable
*/
public function release(Request $request, TelegramBot $telegramBot)
{
$payload = $request->all();

if ($payload['action'] === 'published') {
$release = $payload['release'];
$repo = $payload['repository'];

$message = view('telegram.github-release-notification', [
'repo' => $repo['full_name'],
'version' => $release['tag_name'],
'title' => $release['name'],
'body' => $release['body'],
'url' => $release['html_url']
])->render();

collect(config('telegram.chats'))
->where('orchid_release', true)
->each(fn($subscriber) => $telegramBot->sendMessageToChat($subscriber['id'], $message));
}
}
}
2 changes: 0 additions & 2 deletions app/Http/Controllers/WebHookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public function telegram(Request $request): void
);
}

Log::channel('telegram')->info(json_encode($request->all()));

TelegramMessage::dispatch(
$request->collect('message'),
$captcha,
Expand Down
12 changes: 12 additions & 0 deletions app/Services/Telegram/TelegramBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,16 @@ public function sendWelcomeButton($chatId, $userId, $name)

return null;
}

public function sendMessageToChat(int $chatId, string $message): Response
{
$url = "https://api.telegram.org/bot{$this->token}/sendMessage";

return Http::post($url, [
'chat_id' => $chatId,
'text' => $message,
'parse_mode' => 'Markdown',
]);
}

}
11 changes: 7 additions & 4 deletions config/telegram.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php

return [
'chats' => [
'chats' => [
[
'id' => '-1002111700088',
'name' => 'Ахтунг laravel.su чат',
'locale' => 'en',
'id' => '-1002111700088',
'name' => 'Ахтунг laravel.su чат',
'locale' => 'en',
'orchid_release' => true,
],
[
'id' => '-1001300166722',
Expand All @@ -16,11 +17,13 @@
'id' => '-1001450006147',
'name' => 'Laravel Orchid',
'locale' => 'en',
'orchid_release' => true,
],
[
'id' => '-1001104353296',
'name' => 'Laravel Framework Russian Community',
'locale' => 'ru',
'orchid_release' => true,
],
],
'default_locale' => 'ru',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🚀 *New release {{ $version }}* in {{ $repo }}

📝 *{{ $title }}*

{{ $body }}

[🔗 Link to release]({{ $url }})
3 changes: 3 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Http\Controllers\GithubWebHookController;
use App\Http\Controllers\WebHookController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
Expand All @@ -20,3 +21,5 @@
});

Route::post('/webhook/telegram', [WebHookController::class, 'telegram'])->name('webhook.telegram');

Route::post('/webhook/github/release', [GithubWebHookController::class, 'release'])->name('webhook.github.release');
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Http\Controllers\ChallengesController;
use App\Http\Controllers\CommentsController;
use App\Http\Controllers\DocsController;
use App\Http\Controllers\GithubWebHookController;
use App\Http\Controllers\LikeController;
use App\Http\Controllers\MeetController;
use App\Http\Controllers\PackagesController;
Expand All @@ -26,6 +27,8 @@
|
*/

Route::get('/webhook/github/release', [GithubWebHookController::class, 'release'])->name('webhook.github.release');

Route::view('/', 'pages.welcome')->name('home');
Route::view('/feature', 'pages.feature')->name('feature');
Route::view('/advertising', 'pages.advertising')->name('advertising');
Expand Down
Loading