ioBroker / ioBroker.iot

Connection for Alexa, IFTTT, Google Home and co
MIT License
71 stars 25 forks source link

Include Custom Skill start phrase in lastCommandObj #574

Open Kaldesh84 opened 1 year ago

Kaldesh84 commented 1 year ago

Please include the phrase used to start the ioBroker custom skill into the lastCommandObj.

My scenario: I wanted to trigger a dialog with a simpler phrase (wife approval factor), so I created a routine On Voice command "Alexa, start den Staubsauger" I then executed the command "Alexa, sage i. o. broker starte einen dialog mit "Welcher Bereich soll gesäubert werden" to ask for areas on my vacuum robot's map to be cleaned.

But, as I set the textCommand directly though the Alexa routine, the textCommand state in ioBroker is not changed. So, when now iot/0/lastCommandObj is changed, I can't find which "request" to the skill it relates to.

If I start the dialog mode from ioBroker itself, I can scan through alexa2.0.Echo-Devices.*.Commands.textCommand to find the latest changed textCommand state that contains "i.o. broker starte einen dialog" to find it, which is already a little clunky. With just a routine, that's not even possible.

I then have to create a virtual switch that is triggered by that routine, gets the latest used echo via alexa/0/History/serialNumber and set the textCommand state on that device. That is VERY inconvenient and also adds a necessary delay for the alexa/0/History/serialNumber state to be properly updated.

If you could include the start phrase (like "starte einen dialog mit ... ") in lastCommandObj and maybe keep it there for the whole session, this would make this dialog mode a LOT easier to use.

Apollon77 commented 1 year ago

Ok, please provide more details, show logs or scripts. I only have a rough idea what you mean

Maybe a debug log from iot adapter makes most sense to provide ...

Kaldesh84 commented 1 year ago

As I'm doing my logic via nore-red, it's somewhat difficult to include scripts, so I'll try with screenshots and added detail: get text, sessionId and textCommand

Here, I

filter

Only then can I decide what dialog logic to execute and how to process the user input

switch for different dialogs

switch And then have OUT-links to the different logic blocks for the different starting phrases.

That logic is already clunky and unsafe, because during the processing of the latest change in iot/0/lastCommandObject, a new dialog could already have been started on another alexa device, which could have changed the "last changed textCommand". Including the starting phrase for the Custom Skill would make most of this logic obsolete.

And all of the above is only possible, if I set the "textCommand" state of an alexa device myself in ioBroker. If I use a simple routine in the Alexa App that triggers on "Alexa, starte den Staubsauger" to execute the free text command "sage i.o. Broker starte einen Dialog mit Okay, welchen Bereich soll ich säubern?"

then the .../commands/textCommand state of that Alexa device is not changed in ioBroker, which is why this approach above won't work.

Then I need to add further logic: virtual switch The routine in the Alexa app needs to trigger this virtual switch, that then sets the textCommand to "sage i.o. Broker starte einen Dialog mit Okay, welchen Bereich soll ich säubern?". Then I still need get the alexa device from from alexa2/0/History/serialNumber to set the correct textCommand state, which would work out of the box from the routine in the Alexa app.

Does this clarify things a bit? We can also switch to German, if there's more unclarities ;-)

Kaldesh84 commented 1 year ago

With the mapping of the lastCommandObj.deviceId to the alexa2 serial number, things could already be simplified quite a bit, but that's not present yet, afaik.

Kaldesh84 commented 8 months ago

Bump und simplere Anfrage:

aktuell enthält iot.0.lastCommandObj folgende Werte:

Ich hätte gern noch sowas dazu:

Wo dann drin steht, was Alexa im Rahmen dieser Session zuletzt gesagt hat. Wenn ich also mit "sage i.o. broker starte Dialog mit Was kann ich für dich tun?" sage, dann sollte in dem neuen JSON Feld lastAlexaDialog eben "Was kann ich für dich tun" drin stehen. Wenn ich über iot.0.smart.lastResponseObj einen responseText setze, aber shouldEndSession auf false ist, dann sollte nach meiner nächsten Antwort eben der vorher gesetzte responseText in lastAlexaDialog drin stehen.

Das hilft, eigene und auch komplexere Logiken zu entwickeln mit mehrstufigen Konversationen.

Apollon77 commented 8 months ago

An sich ist die session is dafür gedacht weil die über mehrere Interaktionen in einer Session gleich ist. Ich muss mich in deine Anfrage mal tiefer reindenken wenn ich dazu Zeit finde.