1

I am making an alexa skill using Flask-Ask which has a custom slot - Gender. The main values are "Male", "Female" and the corresponding synonyms are "He", "she", "boy", "girl" etc

The skill simply responds with the gender of the person. Eg. An utterance of "He is 24 years old" should give "male" but is giving "he" as a response

I can see the correct values in the Json output of the skill but is there a simpler built-in function for handling resolutions in flask-ask than coding for that in the intent handler or parsing the json response?

Any help will be very appreciated

1 Answers1

1

I was having a similar issue, I parsed the JSON with a small function:

def resolved_values(request):
    """
    Takes the request JSON and converts it into a dictionary of your intent
    slot names with the resolved value.

    Example usage:

    resolved_vals = resolved_values(request)
    txt = ""
    for key, val in resolved_vals.iteritems():
        txt += "\n{}:{}".format(key, val)


    :param request: request JSON
    :return: {intent_slot_name: resolved_value}
    """
    slots = request["intent"]["slots"]
    slot_names = slots.keys()

    resolved_vals = {}

    for slot_name in slot_names:
        slot = slots[slot_name]

        if "resolutions" in slot:
            slot = slot["resolutions"]["resolutionsPerAuthority"][0]
            slot_status = slot["status"]["code"]
            if slot_status == "ER_SUCCESS_MATCH":
                resolved_val = slot["values"][0]["value"]["name"]
                resolved_vals[slot_name] = resolved_val
            else:
                resolved_vals[slot_name] = None
        else:  # No value found for this slot value
            resolved_vals[slot_name] = None
    return resolved_vals
Avi Vajpeyi
  • 568
  • 6
  • 17