alexa-js / alexa-app

A framework for Alexa (Amazon Echo) apps using Node.js
https://www.youtube.com/watch?v=pzM4jv7k7Rg
MIT License
1.03k stars 212 forks source link

Throw warnings for exceeding known platform limitations #168

Open jlguinn opened 7 years ago

jlguinn commented 7 years ago

Not sure if this belongs here or in alexa-app-server.

I spent the last three and a half weeks discovering/troubleshooting the 24k response size limit. Could warnings be thrown in the console so developers would have some clue that the same code will fail on an Alexa device?

https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/alexa-skills-kit-interface-reference

Response Format

This section documents the format of the response that your service returns. The service for an Alexa skill must send its response in JSON format.

Note the following size limitations for the response:

If your response exceeds these limits, the Alexa service returns an error.

dblock commented 7 years ago

Definitely. I think this belongs here, appreciate a PR.

jlguinn commented 7 years ago

Thanks. Is that something I would do? I'm eager to get involved but a bit of a noob.

dblock commented 7 years ago

Give it a try! See https://github.com/alexa-js/alexa-app/blob/master/CONTRIBUTING.md.

jlguinn commented 7 years ago

I'll take a stab. I created the fork and now it looks like I have some tuts to catch up on writing tests, but this seems like a good spot for me to get started. Thanks for the link.

nickcoury commented 7 years ago

I'll add another related case. Only certain characters are allowed to be spoken within SSML responses, and if invalid characters are passed it errors the response. I've run into a number of times when pulling data from other APIs that include user input.

As a (very) rough illustration, I've been using the following RegEx/JavaScript blacklist to filter out some bad characters. It might be worth it to automatically clean the SSML code to make sure it will be valid, perhaps with a good whitelist.

It would likely be optional or a secondary function such as .validatedSay(), given there are a variety of ways to either substitute or remove the text. Would maybe be best as an add-on library even.

Example: text = (text || '').replace(/[^\w\s/<>.,-"']/gi, '').replace('&', 'and').replace('=', 'equals').replace('@', 'at');