I would like to create simple skill, where the user will be able to find out where the teacher has it´s cabinet. So basically something like this: "Alexa, where can i find teacher X?" "You can find teacher X in room Y". I´ve managed to create DynamoDB table, where I have name of a teacher as primary key and room (their cabinet) as a primary sort key. It should be connected to lambda and my alexa skill correctly. All I need is to tell Alexa which teacher I am looking for, teacher names are stored in the same intent in slots, then Alexa will check DynamoDB and search under the primary key for the name of a teacher pulled from slot and then tell me the room name from the primary sort key. The code in Alexa is really troubling me. I checked every answers and tutorials I could find on the Internet but either nothing worked for me, or it was too old, so that I couldn´t transform it into 2020 style of coding Alexa. My knowledge of json and backend programming in general is really minimal. Can you give me some tips or some code i could follow? It seems to me, that something like this should be really simple, but it really isn´t, at least for me. Thank you in advance for your help.
1 Answers
If I were to approach this design ....
Pre-Requisites :
AWS account : Lambda configured with the skill endpoint trigger and registered for the skill in the Alexa Developer Console
DynamoDB table with the schema you mentioned(primaryKey : teacherName, sortKey : room) in the same AWS account.
Looks like you are planning to create a composite primary key. It has it's benefits but go through here once for core components explanation to check if you do really need it.
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html
- SQS(optional)
Some suggestions on implementation :
- Define good skill interaction model. Include AMAZON.Fallback Intent and implement that in your code. It will help in handling corner cases where you get slot values which you didn't expect or where your skill gets un-expected requests to handle. This will make sure that you always send graceful response to the customer.
- Define slots with proper slot value types.
- In code, when the lambda is triggered for your skill, after checking the canHandle method for your main functionality and validating that you have recieved request for the correct Intent - First make sure that the slot value is interpreted with good confidence ER MATCH. Here's an article for details on that :
I would advise you to create a data model to map your teacher-room data stored in DDB to your code.
This will help you in creating records programmatically in a clean way from code itself, also it defines kindof a contract for the DDB table access from your code.Post that you can create a DDB Client in your handler method which will query the data from the teacher-room table and return a response to the customer with the room number if the entry is present else, will send graceful response to the customer.
You can follow here to understand programmatic access to DDB using java(or whatever you prefer, you'll find here) :
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.Java.html
https://docs.amazonaws.cn/en_us/amazondynamodb/latest/developerguide/JavaDocumentAPICRUDExample.html
Once you get the valid data from DDB you can build and send the response to the customer with the same.
Also implement Fallback Intent in your code to handle situations you are not handling ion your custom defined intents.
(optional) You can use SQS to store erroneous events(that you catch from Fallback or are just exceptions), which you can later revisit, to debug and fix the issues in your service.
I hope this answer gives you some overview for the design and some basic practices to follow for a skill for this use-case.