iosswiftiphonesirikitsirishortcuts

In SiriShortcut how I can handle boolean parameters?


In SiriShortcut, if I am giving a parameter of Boolean then Siri is not asking for the bool value in the dialog. This is because it is taking default value.

Is there any way to overcome this issue?

enter image description here


Solution

  • Finally, I got the solution of above problem.

    First, we need to create an Enum type with name "Save" and then add the Cases with any name you want, I give "Yes" for 1 Index and "No" for 2 Index. As you can see in the below screenshot.

    enter image description here

    Then Go to your intents and then select Type of Enum instead of Boolean.

    enter image description here

    Then select Default value as "unknown".

    enter image description here

    Then go to your IntentHandler file and then paste the below code. That can Enable Siri to ask for a value "Yes" or "No" option because by default we have selected "unknown".

    func resolveSave(for intent: SaveIntent, with completion: @escaping (SaveResolutionResult) -> Void) {
      let save = intent.save
      
      switch save {
       case .no, .yes:
        completion(SaveResolutionResult.success(with: save))
      default:
        completion(SaveResolutionResult.needsValue())
        return
      }
    }