Use atproto actions with ease in iOS shortcuts
at main 2.0 kB view raw
1// 2// MakeAPostIntent.swift 3// shortcut 4// 5// Created by Bailey Townsend on 6/29/25. 6// 7 8// StartMeditationIntent creates a meditation session. 9 10import ATProtoKit 11import AppIntents 12import SwiftData 13 14struct GetALocalAtIdentifierIntent: AppIntent { 15 16 @Parameter( 17 title: "Handle", 18 description: 19 "The handle of the saved account you would like to retrieve. Ex @alice.bsky.social") 20 var handle: String 21 22 static let title: LocalizedStringResource = 23 "Get AT Identifier" 24 25 static let description: IntentDescription = IntentDescription( 26 stringLiteral: 27 "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" 28 ) 29 30 static var parameterSummary: some ParameterSummary { 31 Summary("Get the AT Identifier for \(\.$handle)") 32 } 33 34 func perform() async throws -> some ReturnsValue<AtIdentifierAppEntity> { 35 36 let atProtoManager = AtProtocolManager() 37 do { 38 39 let lookedUpSession = try await atProtoManager.getSessionByHandle( 40 handle: self.handle.lowercased()) 41 guard let session = lookedUpSession else { 42 throw GenericIntentError.message( 43 "\(self.handle) could not be found. Please check the app to make sure that is an account you have setup" 44 ) 45 } 46 let userAccount: AtIdentifierAppEntity = AtIdentifierAppEntity(id: session.id) 47 userAccount.handle = session.handle 48 userAccount.did = session.sessionDID 49 50 return .result(value: userAccount) 51 52 } catch let error as ShortcutErrors { 53 throw GenericIntentError.message( 54 error.errorDescription ?? "There was an error getting the user") 55 } catch let error as GenericIntentError { 56 throw error 57 } catch { 58 throw GenericIntentError.message(error.localizedDescription) 59 } 60 } 61}