Add Telegram connection flow (controller + webhook)
Connect a channel by issuing a one-time code the user posts as /connect <code>
in their channel. A secret-token-guarded webhook matches the code, links the
channel as a SocialAccount (chat_id in meta), and records it on the request so
the connect endpoint can poll for completion. Adds the TelegramConnectRequest
model + migration, the connect/status endpoints, the public webhook route (CSRF
exempt), a ConnectionVerifier branch (getChat liveness), and a telegram:set-webhook
command. Tests cover the code issue, webhook link, secret rejection, expired/
unknown codes, status polling, and the command.
2026-06-14 00:39:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Console\Commands\Telegram;
|
|
|
|
|
|
2026-06-14 01:20:52 +00:00
|
|
|
use App\Actions\SocialAccount\RegisterTelegramWebhook;
|
Add Telegram connection flow (controller + webhook)
Connect a channel by issuing a one-time code the user posts as /connect <code>
in their channel. A secret-token-guarded webhook matches the code, links the
channel as a SocialAccount (chat_id in meta), and records it on the request so
the connect endpoint can poll for completion. Adds the TelegramConnectRequest
model + migration, the connect/status endpoints, the public webhook route (CSRF
exempt), a ConnectionVerifier branch (getChat liveness), and a telegram:set-webhook
command. Tests cover the code issue, webhook link, secret rejection, expired/
unknown codes, status polling, and the command.
2026-06-14 00:39:03 +00:00
|
|
|
use Illuminate\Console\Attributes\Description;
|
|
|
|
|
use Illuminate\Console\Attributes\Signature;
|
|
|
|
|
use Illuminate\Console\Command;
|
2026-06-14 01:20:52 +00:00
|
|
|
use Throwable;
|
Add Telegram connection flow (controller + webhook)
Connect a channel by issuing a one-time code the user posts as /connect <code>
in their channel. A secret-token-guarded webhook matches the code, links the
channel as a SocialAccount (chat_id in meta), and records it on the request so
the connect endpoint can poll for completion. Adds the TelegramConnectRequest
model + migration, the connect/status endpoints, the public webhook route (CSRF
exempt), a ConnectionVerifier branch (getChat liveness), and a telegram:set-webhook
command. Tests cover the code issue, webhook link, secret rejection, expired/
unknown codes, status polling, and the command.
2026-06-14 00:39:03 +00:00
|
|
|
|
|
|
|
|
#[Signature('telegram:set-webhook')]
|
|
|
|
|
#[Description('Register the Telegram bot webhook with the configured URL and secret token')]
|
|
|
|
|
class SetWebhook extends Command
|
|
|
|
|
{
|
|
|
|
|
public function handle(): int
|
|
|
|
|
{
|
2026-06-14 01:20:52 +00:00
|
|
|
try {
|
|
|
|
|
$url = RegisterTelegramWebhook::execute();
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
$this->error($e->getMessage());
|
Add Telegram connection flow (controller + webhook)
Connect a channel by issuing a one-time code the user posts as /connect <code>
in their channel. A secret-token-guarded webhook matches the code, links the
channel as a SocialAccount (chat_id in meta), and records it on the request so
the connect endpoint can poll for completion. Adds the TelegramConnectRequest
model + migration, the connect/status endpoints, the public webhook route (CSRF
exempt), a ConnectionVerifier branch (getChat liveness), and a telegram:set-webhook
command. Tests cover the code issue, webhook link, secret rejection, expired/
unknown codes, status polling, and the command.
2026-06-14 00:39:03 +00:00
|
|
|
|
|
|
|
|
return self::FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->info("Telegram webhook registered at {$url}");
|
|
|
|
|
|
|
|
|
|
return self::SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
}
|