Is there a simple way to access a memory variable inside an Autopilot Task's Say Action like
1 Answers
Twilio developer evangelist here.
You can't do that in the Autopilot JSON because the JSON is static. In order to make it "dynamic" and input a memory variable, you can do that in a Twilio Function that you point your Autopilot task at.
The JSON to point at a Twilio Function would be something like:
{
"actions": [
{
"redirect": {
"uri": "https://your-twilio-function-path.twil.io/-whatever-your-path-is"
}
}
]
}
The Twilio Function would contain JavaScript like this (you need JSON.parse
to pull out objects saved with the Remember Action which are placed at the top-level of the Memory object):
exports.handler = function(context, event, callback) {
let actions = [];
let say = {};
let memory = JSON.parse(event.Memory);
say = {
"say": `Hi ${memory.name}...`
}
actions.push(say);
let respObj = {
"actions": actions
};
callback(null, respObj);
};
Of course, alternatively, you could use
say = {
"say": "Hi " + memory.name
}
Again, because your bot needs to use data from the current conversation context in the dialogue, this is a dynamic task/dynamically-generated Action. You need a Task to respond with dynamic Actions using the Redirect Action and Twilio Functions or your own endpoint. Using the Program Task window as you call it would be a static task does not use data from the context of the current conversation with the user in its dialogue.
Let me know if this helps at all!

- 3,231
- 1
- 14
- 23
-
Thank you! The concatenation ( ... + memory.name ) works, however the inline-approach ($memory.name) does not... I have screenshots but can't add them in a comment. – imolitor Jan 06 '22 at 14:33
-
nvm... I did'nt see that one shall use `` instead of '' on strings using the inline method. Tricky one :) – imolitor Jan 06 '22 at 18:59