leth=newask.Helper();// If you want to use the helper
Usage Overview
Implement FuncyAlexaSkill class.
Flesh out functions to handle requests.
Hook up the skill in the handler in index.ts.
Usage
Inherit from FuncyAlexaSkill. In ctor, map each intent to an array of transforms that will be executed in order. Be sure to initialize the launch request handler as well.
Inside each transform, check the state, most often in the _store property. Check to see if you want your transform to handle the incoming stimulus. If yes, return the next SkillState. If no (i.e. the transform doesn't apply), return null.
transformFooBar: ask.SkillTransform=(
stimulus: ask.Stimulus,
history: ask.SkillState[]
): ask.SkillState=>{// Can also use Promise<ask.SkillState>
// Check to see if this transform applies, if not return null.
if(!this._store||this._store.foo!=="bar"){
returnnull;
}
// Create your speech, mixing plain text, ssml, with ssml helpers.
// I await execute, which is not necessary WRT the callback.
// Async execute is convenient to write, and the callback
// actually is called just before the await will return.
awaitskill.execute(event,context,callback);
h.logFuncComplete(lc);
}catch(errExec){
h.logError(`errExec`,errExec,lc);
}
}
Highlights
FuncyAlexaSkill
Easier workflow for handling incoming requests without function decorators.
Plumbing is handled for you.
SpeechBuilder
Helper class that builds up OutputSpeech objects with a fluent manner.
See ssml-gib for details.
DynamoDBHelper
Simplistic, promise-based helper class that saves and retrieves a user's DynamoRecord based on user id and db table name.
Assumes that you have separately created the table in DynamoDB with the given table name.
DevOps
I also wanted to mention that you can create a nice workflow for DevOps.
With a single keystroke chord ctrl+shift+B, vscode executes the default build task, which is npm run build.
This...
Compiles the TypeScript with tsc.
Builds and copies my TS output to the bin folder.
Copies over the node_modules folder fresh.
Deletes old zip and zips up bin into new zip. (Note: You need to create the first bin.zip file manually. Need to correct the npm bash task.)
Uses aws cli to push the bin.zip to the Lambda function (which uses aliases for production so I can't harm any live skills).
I also update my models and check status via npm scripts as well,
which can get/update models and more. ctrl+~ brings up the vscode bash shell which
makes this a breeze.
I highly recommend using the npm scripts + aws and ask CLIs. (Needs updated to task version 2.0.0)
Here is the relevant code:
.vscode/tasks.json:
{
"version":"0.1.0",
"tasks":[
{
"taskName":"tsc",
"isBuildCommand":true,
"isShellCommand":true,
"command":"npm",
"args":["run","build"],
"showOutput":"silent",
"problemMatcher":"$tsc"
},
{
"taskName":"mochatest",
"isShellCommand":true,
"command":"npm",
"args":["run","test"],
"showOutput":"always"
}
]
}
package.json:
{
...
"scripts":{
"build":"npm run build:ts",
"build:ts":"tsc -p .",
"postbuild":"npm run do-node-modules && npm run zip:bin && npm run aws-push",
"zip:bin":"cd bin && pwd && rm bin.zip && zip -r bin.zip * && cd .. && pwd",