This is an Alexa skill sample showing Persistent memory. Persistent memory is long term memory. When the user relaunches skill, after five minutes or five weeks, the skill recalls and leverages past interactions to provide a more personalized experience.
Bookmark
- Say "set a bookmark for page 123"
- Say "stop"
- Launch the skill again
- Say "what is my bookmark". The skill says, "your bookmark is page 123".
Fact
- Say "tell me a fact". You should hear a random fact
- Say "stop"
- Launch the skill again
- Say "tell me a fact". You should hear a random fact, but not a repeat one of the previous three facts.
Reset Memory
- Say "reset memory". Alexa will warn you that you are about to delete all your saved attributes.
- Say Yes. The skill will confirm and then end.
- Launch the skill again
- Say "what is my bookmark?". The skill will inform you that you do not have any bookmark saved.
This skill uses session and persistent attributes to track key data elements for the user.
Session attributes are active during the scope of one Alexa skill session. Persistent attributes must be stored and retrieved from a database, such as DynamoDB.
Request and Response interceptors handle the task of saving session attributes to persistent attributes. Each time a skill is launched, a request interceptor will load previous persistent attributes into the session attributes. When a skill is stopped (or times out), a response interceptor will save session attributes to persistent attributes.
- Create a new, empty Lambda function from scratch.
- Be sure to define Alexa Skills Kit as the trigger, and click Save
- Attach an IAM role with AmazonDynamoDBFullAccess
- Clone this repository.
- In a command prompt, navigate to the /lambda/custom folder and run
npm install --save ask-sdk - Optional: you may remove node_modules/aws-sdk to save space.
- Zip the contents of the /custom folder and upload to your Lambda function. (Hint, see the deploylambda.sh script at the root)
- Make note of the Lambda Function ARN shown near the top right.
- From the Developer Portal, create a new custom Alexa skill.
- In the Intents panel, click JSON Editor, and paste in the model found in the models/en-US.json file.
- Click SAVE and BUILD.
- In the Interfaces panel, toggle ON the Display Interface. The skill will show a welcome screen on Show/Spot devices.
- In the Endpoint tab, click AWS Lambda ARN and click into the Default Region box.
- Paste in the Lambda ARN recorded above, and click SAVE and then rebuild your skill.
- Test your skill by saying "alexa, open forget me not".