Please excuse our look. We're just getting started here.

Want to learn more about Twilio Forums? Check out our FAQ page here.

Using a function. Is there an easy way to gather all inputs?

Also posted on twitter.

Given I have two functions and I answer a question in the first. Can I access that input from the second function?

Answers

  • How are you calling the second function? You mention on Twitter that the answers are being sent by SMS. Is that going through Studio as well?

  • dustin
    dustin
    edited October 7

    Hey @pnash, thanks for the response. I setup a two Autopilot tasks.

    To summarize: The first autopilot tasks calls, function A. Second task calls, function B. I'd like to access the custom field response I used in the first task from the second task.

    1.
    
    SMSBot: What day do you want this task to start?
    Response: Start on {first_custom_field}
    // Start on monday
    
    SMSBot: When do you want this task to end?
    Response: End on {second_custom_field}
    // End on friday 
    
    2.
    
    // Second function fires. Grab all inputs.
    
    exports.handler = async function(context, event, callback) {
      let first_custom_field = event.Field_first_custom_field_Value; // Assigned to First Task. 
      let second_custom_field = event.Field_second_custom_field_Value; // Assigned to Second Task.
    };
    

    I'm assuming there's a way to gather all "inputs" used during a session regardless if they are assigned to a task. I'm looking at Twilio.twiml.MessagingResponse() among other things.

    Any insight would be appreciated. Happy to clarify if anything doesn't make sense.

  • Ooh, you've got a couple of options here!

    First, instead of individual tasks, you could ask the two questions sequentially using the Collect action. Once the collect completes, all the answers are available in the next request.

    Alternatively, you could continue using tasks as you have so far and when you receive the response from the first one, use the Remember action to place the response into the assistant's memory. You can then access the memory in every other request for the rest of the interaction with the assistant.

If this is an emergency, please contact Twilio Support. This is not an official Support channel. https://support.twilio.com/
Have an urgent question?
Please contact Twilio Support. This is not an official Support channel.
Contact Support