skill.memory

Each skill has its own memory and can remember things about the current shopper.

Use skill.memory to get the skill's memory object and set(key, value) and get(key) to save and retrieve data respectively.

Sample: Remember a shopper's color selection and pre-select it

This example will remember a shopper's most recently selected color (which we can assume is their favorite perhaps) and pre-load it into the color selection field.

var FeraSkill = function(skill) {
var $colorSelect, favoriteColor;
var init = function() {
// Locate the color selector element and load the favorite color from the skill memory.
$colorSelect = $('label:contains("Color") + select');
favoriteColor = skill.memory.get('favorite_color');
};
/**
* Recall the shopper's favorite color from the skill memory into the
* color selector and whenever the color is changed remember the new favorite
* color.
*/
this.run = function () {
recallFavoriteColor();
attachColorChangeListener();
};
/**
* Whenever someone changes their favorite color, remember it.
*/
var attachColorChangeListener = function() {
$colorSelect.on('change', function() {
saveFavoriteColor();
});
};
/**
* Load the shopper's previously remembered favorite color into the select field
* if it is available
*/
var recallFavoriteColor = function() {
if (favoriteColor) {
$colorSelect.val(favoriteColor);
}
};
/**
* Save the current shopper's favorite color to the skill memory.
*/
var saveFavoriteColor = function() {
favoriteColor = $colorSelect.val();
skill.memory.set('favorite_color', favoriteColor);
};
init();
};