L_Cleo
L_Cleo

Reputation: 1527

AppIntent parametrized phrase with custom struct as parameter

I have an AppIntent as the following

struct SearchForObjectsIntent: AppIntent {
    static let title = LocalizedStringResource("Search For Objects")
    static let openAppWhenRun = true
    @Parameter(title: "Find your tobjec",
                  description: "Select your object")
    var selectedObj: MyObject

      @MainActor
    func perform() async throws -> some IntentResult {
        let deeplink = URL(string: selectedObj.url)!
        let nav = EBDeeplinkHandler()
        await nav.handle(deeplink)
        return .result()
    }
}

I would like the AppShorcut:

        AppShortcut(
                 intent: SearchForObjectsIntent(),
                 phrases: [
                     "Open my objects in \(.applicationName)",
                     "Show me my \(\.$selectedObj) object in \(.applicationName)"
                 ],
                 shortTitle: "Open a saved object",
                 systemImageName: "suitcase"
             )

when I ask siri to "Show me my CD object in MyApp" to actually open the app with that chosen object. The first siri phrase work fine, but when I use the second one it opens random internet results. It does make sense, I mean how can I tell siri that the field it should filter the objects is actually by their name?

This is my object entity:

public struct MyObject: Identifiable, Sendable, AppEntity {
    public let id = UUID()
    var url: String
    var nameOfObject: String

    init(url: String, nameOfObject: String) {
        self.url = url
        self.nameOfObject = nameOfObject
    }
    public static var typeDisplayRepresentation: TypeDisplayRepresentation = "Owned Objects"
    public var displayRepresentation: DisplayRepresentation {
        return DisplayRepresentation(title: "\(nameOfObj)", subtitle: "")
    }
    public static var defaultQuery = ObjectIntentQuery()

Whilst the query is:

extension MyObject {
    public struct ObjectIntentQuery: EntityQuery {
        @Dependency
        var objectManager: MockObjectDataManager
        public init() {}

        public func entities(for identifiers: [MyObject.ID]) async throws -> [MyObject] {
            return objectManager.objects.filter { identifiers.contains($0.id) }
        }

        public func suggestedEntities() async throws -> [MyObject] {
            return objectManager.objects
        }
    }
}

The list of entities is retrieved in the right way since when running the shortcut manually the visual UI prompt shows the correct options. Why doesn't siri work in this case?

Upvotes: 0

Views: 115

Answers (0)

Related Questions