feat: new chain
This commit is contained in:
@@ -2,16 +2,28 @@
|
||||
|
||||
namespace App\Telegram\Middleware;
|
||||
|
||||
use App\Telegram\TelegramBotContext;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use SergiX44\Nutgram\Nutgram;
|
||||
use SergiX44\Nutgram\Telegram\Properties\ChatType;
|
||||
|
||||
/**
|
||||
* Allow only the configured owner group/supergroup for the current bot context
|
||||
* (official system chat or the active agent's chat_id).
|
||||
*/
|
||||
class AuthorizedChat
|
||||
{
|
||||
public function __construct(
|
||||
private readonly TelegramBotContext $context,
|
||||
) {}
|
||||
|
||||
public function __invoke(Nutgram $bot, callable $next): mixed
|
||||
{
|
||||
$expected = (string) config('coruna.telegram.owner_chat_id', '');
|
||||
$expected = $this->context->expectedChatId();
|
||||
if ($expected === '') {
|
||||
Log::warning('telegram AuthorizedChat: TELEGRAM_OWNER_CHAT_ID empty');
|
||||
Log::warning('telegram AuthorizedChat: chat id empty', [
|
||||
'agent_id' => $this->context->agent()?->id,
|
||||
]);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -21,6 +33,18 @@ class AuthorizedChat
|
||||
Log::info('telegram AuthorizedChat: chat rejected', [
|
||||
'chat_id' => $chatId,
|
||||
'expected' => $expected,
|
||||
'agent_id' => $this->context->agent()?->id,
|
||||
]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$type = $bot->chat()?->type;
|
||||
$typeValue = $type instanceof ChatType ? $type->value : (string) $type;
|
||||
if (! in_array($typeValue, [ChatType::GROUP->value, ChatType::SUPERGROUP->value, 'group', 'supergroup'], true)) {
|
||||
Log::info('telegram AuthorizedChat: not a group chat', [
|
||||
'chat_id' => $chatId,
|
||||
'type' => $typeValue,
|
||||
]);
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user