question

BradleyGamiMarques avatar image
BradleyGamiMarques asked

How do I create multi-turn dialogs with flask-ask and python 3.6?

I am currently developing an Alexa Skill in Python using John Wheeler's Flask-Ask library.

I want to be able to support multi-turn dialogs and I am not sure how to accomplish this.

Expected Behavior

Alexa: "Welcome to Volume Calculator. Would you like to calculate the volume of an object?"

User: "Yes"

Alexa: "Which object would you like me to calculate the volume of?"

User: "Box"

Alexa: "What is the length of the box?"

User: "5"

Alexa: "What is the width of the box?"

User: "5"

Alexa: "What is the height of the box?"

User: "5"

Alexa "The volume of the box is one-hundred and twenty-five cubic meters."

What do I need to write in Python to accomplish this behavior?

The intent is the BoxVolumeIntent and here is the associated json:

{
        "name": "BoxVolumeIntent",
        "samples": [
          "box",
          "give me the volume of a box"
        ],
        "slots": [
          {
            "name": "length",
            "type": "AMAZON.NUMBER",
            "samples": [
              "{length}",
              "length is {length}",
              "length equals {length}",
              "the length equals {length}",
              "the length is {length}",
              "the length is equal to {length}",
              "the box length is {length}",
              "box length is {length}",
              "the length of the box is {length}",
              "the box length is equal to {length}"
            ]
          },
          {
            "name": "width",
            "type": "AMAZON.NUMBER",
            "samples": [
              "{width}",
              "width is {width}",
              "width equals {width}",
              "the width equals {width}",
              "the width is {width}",
              "the width is equal to {width}",
              "the box width is {width}",
              "box width is {width}",
              "the width of the box is {width}",
              "the box width is equal to {width}"
            ]
          },
          {
            "name": "height",
            "type": "AMAZON.NUMBER",
            "samples": [
              "{height}",
              "height is {height}",
              "height equals {height}",
              "the height equals {height}",
              "the height is {height}",
              "the height is equal to {height}",
              "the box height is {height}",
              "box height is {height}",
              "the height of the box is {height}",
              "the box height is equal to {height}"
            ]
          }
        ]
      }
    ]

alexa skills kitskillhow-topythondialog model
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

BradleyGamiMarques avatar image
BradleyGamiMarques answered

I have solved the problem I was having and I would like to share my findings. First I needed a way to get my session's dialogState so I wrote a helper function to do that. Make sure you import session from flask-ask

def get_dialog_state():
    return session['dialogState]

@ask.intent("BoxVolumeIntent", convert={'length': int, 'width': int, 'height': int})
def calculate_box_volume(length, width, height):

    dialog_state = get_dialog_state()
    if dialog_state != "COMPLETED":
        return delegate(speech=None)

    box_volume = length * width * height
    return statement("The volume of the box is {} cubic meters"
                     .format(box_volume))
1 comment
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Can u share your complete code with us @BradleyGamiMarques? It'll be really helpful because i'm trying to fit this block of code for delegate directive but i'm not able to make it work. And I would also like to know that you have created separate "BoxLengthIntent", "BoxHeightIntent" etc. as intents so are they having any slots or if they are empty? Please provide some insights regarding this. It'll be really helpful! Thanks!

0 Likes 0 ·