Skip to content
Snippets Groups Projects
Commit 5731f528 authored by Paul Romkes's avatar Paul Romkes Committed by Pascal Vizeli
Browse files

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
parent 90c7d0e5
No related branches found
No related tags found
No related merge requests found
......@@ -135,7 +135,6 @@ async def async_setup(hass, config):
intent_type = request["intent"]["intentName"].split("__")[-1]
else:
intent_type = request["intent"]["intentName"].split(":")[-1]
snips_response = None
slots = {}
for slot in request.get("slots", []):
slots[slot["slotName"]] = {"value": resolve_slot_values(slot)}
......@@ -148,8 +147,15 @@ async def async_setup(hass, config):
intent_response = await intent.async_handle(
hass, DOMAIN, intent_type, slots, request["input"]
)
notification = {"sessionId": request.get("sessionId", "default")}
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:
_LOGGER.warning(
"Received unknown intent %s", request["intent"]["intentName"]
......@@ -157,17 +163,6 @@ async def async_setup(hass, config):
except intent.IntentError:
_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)
async def snips_say(call):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment