Remember
The Remember action allows you to add values to an Assistant's memory. It takes key-value pairs and stores them in the memory object of the Dialogue payload to be returned in subsequent requests.
With the Remember
action, you can store key information that is persisted across intents to build rich dialogs such as shopping carts, order flows or any multi-step task.
Make sure to see how to use a Memory value in a user's response using say
.
Static example: Remember a customer's first name
{
"actions": [
{
"remember": {
"first_name": "Valentina"
}
}
]
}
The values are then stored in the Assistant's memory. All the data in the memory will be sent in the Memory
parameter as either POST parameter or URL query parameter, depending on which HTTP method you've configured.
{
"first_name": "Valentina"
}
Dynamic example: Redirect to a Twilio Function to remember different variables based on user input. This way, the Actions JSON is rendered dynamically.
{
"actions": [
{
"redirect": "https://replace-with-your-function.twil.io/dynamicremember"
}
]
}
In a Twilio Function, the following code adds new variables called "status" and "order" to your bot's memory to indicate where the conversation ended when it is handed off to an agent. Autopilot provides the current memory of the bot as a JSON object in each request it makes to your application.
exports.handler = function(context, event, callback) {
console.log(Object.keys(event));
let memory = event.Memory;
let respObj = {};
console.log("Memory "+memory);
let msg = "Thank you for providing customer information! I'm now transferring you to an agent to finish the order.";
respObj = {
"actions": [
{
"say": msg
},{
"remember": {
"status": "complete order",
"order": memory
}
}
]
};
callback(null, respObj);
};
Overwriting behavior
A given key-value pair is overwritten when it is remembered again. If a new key is provided it will be added to the map.
When executing exactly the same collect
flow twice or more times the values will be overwritten in the memory.
Need some help?
We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.