Adding a Value Prompt before invoking the sendQuestionToMe function

I'm currently working on an app that utilizes AppIntents. I have a specific requirement where I want the user to be able to ask a question using a Value Prompt before the sendQuestionToMe function is invoked.

Here's a snippet of my code:

// Imports and struct definitions...

struct QuestionForAll: AppIntent {
    // Intent properties...

    func perform() async throws -> some IntentResult & ProvidesDialog {
        let entities = try await QuestionAppEntityQuery().suggestedEntities()
        let questions = entities.map { $0.name }

        guard let question = question else {
            throw NSError(domain: "", code: -1, userInfo: [NSLocalizedDescriptionKey: "No question provided"])
        }

        let answer = try await sendQuestionToMe(question)
        print(answer)

        // Return the response as an IntentResult
        return .result(
            dialog: IntentDialog(stringLiteral: answer)
        )
    }
}

I would like to add a Value Prompt to the perform() function so that the user can input their question before the sendQuestionToMe function is called.

Could someone please guide me on how to implement this? Any help would be greatly appreciated.

Thank you in advance!

Replies

Solved! No need for Entities if it's only a Value Prompt.

		if question == nil || question!.isEmpty {
			question = try await $question.requestValue(IntentDialog("What would you like to know?"))
			if question == nil || question!.isEmpty {
				throw NSError(domain: "", code: -1, userInfo: [NSLocalizedDescriptionKey: "No question provided"])
			}
		}