Search code examples
twiliotwilio-apitwilio-programmable-chattwilio-functions

Twilio Function - Variable values


I am trying to understand how the variable values can be referenced from event.Memory in Autopilot. Here is a simple test to explain what I am trying to achieve..

From the Bot model --> using remember action to store value

"remember": {
            "userIntent": "PrjSteps"
        }

In the Twilio function --> referencing variable

const memory=event.Memory;
console.log(memory);
console.log(memory.userIntent);

2019-12-11 10:56:44 UTC {"twilio":{"chat": {"ChannelSid":"xxxxxxxxxx","AssistantName":"","Attributes":{},"ServiceSid":"xxxxxxxx","Index":0,"From":"user","MessageSid":"xxxxxxxx"}},"userIntent":"PrjSteps"}

2019-12-11 10:56:44 UTC null

I see that the variable is available in the memory, but I am unable to access the value so I can validate inside the function.

Appreciate any help in this regard,

Thank you


Solution

  • Try:

    const memory = JSON.parse(event.Memory)

    and then you should have access to the information.