63 lines
1.6 KiB
PHP
Executable File
63 lines
1.6 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* Represents a Telegram user connection with their own bot configuration.
|
|
*
|
|
* @property int $id
|
|
* @property int $user_id
|
|
* @property string $telegram_user_id
|
|
* @property string|null $bot_token User's own Telegram bot token
|
|
* @property string|null $bot_username User's own Telegram bot username
|
|
* @property string|null $chat_id Telegram chat ID for sending messages
|
|
* @property string|null $telegram_username
|
|
* @property string|null $telegram_first_name
|
|
* @property string|null $telegram_last_name
|
|
* @property bool $is_active
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @property-read User $user
|
|
*/
|
|
class TelegramUser extends Model
|
|
{
|
|
/** @var array<int, string> */
|
|
protected $fillable = [
|
|
'user_id',
|
|
'telegram_user_id',
|
|
'bot_token',
|
|
'bot_username',
|
|
'chat_id',
|
|
'telegram_username',
|
|
'telegram_first_name',
|
|
'telegram_last_name',
|
|
'is_active',
|
|
];
|
|
|
|
/** @var array<string, string> */
|
|
protected $casts = [
|
|
'is_active' => 'boolean',
|
|
];
|
|
|
|
/**
|
|
* Get the user associated with this telegram user.
|
|
*/
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* Check if the user has a fully configured bot.
|
|
*/
|
|
public function isFullyConfigured(): bool
|
|
{
|
|
return !empty($this->bot_token) && !empty($this->chat_id);
|
|
}
|
|
}
|