0
votes

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
Please share some code snippets.Ankit Kante
There are currently none, since I couldn't make anything work, my already functioning skill (only simple hardcoded answers) didn't work at all, so I deleted everything that had anything to do with this problem, it's now back to simple hardcoded answers. I also looked up the possibility to create a csv/json file on S3 bucket, which I currently use for audiofiles (recorded answers in language that is not supported by Alexa). Maybe that would the way? But I have no idea how to take a string from recognized slot, search it in the file and use it as an answerAdam Benko
You will want to check out this link from DabbleLab: dabblelab.com/tutorials/using-dynamodb-with-custom-alexa-skills To build this feature, you should build it incrementally and use the Alexa-hosted Lambda. Start with being able to successfully read from static JSON (S3), then move to reading all items from your DynamoDb. Once you have that, start using Slots values to query the database. With the hosted Lambda, you will already have CloudWatch and S3 integration. When you add a console.log('some message') to your IntentHandlers, you can see the output in CloudWatch.Steven Senkus

1 Answers

0
votes

If I were to approach this design ....

Pre-Requisites :

  1. AWS account : Lambda configured with the skill endpoint trigger and registered for the skill in the Alexa Developer Console

  2. 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

  1. SQS(optional)

https://aws.amazon.com/sqs/

Some suggestions on implementation :

  1. 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.
  2. Define slots with proper slot value types.
  3. 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 :

https://developer.amazon.com/blogs/alexa/post/cfbd2f5e-c72f-4b03-8040-8628bbca204c/alexa-skill-teardown-understanding-entity-resolution-with-pet-match

  1. 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.

  2. 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.

  3. 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

  1. Once you get the valid data from DDB you can build and send the response to the customer with the same.

  2. Also implement Fallback Intent in your code to handle situations you are not handling ion your custom defined intents.

  3. (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.