Make intents end Snips session without speech (#28820)

* intents should also end session without speech

* Move endSession message to try block

* Minor improvement on endSession response
This commit is contained in:
Paul Romkes 2019-11-18 09:13:22 +01:00 committed by Pascal Vizeli
parent 90c7d0e56a
commit 5731f528d2

View File

@ -135,7 +135,6 @@ async def async_setup(hass, config):
intent_type = request["intent"]["intentName"].split("__")[-1] intent_type = request["intent"]["intentName"].split("__")[-1]
else: else:
intent_type = request["intent"]["intentName"].split(":")[-1] intent_type = request["intent"]["intentName"].split(":")[-1]
snips_response = None
slots = {} slots = {}
for slot in request.get("slots", []): for slot in request.get("slots", []):
slots[slot["slotName"]] = {"value": resolve_slot_values(slot)} slots[slot["slotName"]] = {"value": resolve_slot_values(slot)}
@ -148,8 +147,15 @@ async def async_setup(hass, config):
intent_response = await intent.async_handle( intent_response = await intent.async_handle(
hass, DOMAIN, intent_type, slots, request["input"] hass, DOMAIN, intent_type, slots, request["input"]
) )
notification = {"sessionId": request.get("sessionId", "default")}
if "plain" in intent_response.speech: if "plain" in intent_response.speech:
snips_response = intent_response.speech["plain"]["speech"] notification["text"] = intent_response.speech["plain"]["speech"]
_LOGGER.debug("send_response %s", json.dumps(notification))
mqtt.async_publish(
hass, "hermes/dialogueManager/endSession", json.dumps(notification)
)
except intent.UnknownIntent: except intent.UnknownIntent:
_LOGGER.warning( _LOGGER.warning(
"Received unknown intent %s", request["intent"]["intentName"] "Received unknown intent %s", request["intent"]["intentName"]
@ -157,17 +163,6 @@ async def async_setup(hass, config):
except intent.IntentError: except intent.IntentError:
_LOGGER.exception("Error while handling intent: %s.", intent_type) _LOGGER.exception("Error while handling intent: %s.", intent_type)
if snips_response:
notification = {
"sessionId": request.get("sessionId", "default"),
"text": snips_response,
}
_LOGGER.debug("send_response %s", json.dumps(notification))
mqtt.async_publish(
hass, "hermes/dialogueManager/endSession", json.dumps(notification)
)
await hass.components.mqtt.async_subscribe(INTENT_TOPIC, message_received) await hass.components.mqtt.async_subscribe(INTENT_TOPIC, message_received)
async def snips_say(call): async def snips_say(call):