`). The code carries the workspace, so the webhook * can link the channel without any persisted state. */ 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); $expiresAt = now()->addMinutes(15); $code = TelegramConnectCode::issue($workspace->id, $expiresAt); $request->session()->put(self::SESSION_KEY, $code); return response()->json([ 'code' => $code, 'bot_username' => config('trypost.platforms.telegram.bot_username'), 'expires_at' => $expiresAt->toIso8601String(), ]); } /** * Poll whether the channel issued in this session has been linked yet. */ public function status(Request $request): JsonResponse { $workspace = $request->user()->currentWorkspace; abort_if($workspace === null, SymfonyResponse::HTTP_CONFLICT, 'No active workspace.'); $payload = TelegramConnectCode::decode($request->session()->get(self::SESSION_KEY)); if ($payload === null) { return response()->json(['status' => TelegramConnectStatus::Unknown->value]); } $account = $workspace->socialAccounts() ->where('platform', SocialPlatform::Telegram->value) ->where('meta->connect_nonce', data_get($payload, 'nonce')) ->first(); return response()->json([ 'status' => TelegramConnectStatus::for($account)->value, ]); } }