`) so the webhook can tie the channel to this workspace. */ public function connect(Request $request): JsonResponse { $this->ensurePlatformEnabled(); $workspace = $request->user()->currentWorkspace; abort_if($workspace === null, SymfonyResponse::HTTP_CONFLICT, 'No active workspace.'); $this->authorize('manageAccounts', $workspace); $this->ensureSocialAccountLimit($workspace); $connectRequest = TelegramConnectRequest::create([ 'workspace_id' => $workspace->id, 'user_id' => $request->user()->id, 'code' => Str::lower(Str::random(12)), 'expires_at' => now()->addMinutes(15), ]); return response()->json([ 'code' => $connectRequest->code, 'bot_username' => config('trypost.platforms.telegram.bot_username'), 'expires_at' => $connectRequest->expires_at->toIso8601String(), ]); } /** * Poll whether the channel has been linked yet. */ public function status(Request $request): JsonResponse { $workspace = $request->user()->currentWorkspace; abort_if($workspace === null, SymfonyResponse::HTTP_CONFLICT, 'No active workspace.'); $connectRequest = TelegramConnectRequest::query() ->where('workspace_id', $workspace->id) ->where('code', (string) $request->query('code')) ->first(); $status = match (true) { $connectRequest === null => 'unknown', $connectRequest->social_account_id !== null => 'connected', $connectRequest->isExpired() => 'expired', default => 'pending', }; return response()->json(['status' => $status]); } }