Heapify
Heapify

Reputation: 2901

Alexa Skills Kit Works During Test But Doesn't Work in the Device

I am using Python 2.7 to create an Alexa skill. I created a lambda function in Python and connected it to the Alexa skill. All steps from start to finish works great in the test, but doesn't work in the Amazon Echo Device. It says "There was some problem with the response". Totally vague. I don't know how to debug this. Can anybody suggest what are my options here? I had an understanding that if something works in the test, it should also work in the device. Is this a common issue?

To summarize I am looking for answers to the below two questions:

  1. How do I debug when I get an error in the device and not in the test?
  2. Has anybody else also experienced this? (this is to understand how common this issue is)

Thanks in advance for your help.

Upvotes: 0

Views: 965

Answers (2)

Heapify
Heapify

Reputation: 2901

I wanted to share how I solved this problem. I was using the Python API. I looked into the logs in CloudWatch and for some reason it was throwing KeyError in the session_attributes, a dictionary that was passed. To clarify, here is the before and after of the code and it solves the problem:

Before:

def get_welcome_response():
    """
    called by on_launch function
    """
    session_attributes = {}
    card_title = "Welcome"
    speech_output = "some text"
    reprompt_text = "some text"
    should_end_session = False
    return build_response(session_attributes, build_speechlet_response(
    card_title, speech_output, reprompt_text, should_end_session))

def predict(intent, session):
    """
    called by on_intent function
    """

    session_attributes = session['attributes'] # was throwing KeyError 
    here, but not throwing while test

    if 'value' in intent['slots']['petalLength'].keys():
        session_attributes['petalLength'] = intent['slots']['petalLength']['value']
        session['attributes'] = session_attributes
        return ellicit_petal_width(intent, session)
    elif 'value' in intent['slots']['petalWidth'].keys():
        session_attributes['petalWidth'] = intent['slots']['petalWidth']['value']
        session['attributes'] = session_attributes
        return ellicit_sepal_length(intent, session)
    elif 'value' in intent['slots']['sepalLength'].keys():
        session_attributes['sepalLength'] = intent['slots']['sepalLength']['value']
        session['attributes'] = session_attributes
        return ellicit_sepal_width(intent, session)
    elif 'value' in intent['slots']['sepalWidth'].keys():
        session_attributes['sepalWidth'] = intent['slots']['sepalWidth']['value']
        session['attributes'] = session_attributes
        return get_prediction(intent, session)

After:

def get_welcome_response():
    """
    called by on_launch function
    """
    session_attributes = {}
    card_title = "Welcome"
    speech_output = "some text"
    reprompt_text = "some text"
    should_end_session = False
    return build_response(session_attributes, build_speechlet_response(
    card_title, speech_output, reprompt_text, should_end_session))

def predict(intent, session):
    """
    called by on_intent function
    """

    #added the following and solved the problem
    if 'attributes' not in session.keys():
        session['attributes'] = {}
        session_attributes = session['attributes']
    else:    
        session_attributes = session['attributes']

    if 'value' in intent['slots']['petalLength'].keys():
        session_attributes['petalLength'] = intent['slots']['petalLength']['value']
        session['attributes'] = session_attributes
        return ellicit_petal_width(intent, session)
    elif 'value' in intent['slots']['petalWidth'].keys():
        session_attributes['petalWidth'] = intent['slots']['petalWidth']['value']
        session['attributes'] = session_attributes
        return ellicit_sepal_length(intent, session)
    elif 'value' in intent['slots']['sepalLength'].keys():
        session_attributes['sepalLength'] = intent['slots']['sepalLength']['value']
        session['attributes'] = session_attributes
        return ellicit_sepal_width(intent, session)
    elif 'value' in intent['slots']['sepalWidth'].keys():
        session_attributes['sepalWidth'] = intent['slots']['sepalWidth']['value']
        session['attributes'] = session_attributes
        return get_prediction(intent, session)

My conclusion: Looks like session object doesn't have a key called "attributes" while running the skill in the device. But, it does have the "attributes" key while running it in the test.

Upvotes: 0

Vijayanath Viswanathan
Vijayanath Viswanathan

Reputation: 8571

There are couple of things you can try,

a. Make sure you have created Interaction model for the language you have registered your echo (Eg:- If your echo setup for English(UK) then you should need interaction model for English(UK). Please see the picture attached. )

enter image description here

b. If you have above settings already then Check the logs in CloudWatch against you Lambda function. If you have a problem then it would have been tracked in log.

Upvotes: 2

Related Questions