Code Monkey home page Code Monkey logo

Comments (9)

nikhilym avatar nikhilym commented on May 23, 2024 2

Thanks for the update @abdiels . I will be closing this issue.

Just to answer your question on switching intents, so, as part of the v2 SDK design, a request handler can process more than one intent or in fact any condition that is checked under it's can_handle function. So, rather than calling another handler's handle function, it is better (easier code structure) to create handlers that can handle all the cases. But, the as @timothyaaron mentioned, you can always call any other handler's handle method, as a normal function call in your handle method. All the SDK needs is to send a valid Response back to the user. Hope this helps.

If you are having any other questions, please either reopen this issue or raise another one!!

from alexa-skills-kit-sdk-for-python.

westlakem avatar westlakem commented on May 23, 2024 1

The recommended way breaks dialog flow. You cannot pass the intentHandler to a "handle" function and then in that other intent have it delegate because the request & slots are of the wrong intent

from alexa-skills-kit-sdk-for-python.

timothyaaron avatar timothyaaron commented on May 23, 2024

I've seen this done (I'm thinking it was in one of the demo files) by just returning the handle of the Handler you want to redirect to. See the last line of this exampleโ€ฆ

class LaunchHandler(AbstractRequestHandler):
    def can_handle(self, handler_input):
        return  is_request_type("LaunchRequest")(handler_input)

    def handle(self, handler_input):
        # wrote some launch code here
        return handler_input.response_builder.response

class ResetHandler(AbstractRequestHandler):
    def can_handle(self, handler_input):
        return  is_intent_name("ResetIntent")(handler_input)

    def handle(self, handler_input):
        handler_input.attributes_manager.session_attributes = {}
        return LaunchHandler().handle(handler_input)

from alexa-skills-kit-sdk-for-python.

timothyaaron avatar timothyaaron commented on May 23, 2024

Of course, in this overly simplified example you could also just add or is_intent_name("ResetIntent")(handler_input) to your LaunchHandler.can_handle and handle the one-off inside your LaunchHandler.handle code...

class LaunchHandler(AbstractRequestHandler):
    def can_handle(self, handler_input):
        return  (
            is_request_type("LaunchRequest")(handler_input) or
            is_intent_name("ResetIntent")(handler_input)
        )

    def handle(self, handler_input):
        if is_intent_name("ResetIntent")(handler_input):
            handler_input.attributes_manager.session_attributes = {}

        # wrote some launch code here
        return handler_input.response_builder.response

from alexa-skills-kit-sdk-for-python.

nikhilym avatar nikhilym commented on May 23, 2024

Hey @abdiels , thanks for the link to the issue. As you can see, that feature was available in the v1 version of the SDK. However, in the v2 version of the Node SDK, this feature has not been added. Instead, you can call any handler's handle() code directly as mentioned by @timothyaaron (Thanks for mentioning both approaches ๐Ÿ˜„ ) in his first comment.

Instead if you want multiple events to be handled by a single handler, you can use the can_handle function to do all your validation as mentioned by @timothyaaron in his second comment.

Does that suffice your needs? Or you were looking for something else?

from alexa-skills-kit-sdk-for-python.

abdiels avatar abdiels commented on May 23, 2024

First, thank you all for replying. I have to try it out. I will tonight. I wonder what this does to the dialog status and things of that nature. If the dialog is IN_PROGRESS in one intent, I was not sure you can change to another,, but when it is COMPLETE, right now (without trying to change manually), my app seems to end regardless if the user says an utterance that should direct them to a different intent.

My use case is basically like this...on launch I do an API lookup and give the user options with numbers and I have an intent with 2 slots (In my mind they could be separate intents, but I have it as one now as I have had this kind of issue). Once those slots are filled (I asked for the other in the intent handler), I want to give the user a choice say you can "study" or you can be "quizzed". To me those should be two separate intents, but once I fill out both slots it did not switch to either or them regardless of what the user say. I could be going about this the wrong way, but I thought that instead of allowing the dialog to be completed, I could direct the user to either of those intents. I hope this makes sense. Any advice would be appreciated and I will try the approach suggested by @timothyaaron

from alexa-skills-kit-sdk-for-python.

nikhilym avatar nikhilym commented on May 23, 2024

Hey @abdiels , any update? Did you get around the problem?

from alexa-skills-kit-sdk-for-python.

abdiels avatar abdiels commented on May 23, 2024

Thank you for following up. I have been meaning to reply, but I had not since I did not really get it to work the way suggested; however, I have learned that the approach I was using was not correct. So I believe this can be closed.
Just to try an understand further the suggesting is to call the method than handles the particular intent we want to switch to...I thought that was not allowed since the intent passed into the input handler is already address to the intent where I am sitting on.
Again, that is more of a curiosity satisfaction questions as my original issue was basically lack of knowledge more than really needed the requested feature.

from alexa-skills-kit-sdk-for-python.

nikhilym avatar nikhilym commented on May 23, 2024

Hey @westlakem , as mentioned by @tianrenz on the issue you created on NodeJS SDK, the emitWithState feature in the V1 NodeJS SDK world forwarded the same request to a different function, and will not change the intent/slot information in the request. That is similar to the approach mentioned above, on how to get that working in the current SDK design.

Let's move this discussion to the issue logged on the NodeJS SDK, since all the SDK's follow the same design approach and in case there is a feature request agnostic to the language, we can work on it through the details provided there. In case you have any other questions, please log a new issue so that we can track it in an efficient manner. Thanks.

from alexa-skills-kit-sdk-for-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.