Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

feat(telegram): surface connect failure in the dialog instead of silent expiry

Paulo Castellano2f314c9a8c0e
diff --git a/app/Actions/SocialAccount/ConnectTelegramChannel.php b/app/Actions/SocialAccount/ConnectTelegramChannel.php
index c4d5e4b36..63d19f73b 100644
--- a/app/Actions/SocialAccount/ConnectTelegramChannel.php
+++ b/app/Actions/SocialAccount/ConnectTelegramChannel.php
@@ -7,6 +7,7 @@ namespace App\Actions\SocialAccount;
use App\Enums\SocialAccount\Platform;
use App\Enums\SocialAccount\Status;
use App\Events\TelegramChannelConnected;
+use App\Events\TelegramConnectFailed;
use App\Models\SocialAccount;
use App\Models\Workspace;
use App\Services\Social\Telegram\TelegramApi;
@@ -34,6 +35,8 @@ class ConnectTelegramChannel
->exists();
if ($isNewAccount && self::networkAlreadyConnected($workspace, $chatId)) {
+ TelegramConnectFailed::dispatch($workspace->id, $nonce, 'network_taken');
+
return null;
}
diff --git a/app/Events/TelegramConnectFailed.php b/app/Events/TelegramConnectFailed.php
new file mode 100644
index 000000000..9210f7cee
--- /dev/null
+++ b/app/Events/TelegramConnectFailed.php
@@ -0,0 +1,53 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Events;
+
+use Illuminate\Broadcasting\InteractsWithSockets;
+use Illuminate\Broadcasting\PrivateChannel;
+use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
+use Illuminate\Foundation\Events\Dispatchable;
+use Illuminate\Queue\SerializesModels;
+
+class TelegramConnectFailed implements ShouldBroadcast
+{
+ use Dispatchable, InteractsWithSockets, SerializesModels;
+
+ public function __construct(
+ public string $workspaceId,
+ public string $nonce,
+ public string $reason,
+ ) {}
+
+ public function broadcastAs(): string
+ {
+ return 'telegram.connect.failed';
+ }
+
+ /**
+ * @return array<int, PrivateChannel>
+ */
+ public function broadcastOn(): array
+ {
+ return [
+ new PrivateChannel("workspace.{$this->workspaceId}"),
+ ];
+ }
+
+ /**
+ * @return array<string, string>
+ */
+ public function broadcastWith(): array
+ {
+ return [
+ 'nonce' => $this->nonce,
+ 'reason' => $this->reason,
+ ];
+ }
+
+ public function broadcastQueue(): string
+ {
+ return 'broadcasts';
+ }
+}
diff --git a/lang/en/accounts.php b/lang/en/accounts.php
index 85bc7392f..44876d8ed 100644
--- a/lang/en/accounts.php
+++ b/lang/en/accounts.php
@@ -96,6 +96,7 @@ return [
'new_code' => 'Generate a new code',
'retry' => 'Try again',
'error_generic' => 'Could not start the connection. Please try again.',
+ 'network_taken' => 'This workspace already has a Telegram channel connected. Disconnect it first.',
],
'facebook' => [
diff --git a/lang/es/accounts.php b/lang/es/accounts.php
index 1596a02b9..2f04bd406 100644
--- a/lang/es/accounts.php
+++ b/lang/es/accounts.php
@@ -96,6 +96,7 @@ return [
'new_code' => 'Generar un nuevo código',
'retry' => 'Reintentar',
'error_generic' => 'No se pudo iniciar la conexión. Inténtalo de nuevo.',
+ 'network_taken' => 'Este workspace ya tiene un canal de Telegram conectado. Desconéctalo primero.',
],
'facebook' => [
diff --git a/lang/pt-BR/accounts.php b/lang/pt-BR/accounts.php
index d9cecdc43..8701d9344 100644
--- a/lang/pt-BR/accounts.php
+++ b/lang/pt-BR/accounts.php
@@ -96,6 +96,7 @@ return [
'new_code' => 'Gerar um novo código',
'retry' => 'Tentar novamente',
'error_generic' => 'Não foi possível iniciar a conexão. Tente novamente.',
+ 'network_taken' => 'Este workspace já tem um canal de Telegram conectado. Desconecte-o primeiro.',
],
'facebook' => [
diff --git a/resources/js/components/accounts/TelegramConnectDialog.vue b/resources/js/components/accounts/TelegramConnectDialog.vue
index 7ec1425a4..5cec83e63 100644
--- a/resources/js/components/accounts/TelegramConnectDialog.vue
+++ b/resources/js/components/accounts/TelegramConnectDialog.vue
@@ -72,6 +72,22 @@ useWorkspaceEcho<{ nonce: string }>(
},
);
+useWorkspaceEcho<{ nonce: string; reason: string }>(
+ '.telegram.connect.failed',
+ (payload) => {
+ if (phase.value !== 'ready' || payload.nonce !== nonce.value) {
+ return;
+ }
+
+ phase.value = 'error';
+ clearExpiry();
+ errorMessage.value =
+ payload.reason === 'network_taken'
+ ? trans('accounts.telegram.network_taken')
+ : trans('accounts.telegram.error_generic');
+ },
+);
+
const start = async () => {
phase.value = 'loading';
errorMessage.value = '';
diff --git a/tests/Feature/Social/TelegramConnectionTest.php b/tests/Feature/Social/TelegramConnectionTest.php
index b05092996..f30e90f9c 100644
--- a/tests/Feature/Social/TelegramConnectionTest.php
+++ b/tests/Feature/Social/TelegramConnectionTest.php
@@ -5,6 +5,7 @@ declare(strict_types=1);
use App\Enums\SocialAccount\Platform;
use App\Enums\UserWorkspace\Role;
use App\Events\TelegramChannelConnected;
+use App\Events\TelegramConnectFailed;
use App\Models\Post;
use App\Models\PostPlatform;
use App\Models\SocialAccount;
@@ -119,6 +120,7 @@ it('links a private channel that has no username', function () {
it('does not connect a second telegram channel when one is already connected', function () {
config(['trypost.self_hosted' => false]);
+ Event::fake([TelegramConnectFailed::class]);
SocialAccount::factory()->telegram()->create([
'workspace_id' => $this->workspace->id,
@@ -135,6 +137,12 @@ it('does not connect a second telegram channel when one is already connected', f
expect(
SocialAccount::where('platform', Platform::Telegram)->where('platform_user_id', '-1001234567890')->exists()
)->toBeFalse();
+
+ Event::assertDispatched(
+ TelegramConnectFailed::class,
+ fn (TelegramConnectFailed $event): bool => $event->workspaceId === $this->workspace->id
+ && $event->reason === 'network_taken',
+ );
});
it('connects a second telegram channel in self-hosted mode', function () {