0

嗨,我正在尝试使用请求从 Alexa 请求后端获得响应。我在这些示例中使用 Python:https ://github.com/alexa/skill-sample-python-fact 。但是我的后端是 NodeJS。

来自我的 Lambda:

URL = 'https://alexa-app-nikko.herokuapp.com/alexa'

def get_post_response():
    r = requests.get(URL)

    speech_output = str(r.text)
    return response(speech_response(speech_output, True))

在我的后端,它被路由到 /alexa:

router.get('/', function(request, response) {
    //console.log('Logged from Alexa.');
    response.send('Hello World, Alexa!');
});

我在 Lambda 上对其进行了测试,并在以下结果中正常工作:

{
  "version": "1.0",
  "response": {
    "outputSpeech": {
      "type": "PlainText",
      "text": "Hello World, Alexa!"
    },
    "shouldEndSession": true
  }
}

但是,我null从 Alexa 获得了有关技能输出或此响应的信息:

"There was a problem with the requested skill's response"

我如何从开发人员控制台进行调试,因为 Lambda 似乎很好。

4

2 回答 2

1

根据您自己的答案:

问题是,当您调用LaunchIntent或其他意图时,AMAZON.StopIntent它没有密钥"slots"。你试图访问slots应该抛出KeyError的值。

您可以做的是,当您确定调用任何使用某些插槽的特定意图时,您会尝试访问它们。

这就是我所做的:

def getSlotValue(intent, slot):
    if 'slots' in intent:
        if slot in intent['slots']:
            if 'value' in intent['slots'][slot] and len(intent['slots'][slot]['value']) > 0:
                return intent['slots'][slot]['value']

    return -1

并尝试访问您的意图函数中的插槽值(在您的get_post_responseor中get_power_response)。

于 2018-07-05T09:04:02.500 回答
0

我不知道这个问题与我的请求有什么关系。它现在正在工作。

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

    intent_name = request['intent']['name']
    #intent_slots = request['intent']['slots']

    # process the intents
    if intent_name == "DebugIntent":
        return get_debug_response()
    elif intent_name == "PostIntent":
        return get_post_response()
    elif intent_name == "PowerIntent":
        return get_power_response(request)
        #return get_power_response(intent_slots)
# ----------- Amazon Built-in Intents -----------------
    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()

我调试了它,我得到的是关键字'slots'的问题,所以我在我的代码中删除了我intent_slots = request['intent']['slots']也用来将它传递给另一个函数的代码return get_power_response(intent_slots)。我将其注释掉并替换或只是将原件requestdef on_intent(request, session):.

于 2018-07-05T04:36:37.157 回答