// // MakeAPostIntent.swift // shortcut // // Created by Bailey Townsend on 6/29/25. // // StartMeditationIntent creates a meditation session. import ATProtoKit import AppIntents import SwiftData struct GetALocalAtIdentifierIntent: AppIntent { @Parameter( title: "Handle", description: "The handle of the saved account you would like to retrieve. Ex @alice.bsky.social") var handle: String static let title: LocalizedStringResource = "Get AT Identifier" static let description: IntentDescription = IntentDescription( stringLiteral: "This shortcut allows you to look up locally logged in ATProto accounts to use them for other actions. This is useful if you want to dynamically switch between accounts" ) static var parameterSummary: some ParameterSummary { Summary("Get the AT Identifier for \(\.$handle)") } func perform() async throws -> some ReturnsValue { let atProtoManager = AtProtocolManager() do { let lookedUpSession = try await atProtoManager.getSessionByHandle( handle: self.handle.lowercased()) guard let session = lookedUpSession else { throw GenericIntentError.message( "\(self.handle) could not be found. Please check the app to make sure that is an account you have setup" ) } let userAccount: AtIdentifierAppEntity = AtIdentifierAppEntity(id: session.id) userAccount.handle = session.handle userAccount.did = session.sessionDID return .result(value: userAccount) } catch let error as ShortcutErrors { throw GenericIntentError.message( error.errorDescription ?? "There was an error getting the user") } catch let error as GenericIntentError { throw error } catch { throw GenericIntentError.message(error.localizedDescription) } } }