AppDaemon + Alexa - Multi Step Interactions!

That’s the way alexa works with custom skills.

If you just want her to respond to the user, you set the ShouldEndSession flag to true and pass one speechOutput object containing what ever it is you want her to say.

If you want her to engage in conversation with the user, you set the ShouldEndSession flag to false and pass two speechOutput objects containing the question or what ever it is you want to ask the user.
The first speechOutput object will be rendered and played to the user, it the user doesn’t resopnds within, I think it’s 3 seconds, alexa will render and play the second speechOutput object to the user, if the user doesn’t respond again, alexa will end the session sending you (the skill) a request of type SessionEnded allowing you (the skill) to do anything you would like to do when a session ends.

The thing is, when alexa sends the SessionEnded event, you’re not supposed to return anything to it, if you do return something, she will tell you that something went wrong with skill.

BTW: alexa will send a SessionEnded request for every ending of the session on the device end, even if there was an error on the device.

The thing is, with AppDaemon, I can’t “not return anything”…
So the result is, when ever a session ended on the device end and not your end (the skill), anything return by AppDaemon will be considered as “something went wrong with the skill”.

So I’m looking for a way to “kill the execution of application” and prevent AppDaemon from returning anything when I receive a SessionEnded request.

i have this and it doesnt generate a problem at the end:

        elif dialog == "COMPLETED":
            #self.log(data)      
            self.log("dialog Completed")
            self.log("*************************************************")
            intentstate = eval("self." + self.intentname)()
            if intentstate == "normalEnd":
                response = self.my_alexa_response(EndSession = False, DialogDelegate = False, speech = self.random_arg("intentEnd"), card = "Appdaemon", title = self.intentname)
            elif intentstate == "error":
                response = self.my_alexa_response(EndSession = True, DialogDelegate = False, speech = self.random_arg("responseError"), card = "Appdaemon", title = self.intentname)
            else:
                response = self.my_alexa_response(EndSession = False, DialogDelegate = False, speech = intentstate, card = "Appdaemon", title = self.intentname)
            return response, 200


    def my_alexa_response(self, EndSession = False, DialogDelegate = False, speech = None, card = None, title = None):

        response = {"shouldEndSession":EndSession}
        if DialogDelegate:
            response["directives"] = [{"type": "Dialog.Delegate", "updatedIntent": None}]

        if speech is not None:
           response["outputSpeech"] = {"type": "PlainText","text": speech}

        if card is not None:
            response["card"] = {"type": "Simple", "title": title, "content": card}

        speech = \
            {
            "version": "1.0",
            "response": response,
            "sessionAttributes": {}
            }

        return speech

How are you handling SessionEnded requests in your code?

The following states “Your service cannot send back a response to a SessionEndedRequest”:
https://developer.amazon.com/docs/custom-skills/handle-requests-sent-by-alexa.html#sessionendedrequest

BTW: I haven’t tried out the dialogState directive as the documentation states it’s only available with the use of the dialog model withing the skill builder (beta).

I’m still coding for the “old fashion” custom skills.

Maybe it’s a different flow of requests/responds when using the dialogState directive.
It actually makes sense, considering the directive is supposed to allow the skill to issue a progressive response, which means the device needs to be able to accept responds from the skill even after the session ended…

thats the big difference then.
i use the dialogstate directive.

i played around with the “old fashion” way a little bit, but that was not as usefull, because those things i could already accomplish with emulated hue.

Hmm… I don’t think I’m going to switch to dialogstate just yet.
I’m sure I’ll find away around my situation using the regular custom skill.

Thanks.

Here is what I did so far, everything works extremely well as long as the session ends on the service end and not on the device end.

1 Like

wow, and all that without dialogstate?
to accomplish something like that they created the dialog state if i am correct.
i am impressed.

i used dialogstate to get to this (sorry video in german)

1 Like

Thanks for the feedback. :slight_smile:
I’m sure I’ll figure it out eventually, I just have a lot of work lately so I haven’t found the time to try it.
I really like what you did there, maybe I’ll switch to using the dialog directive too. :wink:

1 Like

I’ve shared my (not finished) project here.

1 Like

I think you should add the skill (intens)
without that its hard to recreate anything from it :wink:

I had a feeling I forgot something…
:laughing:

Added it to the repository here.

1 Like

Based on this thread and some other references, I was able to develop and host my own intents using AppDaemon instead of Amazon Lambda. I used DialogState and the online Amazon Developer console to develop my Alexa skills. Thanks to all above who contributed.

2 Likes

i update my alexa app fast every days in the last weeks.
i even got my wife to have a complete conversation with AD through alexa :wink:

at the moment i have got quite a few intents working and the possibility for complete conversations or even goodnight stories.
in a short time i will add at all to my github, so everyone can have fun from it.

but its good to hear that you got things running.

Thanks a lot, you’ve been of great help…

1 Like

Have you added this to github yet? Do you have a link to your github?

i have added my app to my github, but only in german and without instructions.
thats why i didnt tell about it yet.
i will add instructions how to set it up and english version, but you are welcome to look at it as it is:
https://github.com/ReneTode/My-AppDaemon/tree/master/apps/alexa

2 Likes

I’m just looking for a large chunk of alexa & appdaemon code. I might be able to read german as long as they are variables :joy:, otherwise I’ll get lost. Thanks!

all vars are english. only the text that gets send to alexa (which is in the yaml file) are in german.

1 Like

Rene,
Any updates on this? I may try it out this weekend since it’s a long weekend over here.

AAA is still up and running.
only the intent documentation needs some reworking, because amazon changed its interface.