Alexa仅调用LauchRequest而不是意图

时间:2018-06-27 06:45:17

标签: python json aws-lambda alexa alexa-skills-kit

嗨,我在以下链接中关注使用Python for Alexa的事实技能教程: https://github.com/alexa/skill-sample-python-fact

我的问题是Alexa仅启动了“ LaunchRequest”

def lambda_handler(event, context):
    # App entry point 

    #print(event)

    if event['session']['new']:
        on_session_started()

    if event['request']['type'] == "LaunchRequest":
        return on_launch(event['request'])
    elif event['request']['type'] == "IntentRequest":
        return on_intent(event['request'], event['session'])
    elif event['request']['type'] == "SessionEndedRequest":
        return on_session_ended()

但是它不会为“ GetNewFactIntent”执行“ IntentRequest”

def on_intent(request, session):
    """ called on receipt of an Intent  """

    intent_name = request['intent']['name']

    # process the intents
    if intent_name == "GetNewFactIntent":
    return get_fact_response()
    elif intent_name == "AMAZON.HelpIntent":
        return get_help_response()
    elif intent_name == "AMAZON.StopIntent":
        return get_stop_response()
    elif intent_name == "AMAZON.CancelIntent":
        return get_stop_response()
    elif intent_name == "AMAZON.FallbackIntent":
        return get_fallback_response()
    else:
        print("invalid Intent reply with help")
        return get_help_response()

因此,只有在调用函数时调用名称才有效,并且“ GetNewFactIntent”中的示例语音不会调用函数。 我的猜测是,它在传递给AWS Lambda的JSON方面存在问题。它没有收到“ IntentRequest”,或者找不到

intent_name = request['intent']['name']

JSON模式:

{
    "interactionModel": {
        "languageModel": {
            "invocationName": "space facts",
            "intents": [
                {
                    "name": "AMAZON.CancelIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.HelpIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.StopIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.FallbackIntent",
                    "samples": []
                },
                {
                    "name": "GetNewFactIntent",
                    "slots": [],
                    "samples": [
                        "a fact",
                        "a space fact",
                        "tell me a fact",
                        "tell me a space fact",
                        "give me a fact",
                        "give me a space fact",
                        "tell me trivia",
                        "tell me a space trivia",
                        "give me trivia",
                        "give me a space trivia",
                        "give me some information",
                        "give me some space information",
                        "tell me something",
                        "give me something"
                    ]
                }
            ],
            "types": []
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我的问题是我没有告诉我调用名称。因此,教训是:在意图之前,首先要调用。