-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ remove closed reports from backend chat (#2802)
- Loading branch information
1 parent
2b86773
commit 0e00b7d
Showing
10 changed files
with
143 additions
and
107 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,17 +59,14 @@ MIX_LEGAL_ADDRESS2="12345 Musterstadt" | |
MIX_LEGAL_EMAIL="[email protected]" | ||
MIX_LEGAL_TEL="01234 / 56789" | ||
|
||
# Telegram Bot credentials. Currently only used for the admin backend | ||
TELEGRAM_ADMIN_ID=123456789 | ||
TELEGRAM_TOKEN=12345678:abcdefghijklmnop | ||
|
||
# Should the year in review be visible to the users? | ||
YEAR_IN_REVIEW_BACKEND=false | ||
YEAR_IN_REVIEW_ALERT=false | ||
|
||
# Webhook urls which will be called when a new event is suggested | ||
ADMIN_NOTIFICATION_URL=https://api.telegram.org/bot.../sendMessage | ||
ADMIN_NOTIFICATION_CHAT_ID=123456789 | ||
# Telegram Bot credentials - used for admin notifications | ||
TELEGRAM_ADMIN_ACTIVE=false # Set to true to enable Telegram notifications | ||
TELEGRAM_ADMIN_TOKEN=0000000000:0000000000000000000000000000 | ||
TELEGRAM_ADMIN_CHAT_ID=123456789 | ||
|
||
# Shall webhooks actually call other servers? Default is off to work privacy-preserving. | ||
WEBHOOKS_ACTIVE=true | ||
|
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace App\Services; | ||
|
||
use Illuminate\Support\Facades\Http; | ||
|
||
class TelegramService | ||
{ | ||
|
||
const TELEGRAM_API_URL = 'https://api.telegram.org/bot'; | ||
|
||
private string $chatId; | ||
private string $token; | ||
|
||
public function __construct(string $chatId, string $token) { | ||
$this->chatId = $chatId; | ||
$this->token = $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(self::TELEGRAM_API_URL . $this->token . '/sendMessage', [ | ||
'chat_id' => $this->chatId, | ||
'text' => $text, | ||
'parse_mode' => $parseMode, | ||
]); | ||
return $response->json('result.message_id'); | ||
} | ||
|
||
public function deleteMessage(int $messageId): void { | ||
Http::post(self::TELEGRAM_API_URL . $this->token . '/deleteMessage', [ | ||
'chat_id' => $this->chatId, | ||
'message_id' => $messageId, | ||
]); | ||
} | ||
} |
This file contains 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 characters
This file contains 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 characters
20 changes: 20 additions & 0 deletions
20
database/migrations/2024_07_30_000000_add_admin_notification_id_to_reports.php
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
public function up(): void { | ||
Schema::table('reports', static function(Blueprint $table) { | ||
$table->unsignedBigInteger('admin_notification_id')->nullable()->after('reporter_id'); | ||
}); | ||
} | ||
|
||
public function down(): void { | ||
Schema::table('reports', static function(Blueprint $table) { | ||
$table->dropColumn('admin_notification_id'); | ||
}); | ||
} | ||
}; |