refactor(telegram): share administrator delivery channel
parent
0a8a318291
commit
fa66714db9
@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Telegram;
|
||||
|
||||
use App\Models\Configurations;
|
||||
use App\Models\User;
|
||||
use App\Services\Config;
|
||||
use App\Services\TicketTelegramConfig;
|
||||
|
||||
/**
|
||||
* Shared low-level administrator Telegram channel.
|
||||
*
|
||||
* It owns only authoritative destination resolution and a single remote send.
|
||||
* Ticket and abuse-alert ledgers, formatting and reply semantics stay outside.
|
||||
*/
|
||||
final class AdministratorTelegramChannel
|
||||
{
|
||||
private const ALLOWED_OPTIONS = [
|
||||
'reply_to_message_id',
|
||||
'allow_sending_without_reply',
|
||||
'disable_web_page_preview',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
private readonly AdministratorTelegramTransport $transport = new TelegramBotApiTransport()
|
||||
) {}
|
||||
|
||||
public function eligibleAdministrator(int $administratorId): bool
|
||||
{
|
||||
$allowed = array_map('intval', explode(',', (string) Config::get('super_admin', '')));
|
||||
if ($administratorId <= 0 || !in_array($administratorId, $allowed, true)) {
|
||||
return false;
|
||||
}
|
||||
$user = User::find($administratorId);
|
||||
return $user !== null && (bool) $user->is_admin && (int) $user->enable === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the authoritative private-chat destination. Old binding rows are
|
||||
* upgraded once with a generation while holding the configuration row lock.
|
||||
*/
|
||||
public function currentDestination(): ?AdministratorTelegramDestination
|
||||
{
|
||||
try {
|
||||
$runtime = TicketTelegramConfig::runtimeForDelivery();
|
||||
} catch (\Throwable $exception) {
|
||||
throw new AdministratorTelegramLocalUnavailable(
|
||||
'Administrator Telegram configuration is temporarily unavailable'
|
||||
);
|
||||
}
|
||||
if ($runtime === null) {
|
||||
return null;
|
||||
}
|
||||
return $this->boundDestination();
|
||||
}
|
||||
|
||||
/** Resolve a stored binding even while outbound Telegram is disabled. */
|
||||
public function boundDestination(): ?AdministratorTelegramDestination
|
||||
{
|
||||
$row = Configurations::where('name', TicketTelegramConfig::BINDING)->first();
|
||||
$state = self::readState($row);
|
||||
$destination = $this->destinationFromState($state);
|
||||
if ($destination !== null) {
|
||||
return $destination;
|
||||
}
|
||||
if ($row === null || !$this->eligibleBindingState($state, false)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (new Configurations())->getConnection()->transaction(function (): ?AdministratorTelegramDestination {
|
||||
$locked = Configurations::where('name', TicketTelegramConfig::BINDING)
|
||||
->lockForUpdate()->first();
|
||||
$current = self::readState($locked);
|
||||
if ($locked === null || !$this->eligibleBindingState($current, false)) {
|
||||
return null;
|
||||
}
|
||||
if (preg_match(
|
||||
'/^[a-f0-9]{32}$/D',
|
||||
(string) ($current['binding_generation'] ?? '')
|
||||
) !== 1) {
|
||||
$current['binding_generation'] = bin2hex(random_bytes(16));
|
||||
$locked->value = json_encode($current, JSON_THROW_ON_ERROR);
|
||||
if (!$locked->save()) {
|
||||
throw new \RuntimeException('Telegram binding generation storage failed');
|
||||
}
|
||||
}
|
||||
return $this->destinationFromState($current);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Send once to the expected binding generation. A concurrent unbind/rebind
|
||||
* is rejected before the remote request, so a reserved business delivery
|
||||
* can never drift to another administrator or chat.
|
||||
*
|
||||
* @param array<string, int|string|bool> $options
|
||||
*/
|
||||
public function send(
|
||||
AdministratorTelegramDestination $expected,
|
||||
string $text,
|
||||
array $options = []
|
||||
): int {
|
||||
$textLength = mb_strlen($text, 'UTF-8');
|
||||
if ($textLength < 1 || $textLength > 4096) {
|
||||
throw new AdministratorTelegramPreflightException(
|
||||
'Telegram message length is invalid'
|
||||
);
|
||||
}
|
||||
foreach (array_keys($options) as $key) {
|
||||
if (!is_string($key) || !in_array($key, self::ALLOWED_OPTIONS, true)) {
|
||||
throw new AdministratorTelegramPreflightException(
|
||||
'Telegram send option is not allowed'
|
||||
);
|
||||
}
|
||||
}
|
||||
if (isset($options['reply_to_message_id'])
|
||||
&& (!is_int($options['reply_to_message_id'])
|
||||
|| $options['reply_to_message_id'] <= 0)) {
|
||||
throw new AdministratorTelegramPreflightException(
|
||||
'Telegram reply message id is invalid'
|
||||
);
|
||||
}
|
||||
|
||||
// Both reads are authoritative. Config runtime also rejects disabled or
|
||||
// unreadable credentials; the binding read fences recipient changes.
|
||||
try {
|
||||
$config = TicketTelegramConfig::runtimeForDelivery();
|
||||
} catch (\Throwable $exception) {
|
||||
throw new AdministratorTelegramLocalUnavailable(
|
||||
'Administrator Telegram configuration is temporarily unavailable'
|
||||
);
|
||||
}
|
||||
if ($config === null) {
|
||||
throw new AdministratorTelegramPreflightException(
|
||||
'Administrator Telegram configuration is unavailable'
|
||||
);
|
||||
}
|
||||
try {
|
||||
$current = $this->boundDestination();
|
||||
} catch (\Throwable $exception) {
|
||||
throw new AdministratorTelegramLocalUnavailable(
|
||||
'Administrator Telegram binding is temporarily unavailable'
|
||||
);
|
||||
}
|
||||
if ($current === null || !$current->equals($expected)) {
|
||||
throw new AdministratorTelegramPreflightException(
|
||||
'Administrator Telegram destination changed'
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->transport->sendMessage(
|
||||
(string) $config['bot_token'],
|
||||
$current->chatId,
|
||||
$text,
|
||||
$options
|
||||
);
|
||||
} catch (AdministratorTelegramRemoteEffectUnknown $exception) {
|
||||
throw $exception;
|
||||
} catch (\Throwable $exception) {
|
||||
throw new AdministratorTelegramRemoteEffectUnknown(
|
||||
'Administrator Telegram remote effect is unknown'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function destinationFromState(array $state): ?AdministratorTelegramDestination
|
||||
{
|
||||
if (!$this->eligibleBindingState($state, true)) {
|
||||
return null;
|
||||
}
|
||||
return new AdministratorTelegramDestination(
|
||||
(int) $state['bound_admin_id'],
|
||||
(string) $state['chat_id'],
|
||||
(string) $state['binding_generation']
|
||||
);
|
||||
}
|
||||
|
||||
private function eligibleBindingState(array $state, bool $requireGeneration): bool
|
||||
{
|
||||
$administratorId = (int) ($state['bound_admin_id'] ?? 0);
|
||||
$chatId = $state['chat_id'] ?? null;
|
||||
if ((!is_string($chatId) && !is_int($chatId))
|
||||
|| preg_match('/^[1-9][0-9]{0,18}$/D', (string) $chatId) !== 1
|
||||
|| !$this->eligibleAdministrator($administratorId)) {
|
||||
return false;
|
||||
}
|
||||
return !$requireGeneration || preg_match(
|
||||
'/^[a-f0-9]{32}$/D',
|
||||
(string) ($state['binding_generation'] ?? '')
|
||||
) === 1;
|
||||
}
|
||||
|
||||
private static function readState($row): array
|
||||
{
|
||||
$state = $row === null ? [] : json_decode((string) $row->value, true);
|
||||
return is_array($state) ? $state : [];
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Telegram;
|
||||
|
||||
/** Immutable identity of the currently bound administrator Telegram chat. */
|
||||
final readonly class AdministratorTelegramDestination
|
||||
{
|
||||
public function __construct(
|
||||
public int $administratorId,
|
||||
public string $chatId,
|
||||
public string $bindingGeneration
|
||||
) {}
|
||||
|
||||
public function equals(self $other): bool
|
||||
{
|
||||
return $this->administratorId === $other->administratorId
|
||||
&& hash_equals($this->chatId, $other->chatId)
|
||||
&& hash_equals($this->bindingGeneration, $other->bindingGeneration);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Telegram;
|
||||
|
||||
/** The remote request did not start, but local infrastructure may recover. */
|
||||
final class AdministratorTelegramLocalUnavailable extends \RuntimeException {}
|
||||
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Telegram;
|
||||
|
||||
/** The Telegram network request is known not to have started. */
|
||||
final class AdministratorTelegramPreflightException extends \RuntimeException {}
|
||||
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Telegram;
|
||||
|
||||
/** A Telegram send may have reached the remote service and must not be replayed. */
|
||||
final class AdministratorTelegramRemoteEffectUnknown extends \RuntimeException {}
|
||||
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Telegram;
|
||||
|
||||
interface AdministratorTelegramTransport
|
||||
{
|
||||
/**
|
||||
* Perform exactly one Telegram sendMessage request and return its message id.
|
||||
* Once invoked, every failure is reported as RemoteEffectUnknown because
|
||||
* the caller cannot safely prove whether Telegram accepted the message.
|
||||
*
|
||||
* @param array<string, int|string|bool> $options
|
||||
*/
|
||||
public function sendMessage(
|
||||
string $botToken,
|
||||
string $chatId,
|
||||
string $text,
|
||||
array $options = []
|
||||
): int;
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Telegram;
|
||||
|
||||
use TelegramBot\Api\BotApi;
|
||||
|
||||
/** One-shot Telegram transport. It deliberately performs no retry. */
|
||||
final class TelegramBotApiTransport implements AdministratorTelegramTransport
|
||||
{
|
||||
public function sendMessage(
|
||||
string $botToken,
|
||||
string $chatId,
|
||||
string $text,
|
||||
array $options = []
|
||||
): int {
|
||||
try {
|
||||
$result = (new BotApi($botToken))->call('sendMessage', array_merge([
|
||||
'chat_id' => $chatId,
|
||||
'text' => $text,
|
||||
], $options), 10);
|
||||
} catch (\Throwable $exception) {
|
||||
// SDK exception text can contain the bot token through its request URL.
|
||||
throw new AdministratorTelegramRemoteEffectUnknown(
|
||||
'Administrator Telegram remote effect is unknown'
|
||||
);
|
||||
}
|
||||
|
||||
$messageId = is_array($result) ? ($result['message_id'] ?? null) : null;
|
||||
if (is_object($result)) {
|
||||
if (method_exists($result, 'getMessageId')) {
|
||||
$messageId = $result->getMessageId();
|
||||
} elseif (isset($result->message_id)) {
|
||||
$messageId = $result->message_id;
|
||||
}
|
||||
}
|
||||
if ((!is_int($messageId) && !is_string($messageId))
|
||||
|| preg_match('/^[1-9][0-9]{0,18}$/D', (string) $messageId) !== 1
|
||||
|| strlen((string) $messageId) > strlen((string) PHP_INT_MAX)
|
||||
|| (strlen((string) $messageId) === strlen((string) PHP_INT_MAX)
|
||||
&& strcmp((string) $messageId, (string) PHP_INT_MAX) > 0)) {
|
||||
throw new AdministratorTelegramRemoteEffectUnknown(
|
||||
'Administrator Telegram remote effect is unknown'
|
||||
);
|
||||
}
|
||||
return (int) $messageId;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,308 @@
|
||||
<?php
|
||||
|
||||
// In-memory contract: no application bootstrap, database or Telegram network.
|
||||
namespace App\Models {
|
||||
final class User
|
||||
{
|
||||
public static array $rows = [];
|
||||
|
||||
public function __construct(
|
||||
public int $id,
|
||||
public int $is_admin = 1,
|
||||
public int $enable = 1
|
||||
) {}
|
||||
|
||||
public static function find($id): ?self
|
||||
{
|
||||
return self::$rows[(int) $id] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
final class Configurations
|
||||
{
|
||||
public static array $rows = [];
|
||||
public static int $transactions = 0;
|
||||
public static int $locks = 0;
|
||||
public static bool $failReads = false;
|
||||
|
||||
public function __construct(public string $name = '', public string $value = '{}') {}
|
||||
|
||||
public static function where($key, $value): \AdministratorTelegramChannelQuery
|
||||
{
|
||||
return new \AdministratorTelegramChannelQuery((string) $value);
|
||||
}
|
||||
|
||||
public function getConnection(): \AdministratorTelegramChannelConnection
|
||||
{
|
||||
return new \AdministratorTelegramChannelConnection();
|
||||
}
|
||||
|
||||
public function save(): bool
|
||||
{
|
||||
self::$rows[$this->name] = clone $this;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace App\Services {
|
||||
final class Config
|
||||
{
|
||||
public static string $superAdministrators = '1';
|
||||
|
||||
public static function get(string $key, mixed $default = null): mixed
|
||||
{
|
||||
return $key === 'super_admin' ? self::$superAdministrators : $default;
|
||||
}
|
||||
}
|
||||
|
||||
final class TicketTelegramConfig
|
||||
{
|
||||
public const BINDING = 'ticket_telegram_binding';
|
||||
public static bool $enabled = true;
|
||||
public static bool $failRuntime = false;
|
||||
public static string $token = '123456789:' . 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
|
||||
|
||||
public static function runtime(bool $requireEnabled = true): array
|
||||
{
|
||||
if ($requireEnabled && !self::$enabled) {
|
||||
throw new \RuntimeException('disabled');
|
||||
}
|
||||
return ['bot_token' => self::$token];
|
||||
}
|
||||
|
||||
public static function runtimeForDelivery(): ?array
|
||||
{
|
||||
if (self::$failRuntime) {
|
||||
throw new \RuntimeException('synthetic configuration database failure');
|
||||
}
|
||||
return self::$enabled ? ['bot_token' => self::$token] : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
use App\Models\Configurations;
|
||||
use App\Models\User;
|
||||
use App\Services\TicketTelegramConfig;
|
||||
use App\Services\Telegram\AdministratorTelegramChannel;
|
||||
use App\Services\Telegram\AdministratorTelegramLocalUnavailable;
|
||||
use App\Services\Telegram\AdministratorTelegramPreflightException;
|
||||
use App\Services\Telegram\AdministratorTelegramRemoteEffectUnknown;
|
||||
use App\Services\Telegram\AdministratorTelegramTransport;
|
||||
|
||||
require dirname(__DIR__) . '/app/Services/Telegram/AdministratorTelegramDestination.php';
|
||||
require dirname(__DIR__) . '/app/Services/Telegram/AdministratorTelegramTransport.php';
|
||||
require dirname(__DIR__) . '/app/Services/Telegram/AdministratorTelegramPreflightException.php';
|
||||
require dirname(__DIR__) . '/app/Services/Telegram/AdministratorTelegramLocalUnavailable.php';
|
||||
require dirname(__DIR__) . '/app/Services/Telegram/AdministratorTelegramRemoteEffectUnknown.php';
|
||||
|
||||
final class AdministratorTelegramChannelConnection
|
||||
{
|
||||
public function transaction(callable $callback): mixed
|
||||
{
|
||||
Configurations::$transactions++;
|
||||
try {
|
||||
return $callback();
|
||||
} finally {
|
||||
Configurations::$transactions--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class AdministratorTelegramChannelQuery
|
||||
{
|
||||
public function __construct(private readonly string $name) {}
|
||||
|
||||
public function lockForUpdate(): self
|
||||
{
|
||||
if (Configurations::$transactions !== 1) {
|
||||
throw new RuntimeException('lock outside transaction');
|
||||
}
|
||||
Configurations::$locks++;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function first(): ?Configurations
|
||||
{
|
||||
if (Configurations::$failReads) {
|
||||
throw new RuntimeException('synthetic binding database failure');
|
||||
}
|
||||
$row = Configurations::$rows[$this->name] ?? null;
|
||||
return $row === null ? null : clone $row;
|
||||
}
|
||||
}
|
||||
|
||||
final class AdministratorTelegramChannelFakeTransport
|
||||
implements AdministratorTelegramTransport
|
||||
{
|
||||
public array $calls = [];
|
||||
public bool $fail = false;
|
||||
|
||||
public function sendMessage(
|
||||
string $botToken,
|
||||
string $chatId,
|
||||
string $text,
|
||||
array $options = []
|
||||
): int {
|
||||
$this->calls[] = compact('botToken', 'chatId', 'text', 'options');
|
||||
if ($this->fail) {
|
||||
throw new AdministratorTelegramRemoteEffectUnknown(
|
||||
'synthetic transport failure'
|
||||
);
|
||||
}
|
||||
return 9001;
|
||||
}
|
||||
}
|
||||
|
||||
require dirname(__DIR__) . '/app/Services/Telegram/TelegramBotApiTransport.php';
|
||||
require dirname(__DIR__) . '/app/Services/Telegram/AdministratorTelegramChannel.php';
|
||||
|
||||
$assert = static function (bool $condition, string $message): void {
|
||||
if (!$condition) {
|
||||
fwrite(STDERR, $message . PHP_EOL);
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
$expectFailure = static function (callable $callback, string $message) use ($assert): void {
|
||||
try {
|
||||
$callback();
|
||||
} catch (Throwable $exception) {
|
||||
return;
|
||||
}
|
||||
$assert(false, $message);
|
||||
};
|
||||
$setBinding = static function (array $state): void {
|
||||
Configurations::$rows[TicketTelegramConfig::BINDING] = new Configurations(
|
||||
TicketTelegramConfig::BINDING,
|
||||
json_encode($state, JSON_THROW_ON_ERROR)
|
||||
);
|
||||
};
|
||||
|
||||
User::$rows[1] = new User(1);
|
||||
$transport = new AdministratorTelegramChannelFakeTransport();
|
||||
$channel = new AdministratorTelegramChannel($transport);
|
||||
|
||||
$setBinding(['bound_admin_id' => 1, 'chat_id' => '123456']);
|
||||
$destination = $channel->currentDestination();
|
||||
$assert($destination !== null
|
||||
&& $destination->administratorId === 1
|
||||
&& $destination->chatId === '123456'
|
||||
&& preg_match('/^[a-f0-9]{32}$/D', $destination->bindingGeneration) === 1
|
||||
&& Configurations::$locks === 1
|
||||
&& Configurations::$transactions === 0,
|
||||
'Legacy binding was not upgraded atomically with a valid generation.');
|
||||
|
||||
$messageId = $channel->send($destination, 'Test alert', [
|
||||
'disable_web_page_preview' => 'true',
|
||||
]);
|
||||
$assert($messageId === 9001 && count($transport->calls) === 1
|
||||
&& $transport->calls[0]['chatId'] === '123456'
|
||||
&& $transport->calls[0]['botToken'] === TicketTelegramConfig::$token,
|
||||
'Authoritative destination was not sent exactly once.');
|
||||
|
||||
$expectFailure(
|
||||
fn () => $channel->send($destination, 'Unsafe', ['parse_mode' => 'HTML']),
|
||||
'Unknown Telegram option was accepted.'
|
||||
);
|
||||
$assert(count($transport->calls) === 1,
|
||||
'Rejected Telegram options reached the network transport.');
|
||||
|
||||
$setBinding([
|
||||
'bound_admin_id' => 1,
|
||||
'chat_id' => '654321',
|
||||
'binding_generation' => bin2hex(random_bytes(16)),
|
||||
]);
|
||||
$expectFailure(
|
||||
fn () => $channel->send($destination, 'Stale destination'),
|
||||
'A stale binding generation was sent after rebind.'
|
||||
);
|
||||
$assert(count($transport->calls) === 1,
|
||||
'A stale destination reached the Telegram transport.');
|
||||
|
||||
$setBinding([
|
||||
'bound_admin_id' => 1,
|
||||
'chat_id' => '123456',
|
||||
'binding_generation' => $destination->bindingGeneration,
|
||||
]);
|
||||
TicketTelegramConfig::$enabled = false;
|
||||
$assert($channel->currentDestination() === null,
|
||||
'Disabled Telegram configuration still exposed a destination.');
|
||||
$assert($channel->boundDestination()?->equals($destination) === true,
|
||||
'Disabling outbound Telegram hid the retained administrator binding.');
|
||||
$expectFailure(
|
||||
fn () => $channel->send($destination, 'Disabled channel'),
|
||||
'Disabled Telegram configuration still sent a message.'
|
||||
);
|
||||
TicketTelegramConfig::$enabled = true;
|
||||
$assert(count($transport->calls) === 1,
|
||||
'Disabled Telegram configuration reached the transport.');
|
||||
|
||||
TicketTelegramConfig::$failRuntime = true;
|
||||
$localFailure = null;
|
||||
try {
|
||||
$channel->currentDestination();
|
||||
} catch (Throwable $exception) {
|
||||
$localFailure = $exception;
|
||||
}
|
||||
$assert($localFailure instanceof AdministratorTelegramLocalUnavailable,
|
||||
'Configuration infrastructure failure was collapsed into disabled.');
|
||||
try {
|
||||
$channel->send($destination, 'Local configuration failure');
|
||||
} catch (Throwable $exception) {
|
||||
$localFailure = $exception;
|
||||
}
|
||||
$assert($localFailure instanceof AdministratorTelegramLocalUnavailable
|
||||
&& count($transport->calls) === 1,
|
||||
'Local configuration failure reached transport or became remote unknown.');
|
||||
TicketTelegramConfig::$failRuntime = false;
|
||||
|
||||
Configurations::$failReads = true;
|
||||
try {
|
||||
$channel->send($destination, 'Local binding failure');
|
||||
} catch (Throwable $exception) {
|
||||
$localFailure = $exception;
|
||||
}
|
||||
$assert($localFailure instanceof AdministratorTelegramLocalUnavailable
|
||||
&& count($transport->calls) === 1,
|
||||
'Binding read failure reached transport or became remote unknown.');
|
||||
Configurations::$failReads = false;
|
||||
|
||||
$transport->fail = true;
|
||||
$remoteFailure = null;
|
||||
try {
|
||||
$channel->send($destination, 'Unknown-effect send');
|
||||
} catch (Throwable $exception) {
|
||||
$remoteFailure = $exception;
|
||||
}
|
||||
$assert($remoteFailure instanceof AdministratorTelegramRemoteEffectUnknown,
|
||||
'Transport failure was not classified as remote-effect unknown.');
|
||||
$assert(count($transport->calls) === 2,
|
||||
'A transport failure was internally retried.');
|
||||
$transport->fail = false;
|
||||
|
||||
$setBinding([
|
||||
'bound_admin_id' => 1,
|
||||
'chat_id' => '654321',
|
||||
'binding_generation' => bin2hex(random_bytes(16)),
|
||||
]);
|
||||
$preflightFailure = null;
|
||||
try {
|
||||
$channel->send($destination, 'Known preflight failure');
|
||||
} catch (Throwable $exception) {
|
||||
$preflightFailure = $exception;
|
||||
}
|
||||
$assert($preflightFailure instanceof AdministratorTelegramPreflightException
|
||||
&& count($transport->calls) === 2,
|
||||
'Destination change was not classified before the remote request.');
|
||||
|
||||
User::$rows[1]->enable = 0;
|
||||
$assert($channel->currentDestination() === null,
|
||||
'Disabled administrator remained an eligible destination.');
|
||||
User::$rows[1]->enable = 1;
|
||||
\App\Services\Config::$superAdministrators = '2';
|
||||
$assert($channel->currentDestination() === null,
|
||||
'Removed super administrator remained an eligible destination.');
|
||||
|
||||
echo "Administrator Telegram channel tests passed.\n";
|
||||
}
|
||||
Loading…
Reference in New Issue