使用Python API请求的Alexa技能

时间:2019-01-18 19:39:15

标签: python-2.7 alexa alexa-skills-kit alexa-skill alexa-slot

我的alexa技能应该从用户那里获取输入,然后查找route_code以将其输入到api请求url中。在本地测试中它可以工作,但是由于某种原因,现在我的代码在使用alexa进行测试时没有输入route_code,我不确定可能会丢失什么或弄乱了什么地方,因为当我查看JSON时,它确实匹配成功。目前,它仅输出repromt_text,而不是应从api请求中输出的消息

下面是它似乎未按预期运行的地方。完整的代码在这里https://github.com/meyrickj/Alexa-skill-Philly-Tranist/blob/master/lambda_function.py

def get_status(intent):
session_attributes = {}
card_title = "Septa Status"
speech_output = "I'm not sure which route you wanted the status for. " \
                "Please try again. Try asking about the Market Frankford line or a bus route, such as Route 66."
reprompt_text = "I'm not sure which route you wanted the status for. " \
                "Try asking about the Market Frankford line or a bus route, such as Route 66."
should_end_session = False

if "Route" in intent["slots"]:
    route_name = intent["slots"]["Route"]["value"]

    route_code = get_route_code(route_name.lower())

    if (route_code != "unkn"):

        response = urllib2.urlopen(API_BASE_URL + "/Alerts/get_alert_data.php?req1=" + route_code)
        route_status = json.load(response)  

        if len(route_status[0]["current_message"]) > 0:
            speech_output = "The current status of" + route_status[0]["route_name"] + route_status[0]["current_message"] 
        else:
            speech_output = "The " + route_status[0]["route_name"] + " is running normally."   

        reprompt_text = ""

return build_response(session_attributes, build_speechlet_response(
   card_title, speech_output, reprompt_text, should_end_session))

0 个答案:

没有答案
相关问题