Hello! If you have been reading along you know that I have published an Amazon Echo Skill, but at the time I have posted this I published my third skill on the skill store. It is called Fan Muse Jobs and we will be using it as an example of how to modularize your Amazon Alexa Skill Code. Let’s get right into the main directory!
Here is what the main directory looks like:
Let’s break this down.
docs/: This is used to create a GitHub projects page for the project. We will not be going into detail about this directory here.
helpers/: This is a directory to hold all of the functions that get called within an intent function in order to complete some processing for the intent.
intents/: This is a directory to hold all of the intent functions for your skill.
.gitignore: This file was made to prevent certain auto generated files from being committed to source control
alexa-skill.js: The file that you get from Amazon when wanting to create a skill. Your
service.js uses this file.
package.json: This holds all the information about the project and its npm dependencies
Let’s go more in depth.
Here is what the
helpers/ directory looks like:
All of these files are called to complete some task that an intent needs in order to give the proper output to the user. This makes your intent function code look clean.
Here is what the
intents/ directory looks like:
Each of these files represents a function that gets executed when the user says something specific that triggers that intent. You must have at the minimum a launch, stop, cancel, and help intent in order to have a skill. The rest of the intents were specific to my skill.
alexa-skill.js and all of your intents. It contains an intent handler that knows to route a specific intent to an intent function.
In conclusion you should make sure that all of your intent functions are separated into their own files. They should be requiring modules that you created to handle what happens in the intents and those files should be in
helpers. All of your intents will then be required in the main file
I hope you enjoyed this post! Share it with your fellow developers on social media. Follow me on twitter to stay updated with my posts here. Check out my other two Amazon Alexa Skills Edit Docs and Fink-link. If you are into self-help and self growth check out my YouTube channel where I give you information on the books I read!