feat: new chain
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Telegram;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
/**
|
||||
* Request-scoped Telegram bot identity.
|
||||
* null agent = official system bot; otherwise an agent-configured bot.
|
||||
*/
|
||||
class TelegramBotContext
|
||||
{
|
||||
private ?User $agent = null;
|
||||
|
||||
public function setAgent(?User $agent): void
|
||||
{
|
||||
$this->agent = $agent;
|
||||
}
|
||||
|
||||
public function agent(): ?User
|
||||
{
|
||||
return $this->agent;
|
||||
}
|
||||
|
||||
public function isOfficial(): bool
|
||||
{
|
||||
return $this->agent === null;
|
||||
}
|
||||
|
||||
public function isAgent(): bool
|
||||
{
|
||||
return $this->agent !== null;
|
||||
}
|
||||
|
||||
public function expectedChatId(): string
|
||||
{
|
||||
if ($this->agent !== null) {
|
||||
return trim((string) ($this->agent->chat_id ?? ''));
|
||||
}
|
||||
|
||||
return trim((string) config('coruna.telegram.owner_chat_id', ''));
|
||||
}
|
||||
|
||||
public static function webhookSecretFor(User $agent): string
|
||||
{
|
||||
return hash_hmac('sha256', 'telegram-agent:'.$agent->id, (string) config('app.key'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user