I have a very simple AppIntent but Siri is easily confused when capturing parameters and responds with "Something went wrong" then silently terminates the process - how do I see the error and ask the user to try again?
The error happens before the Perform method and only when running on a handset.
import AppIntents
import SwiftUI
enum MyValues: String {
case no
case alittle
case alot
}
extension MyValues: AppEnum {
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Choose values"
static var caseDisplayRepresentations: [MyValues: DisplayRepresentation] = [
.no: "No",
.alittle: "A little",
.alot: "A lot"
]
static var scoreFromValue: [MyValues: Int] = [
.no: 1,
.alittle: 3,
.alot: 5
]
}
struct MyIntent: AppIntent {
static private func score(values: [Int]) -> String {
let result = values.reduce(1, *)
return String(result)
}
static let title: LocalizedStringResource = "Values Questionnaire"
@Parameter(title: "value1", requestValueDialog:("Question 1?") )
var valueOne: MyValues
@Parameter(title: "value2", requestValueDialog:("Question 2?"))
var valueTwo: MyValues
@Parameter(title: "value3", requestValueDialog:("Question 3?"))
var valueThree: MyValues
@Parameter(title: "value4", requestValueDialog: ("Question 4?"))
var valueFour: MyValues
@MainActor
func perform() async throws -> some IntentResult{
return .result(dialog: """
I got \(valueOne.rawValue), \(valueTwo.rawValue), \(valueThree.rawValue) and \(valueFour.rawValue) which is a score of \(MyIntent.score(values: [MyValues.scoreFromValue[valueOne] ?? 0, MyValues.scoreFromValue[valueTwo] ?? 0, MyValues.scoreFromValue[valueThree] ?? 0, MyValues.scoreFromValue[valueFour] ?? 0]))
""")
}
}