Skip to content

Commit e61f162

Browse files
authored
Include Assist JSON value in Shortcuts result (home-assistant#2293)
<!-- Thank you for submitting a Pull Request and helping to improve Home Assistant. Please complete the following sections to help the processing and review of your changes. Please do not delete anything from this template. --> ## Summary <!-- Provide a brief summary of the changes you have made and most importantly what they aim to achieve --> ## Screenshots <!-- If this is a user-facing change not in the frontend, please include screenshots in light and dark mode. --> ## Link to pull request in Documentation repository <!-- Pull requests that add, change or remove functionality must have a corresponding pull request in the Companion App Documentation repository (https://github.com/home-assistant/companion.home-assistant). Please add the number of this pull request after the "#" --> Documentation: home-assistant/companion.home-assistant# ## Any other notes <!-- If there is any other information of note, like if this Pull Request is part of a bigger change, please include it here. -->
1 parent e3e0bf5 commit e61f162

File tree

2 files changed

+93
-29
lines changed

2 files changed

+93
-29
lines changed

Sources/App/Resources/Base.lproj/Intents.intentdefinition

Lines changed: 84 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,26 +2030,6 @@
20302030
<key>INIntentParameterPromptDialogType</key>
20312031
<string>Primary</string>
20322032
</dict>
2033-
<dict>
2034-
<key>INIntentParameterPromptDialogCustom</key>
2035-
<true/>
2036-
<key>INIntentParameterPromptDialogFormatString</key>
2037-
<string>There are ${count} options matching ‘${language}’.</string>
2038-
<key>INIntentParameterPromptDialogFormatStringID</key>
2039-
<string>Z3WVKZ</string>
2040-
<key>INIntentParameterPromptDialogType</key>
2041-
<string>DisambiguationIntroduction</string>
2042-
</dict>
2043-
<dict>
2044-
<key>INIntentParameterPromptDialogCustom</key>
2045-
<true/>
2046-
<key>INIntentParameterPromptDialogFormatString</key>
2047-
<string>Just to confirm, you wanted ‘${language}’?</string>
2048-
<key>INIntentParameterPromptDialogFormatStringID</key>
2049-
<string>05aeZv</string>
2050-
<key>INIntentParameterPromptDialogType</key>
2051-
<string>Confirmation</string>
2052-
</dict>
20532033
</array>
20542034
<key>INIntentParameterSupportsDynamicEnumeration</key>
20552035
<true/>
@@ -2091,7 +2071,7 @@
20912071
</dict>
20922072
</array>
20932073
<key>INIntentResponseLastParameterTag</key>
2094-
<integer>2</integer>
2074+
<integer>3</integer>
20952075
<key>INIntentResponseOutput</key>
20962076
<string>result</string>
20972077
<key>INIntentResponseParameters</key>
@@ -2105,10 +2085,14 @@
21052085
<integer>1</integer>
21062086
<key>INIntentResponseParameterName</key>
21072087
<string>result</string>
2088+
<key>INIntentResponseParameterObjectType</key>
2089+
<string>IntentAssistResult</string>
2090+
<key>INIntentResponseParameterObjectTypeNamespace</key>
2091+
<string>sI7YSe</string>
21082092
<key>INIntentResponseParameterTag</key>
2109-
<integer>1</integer>
2093+
<integer>3</integer>
21102094
<key>INIntentResponseParameterType</key>
2111-
<string>String</string>
2095+
<string>Object</string>
21122096
</dict>
21132097
<dict>
21142098
<key>INIntentResponseParameterDisplayName</key>
@@ -2418,6 +2402,83 @@
24182402
</dict>
24192403
</array>
24202404
</dict>
2405+
<dict>
2406+
<key>INTypeDisplayName</key>
2407+
<string>Assist Result</string>
2408+
<key>INTypeDisplayNameID</key>
2409+
<string>DhCruz</string>
2410+
<key>INTypeLastPropertyTag</key>
2411+
<integer>100</integer>
2412+
<key>INTypeName</key>
2413+
<string>IntentAssistResult</string>
2414+
<key>INTypeProperties</key>
2415+
<array>
2416+
<dict>
2417+
<key>INTypePropertyDefault</key>
2418+
<true/>
2419+
<key>INTypePropertyDisplayPriority</key>
2420+
<integer>1</integer>
2421+
<key>INTypePropertyName</key>
2422+
<string>identifier</string>
2423+
<key>INTypePropertyTag</key>
2424+
<integer>1</integer>
2425+
<key>INTypePropertyType</key>
2426+
<string>String</string>
2427+
</dict>
2428+
<dict>
2429+
<key>INTypePropertyDefault</key>
2430+
<true/>
2431+
<key>INTypePropertyDisplayPriority</key>
2432+
<integer>2</integer>
2433+
<key>INTypePropertyName</key>
2434+
<string>displayString</string>
2435+
<key>INTypePropertyTag</key>
2436+
<integer>2</integer>
2437+
<key>INTypePropertyType</key>
2438+
<string>String</string>
2439+
</dict>
2440+
<dict>
2441+
<key>INTypePropertyDefault</key>
2442+
<true/>
2443+
<key>INTypePropertyDisplayPriority</key>
2444+
<integer>3</integer>
2445+
<key>INTypePropertyName</key>
2446+
<string>pronunciationHint</string>
2447+
<key>INTypePropertyTag</key>
2448+
<integer>3</integer>
2449+
<key>INTypePropertyType</key>
2450+
<string>String</string>
2451+
</dict>
2452+
<dict>
2453+
<key>INTypePropertyDefault</key>
2454+
<true/>
2455+
<key>INTypePropertyDisplayPriority</key>
2456+
<integer>4</integer>
2457+
<key>INTypePropertyName</key>
2458+
<string>alternativeSpeakableMatches</string>
2459+
<key>INTypePropertySupportsMultipleValues</key>
2460+
<true/>
2461+
<key>INTypePropertyTag</key>
2462+
<integer>4</integer>
2463+
<key>INTypePropertyType</key>
2464+
<string>SpeakableString</string>
2465+
</dict>
2466+
<dict>
2467+
<key>INTypePropertyDisplayName</key>
2468+
<string>JSON</string>
2469+
<key>INTypePropertyDisplayNameID</key>
2470+
<string>hhPmPc</string>
2471+
<key>INTypePropertyDisplayPriority</key>
2472+
<integer>5</integer>
2473+
<key>INTypePropertyName</key>
2474+
<string>json</string>
2475+
<key>INTypePropertyTag</key>
2476+
<integer>100</integer>
2477+
<key>INTypePropertyType</key>
2478+
<string>String</string>
2479+
</dict>
2480+
</array>
2481+
</dict>
24212482
</array>
24222483
</dict>
24232484
</plist>

Sources/Shared/Intents/AssistIntentHandler.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class AssistIntentHandler: NSObject, AssistIntentHandling {
6767
}
6868
}
6969

70-
let promise: Promise<ConversationResponse> = Current.webhooks.sendEphemeral(
70+
Current.webhooks.sendEphemeral(
7171
server: server,
7272
request: .init(
7373
type: "conversation_process",
@@ -76,11 +76,14 @@ class AssistIntentHandler: NSObject, AssistIntentHandling {
7676
"language": intent.language?.identifier ?? Locale.current.identifier,
7777
]
7878
)
79-
)
80-
81-
promise.done { result in
82-
Current.Log.info("finishing with \(result)")
83-
completion(.success(result: result.speech))
79+
).map { (original: [String: Any]) -> (ConversationResponse, [String: Any]) in
80+
let object: ConversationResponse = try Mapper().map(JSONObject: original)
81+
return (object, original)
82+
}.done { object, original in
83+
Current.Log.info("finishing with \(object)")
84+
let value = IntentAssistResult(identifier: nil, display: object.speech)
85+
value.json = String(decoding: try JSONSerialization.data(withJSONObject: original), as: UTF8.self)
86+
completion(.success(result: value))
8487
}.catch { error in
8588
Current.Log.error("erroring with \(error)")
8689
completion(.failure(error: error.localizedDescription))

0 commit comments

Comments
 (0)