0

I am creating a chat bot with Twilio Autopilot, and I am trying to retrieve a variable that I save in a function from another function with Action Remember.

This is my first function:

    exports.handler = function(context, event, callback) {
        console.log(Object.keys(event));
        let memory = event.Memory;
        let respObj = {};
        console.log("Memory "+memory);
        
        let msg = "Hi, im save the name";
        respObj = {
            "actions": [
                {
                    "say": msg
                },{
                    "remember": {
                        "myname": "pau"
                  }
              } 
            ]
        };
         console.log("Memory "+memory);
        callback(null, respObj);
    };

This is my second function:

    exports.handler = function(context, event, callback) {
    
        let responseObject = {};
        let memory = JSON.parse(event.Memory);
    
        let ret = memory.myname;
        
        console.log(ret);
        
        console.log("Memory "+memory);
    
        responseObject={
            "actions":[
                {
                   "say":"your name is" + ret 
                }
            ]
            
        };
        
        callback(null, responseObject);
    };

I get an undefined of the variable, when I call this second function.

I would appreciate if someone could help me. Thank you!!! Regards.

Pau Chena
  • 11
  • 2
  • Your key:value pair is: ` "myname": "pau"` yet you are trying to pull the key `minombre`. My name is Spanish but the key is in English? – Alan Jul 06 '20 at 18:04
  • hahaha is that the code is originally in spanish. I translated it to post it here, I already edited it. Thank you!. – Pau Chena Jul 07 '20 at 05:01
  • Nothing else stands out. Can you enumerate Memory, to see what it contains or view the payload contents of the Webhook to your code? – Alan Jul 07 '20 at 11:16

0 Answers0