{{announcement.body}}
{{announcement.title}}

Syncing Local Alexa Skills JSON Files With Alexa Developer Console Settings

DZone 's Guide to

Syncing Local Alexa Skills JSON Files With Alexa Developer Console Settings

In this article, we provide a quick fix to sync local Alexa Skill JSON Files with your Alexa developer console settings.

· Web Dev Zone ·
Free Resource

In the Alexa Skills for Node.JS ASK SDK development world, the Alexa Skills Kit (ASK) Command-Line Interface (CLI) is one of the most overlooked tools.

Boosting Developer Productivity

With proper use, one could really increase productivity when developing Alexa Skills. This is especially so if you are creating many Alexa Skills, either because you are in the learning process or you are just managing multiple Alexa Skills projects for yourself or your clients.

The fact that the ASK-CLI is overlooked is not surprising, as many beginners will start off by using the Alexa Developer Console first, where you set up the voice user interaction model and also the typical AWS Lambda based hosted skill. Moreover, the ADC even comes with an online code editor for your Lambda function,  hence there seems to be no need to use you local command line at all.

That is until you start banging your head against the wall at the limitations of the online editor. Many developers will also start to outgrow the basic hello-world and fact-skill boilerplates and want to create more complex skills with multiple files and node modules. This is when you will start going into the world of ASK-CLI.

I won't go through setting up of the ASK-CLI, as there are heaps of information out there that does this already. Like me, there will be a point in time when you are living between both worlds and switching between the Alexa Developer Console (ADC) and your local command line.

One issue that you will be facing then is that the JSON files on your local development environment will quickly get out of sync with the settings and configuration that you have in the ADC. Sometimes, it is easier to update the distribution settings, such as skill description, category, URLs, and keywords on the ADC, especially when you have multiple locales to fill up. The interaction model is also easier to create and edit using the ADC.

ASK CLI SMAPI Subcommands

This is where the ASK-CLI can come in handy. Specifically, the Skill Management API (SMAPI) subcommands.

There are two subcommands that are the most useful in my opinion, the get-interaction-model and the get-skill-manifest subcommands.

Pulling Down the Interaction Model

For example, for the get-interaction-model subcommand, which will pull down the interaction models from the ADC, you can type in the following:

Shell


You might want to also put in --profile <yourprofile> if you are switching between multiple profiles.

The above code will however just output the model onto your console. You would need to use > to save the standard output into a file like this (from the root of your project)

Shell


Skill ID

One thing you might notice above, is that the skill id is quite a long piece of information that can be easily mistyped or even copied wrongly. Moreover, to get it, most people will normally go the long way to the ADC and obtain the skill id via the "View Skill ID" link from their Alexa Skills list.

The skill id can be obtained locally. You would have to deploy your Skill for the first time before you can get this. There is a (hidden) folder called .ask under the root of the Alexa Skill project directory. Inside, there is a file called ask-states.json, where you will find the Skill id.

Please note that as of the time this article was written, ASK-CLI v2 has just been released so the above file and directory structure is related to that version of the ASK-CLI. Version 1.x of the ASK-CLI has a completely different structure and the skill id is found in a different file. Some of you, like me, might be working on those two different versions.

Obtaining the Skill ID Via a Node.js Script

To make life easier to get the Skill id from the command line between the two versions, I've obtained some outdated code originally written by Justin Jeffress on the Alexa Blogs (referenced below) and made some improvements so that it factors in both versions. The code, get-skill-id.js, can be seen below (or you can get the gist here). The code is written for Node.js, for the Mac/Linux environment.

JavaScript


The cool part about the code above is that you can be anywhere deep in the project directory structure, and it will recursively seek upwards up to find the Skill id embedded within one of the two possible config files.

As per Justin's recommendation, I also saved the file in my home directory and created an alias in my .bash_profile. 

Plain Text


Then, having the alias, I can execute the following from anywhere in the project directory structure:

Shell


Normally, I will traverse down to where the interaction model files are (for ASK-CLI v2):

Plain Text


and execute

Shell


Pulling Down the Skill Manifest

For the other subcommand, which is the get-skill-manifest subcommand, you can also do something similar. Navigate to skill-package directory from the project root and execute:

Shell


Having the Skill id obtained easily will help you benefit more from the various ASK-CLI SMAPI subcommands, as most of them would require the skill id as a parameter.

Conclusion

I hope you have found this article useful and will go further and create more script automations. Remember, if you keep on doing something over and over again and it takes a fairly long time each time you do it, there is a high chance that writing script commands and hence automating some of there repetitive tasks can shave off hours of your development efforts.

Let me know what you think and also love to hear how else you have been increasing productivity in your daily development workflow.


Stay Tuned

Stay tuned for more productivity-enhancing articles regarding voice app development. If you prefer videos, I will be releasing a few sets of videos based on my just recently inspired YouTube channel. You can also follow me on twitter @VoiceTechGuy1.

Originally Inspire Blog Post

The above article and get-skill-id.js script was inspired by a blog post written by Justin Jeffress @SleepyDeveloper at the Alexa Blogs (referenced below). It is however outdated at the time of this article being written with the introduction of ASK-CLI v2.x. I also have added the ability to check skill ids from both ASK-CLI v1 and v2 file structures.  Justin also have a Twitch channel at the time of this writing and have a biweekly live stream of progressively building an Alexa Skill (as of the time this article is written).

Topics:
alexa skill development, dev ops, node.js, tutorial, web dev

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}