`). 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); return response()->json([ 'code' => TelegramConnectCode::issue($workspace->id, $expiresAt), 'bot_username' => config('trypost.platforms.telegram.bot_username'), 'expires_at' => $expiresAt->toIso8601String(), ]); } /** * Poll whether the channel for the given code 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->query('code')); 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, ]); } }