chatskills
chatskills copied to clipboard
Using non-alphanumerics in app name causes opaque errors
Hello, I'm working through your excellent book-in-progress, Building Voice-Enabled Apps with Alexa, and I encountered a strange error when working through the 'dragonhunt' skill in Chapter 2. When I went to run it with node index, I got this unhelpful error back in the terminal window:
/node_modules/chatskills/lib/chatskills.js:24
this.sessions[this.sessionId].slots[key] = value;
^
TypeError: Cannot read property 'slots' of undefined
That's JavaScript for you, right?
After digging around a bit, I discovered I had named my skill dragon_hunt, with an underscore, and this had caused the regular expression in use in ChatSkillsManager#session to fail to match the input. The regex is defined thus: new RegExp(this.id + '[,\\-\\!\\? ]+ask ([a-zA-Z0-9]+)[,\\. ](.*)', 'i').
So, is the exclusion of non-alphanumerics from skill name intentional, or just accidental? If it's intentional, or seems like a good idea, then I could submit a pull request to check skill names at the beginning of execution against that requirement and throw an error if the skill name isn't going to fly. Otherwise, I could submit a PR expanding the characters allowed in the regex and probably also checking against that, since there will be some characters we don't want in the skill name. Either way, I'd be happy to contribute to your very helpful project.
Thank you for reporting this! I really appreciate it!!
For now, I'd probably hold off on changing the regex. Maybe a warning message, if the name contains an invalid character, would be helpful?
Another item to consider is the Alexa skill Invocation Name Requirements.
For invocation names, Amazon states: "The invocation name must contain only lower-case alphabetic characters, spaces between words, possessive apostrophes, or periods used in abbreviations."
I guess this doesn't map one-for-one with the name you give your skill within the code, but it's something to consider as well. :)
The Invocation Name requirements is good information to have. I hadn't even thought about the distinction between namespace and invocation name. It's fun to dig into something relatively new, like Alexa.
I will put together a PR for screening the namespace for characters that don't match the regex. Thanks again for the library and the book.