Alexa Progressive Response after ON_ELEMENT_SELECTED not working


#1

I have a Jovo skill where a user chooses a category via a touch selection on the screen (using APL) which then reads data out of a database before responding to the user. I have added a Progressive Response that says “Please wait while I get that category for you”. If I say the category verbally, the skill works fine. If I use the touch screen to select the category, I get the error: Request failed with status code 403 (screenshot shown below:)

In the case where it works, I believe the code progression is as follows:
ON_REQUEST–>ChooseCategoryIntent()

When it doesn’t work, the progression in my code is:
ON_ELEMENT_SELECTED()–>return this.toStateIntent('GetCategoryState', 'ChooseCategoryIntent');–>ChooseCategoryIntent()

Am I missing something or is this a bug? Any suggestions to help debug the problem? For now, I have an if statement based on the incoming route to avoid the error, but I’d like this to work.

Thanks in advance for any help or suggestions.


#2

Hey @Ben_Hartman

I think I understand the problem but could you provide a little more code? Just to make it easier to reproduce the issue.


#3

Sure @AlexSwe

Here’s a condensed version of my code where I get the key press:

ON_ELEMENT_SELECTED() {
    const requestType = this.$request.request.type;
    const requestArg = this.$request.request.arguments[0];
    if (requestType === 'Alexa.Presentation.APL.UserEvent') {
      if (requestArg === 'ListItemSelected') {
        // Get the category
        const categoryIdx = this.$request.request.arguments[1] - 1; // turn it to '0'-based
        const category = Spreadsheet.getCategories()[categoryIdx]; 
        this.$session.$data.chosenCategory = category;
        console.log(`GOT CATEGORY LIST TOUCH EVENT! Category: ${category}`);
        return this.toStateIntent('GetCategoryState', 'ChooseCategoryIntent');
      }
    }
  } 

…and here’s a snippet of the code where I try to use the Progressive Response:

GetCategoryState: {
  async ChooseCategoryIntent() {
    var route = this.getRoute();
    var keyPressEntry = typeof route.from != 'undefined' 
      && route.from.includes('ON_ELEMENT_SELECTED'); 

    // Get the input from the user
    var userCategory;
    if (keyPressEntry) {
      userCategory = this.$session.$data.chosenCategory;
    } else {
      userCategory = this.$inputs.category.value;
      console.log(`CHOOSE CATEGORY: value->${userCategory}, key->${this.$inputs.category.key}`);
    }

    // Check if the user said "random"
    if (userCategory.toLowerCase() === 'random') {
      if (this.isAlexaSkill() && !keyPressEntry) {
        // Let user know this could take a little bit
        await this.$alexaSkill.progressiveResponse
          (`Please wait while I generate a random mix of words.`);
      }
      await Spreadsheet.loadRandomMix();
    }
.
.
.

I get the error when the progressive response line is executed and I don’t have the check for keyPressEntry - (I have the check for keyPressEntry in the code right now so I can continue testing). Fortunately, it’s not a huge deal, since the response is not necessary for the skill to work properly. I just like to use them when I have to call an API that’s going to take a few seconds.

Finally, here’s the relevant portion of the APL JSON:

{
            "type": "AlexaTextList",
            "theme": "${viewport.theme}",
            "headerTitle": "${textListData.headerTitle}",
            "headerSubtitle": "${textListData.headerSubtitle}",
            "headerAttributionImage": "${textListData.headerAttributionImage}",
            "headerDivider": true,
            "headerBackButtonAccessibilityLabel": "back",
            "headerBackButtonCommand": {
              "type": "SendEvent",
              "arguments": [
                "goBack"
              ]
            },
            "backgroundImageSource": "${textListData.backgroundImageSource}",
            "backgroundScale": "best-fill",
            "backgroundAlign": "center",
            "primaryAction": {
              "type": "SendEvent",
              "arguments": [
                "ListItemSelected",
                "${ordinal}"
              ]
            },
            "listItems": "${textListData.listItemsToShow}"
          }

Let me know if you need anything else or if you’d like me to clarify anything.

I appreciate you guys looking into this.


#4

I think it’s an Alexa bug. I dived in a little deeper and discovered the following. Like you said, it works with regular requests. TouchEvents seem not to be regular requests for the Alexa API.

The API call to make progressive responses requires the requestId from the request. Both requests (regular and touch) have the requestId, but a call after the touch event request throws `‘Unrecognized requestId: <REQUEST_ID>’.

Unfortunately, we can’t fix that on our side :frowning:


#5

That makes sense. Fortunately for me, it’s not a huge deal and I can if…then my way around this special case.

Thanks for looking into it for me.