actions-on-google / actions-on-google-testing-nodejs

Apache License 2.0
75 stars 18 forks source link

Fix bug for finalResponse #3

Closed adamcohenrose closed 6 years ago

adamcohenrose commented 6 years ago

The finalResponse code was never reached since the debugInfo.expectedInputs was undefined and so indexing into the zeroth item resulted in an error

Fleker commented 6 years ago

Thanks a lot for filing this PR! Do you have an example project that I can use to verify your patch? At some point soon there'll be actual tests to verify parsing these responses, so it'll be helpful to at least grab the JSON response that is returned so that this won't be an issue going forward.

Fleker commented 6 years ago

I've managed to reproduce this when Number Genie is exiting:

{
  conversationToken: '[\"_actions_on_google\",\"game\",\"yes_no\"]',
  finalResponse: {
    richResponse: {
      items: [
        {
          simpleResponse: {
            textToSpeech: '<speak>OK, I\'m already thinking of a number for next time.</speak>',
            displayText: 'OK, I\'m already thinking of a number for next time.',
          },
        },
      ],
    },
  },
  responseMetadata: {
    status: {
      message: 'Success (200)',
    },
    queryMatchInfo: {
      queryMatched: true,
      intent: '2ae41bb5-5423-414d-9190-1b6dd460e12f',
    },
  },
  userStorage: '{\"data\":{}}',
}
Fleker commented 6 years ago

Do you think it would make more sense to make this a conditional, ie:

debugInfo.expectedInputs ?
    debugInfo.expectedInputs[0].inputPrompt.richInitialPrompt :
    debugInfo.finalResponse.richResponse
adamcohenrose commented 6 years ago

Sorry for taking so long to respond. Great that you've found an example!

Yes, I agree – it's clearer as a conditional.

Fleker commented 6 years ago

A bunch of fixes have been published as part of the move to TypeScript, so this should be resolved now.