text: /*
    Echo Funlet
  
    Description:
      Reply with the static TwiML provided as parameter.
      This is an alternative to TwiML Bins, which can be a starting point
      to introduce more advanced logic than the TwiML Bins can handle.
  
      This is an upgrade of the Echo Twimlet [1],
      designed to be backward-compatible with the Twimlet.
  
    Contents:
      1. Configuration
      2. Input Parameters
      3. Output Helpers
      4. Main Handler
      5. Other Exports
      6. References
  */
  
  /*
    1. Configuration
  
    Here you can change values for the input parameters,
    directly in the script.
  
    These values will be superseded by HTTP parameters and properties
    defined in the environment. You can customize the names and priorities
    of these various parameters in the next section: Input Parameters.
  */
  
  let config = {
    // Twiml instructions, as a text string
    twiml: '<Response>' + '<Say>echo</Say>' + '</Response>',
  };
  
  /*
    2. Input Parameters
  
    Each input parameter Foo is read by a separate function getFoo()
    which takes one parameter for each source:
  
      * params - object, the set of HTTP parameters
                 from the URL (GET) or the body (POST) of the query
      * env - object, the set of environment properties
              defined in the Twilio account
      * config - object, the configuration object
                 defined above in this script
  
    The HTTP parameters are considered first, then environment properties,
    then the script parameters. This can be customized in the functions below.
  */
  
  function getTwiml(params, env, config) {
    return params.Twiml || env.FUNLET_ECHO_TWIML || config.twiml;
  }
  
  /*
    3. Output Helpers
  
    These helper functions build part of the output.
  
    This is where you can fine-tune the TwiML elements and attributes
    produced in response to each stage of the Funlet.
  */
  
  /*
    Function: echo()
  
    Parameters:
      * twiml - string, input TwiML
  
    Returns:
      string, the TwiML instructions received as input, unchanged
  */
  function echo(twiml) {
    return twiml;
  }
  
  /*
    4. Main Handler
  
    This is the entry point to your Twilio Function,
    which will run to process an incoming HTTP request
    such as the ones generated by Twilio events.
  */
  
  exports.handler = function (context, event, callback) {
    const NO_ERROR = null;
  
    let response = new Twilio.Response();
    response.appendHeader('Content-Type', 'text/xml');
  
    response.setBody(echo(getTwiml(event, context, config)));
  
    callback(NO_ERROR, response);
  };
  
  /*
    5. Other Exports
  
    These internal features are exported too, for the purpose of unit tests.
  */
  
  exports.config = config;
  
  exports.input = {
    getTwiml: getTwiml,
  };
  
  exports.output = {
    echo: echo,
  };
  
  /*
    6. References
  
      [1] Echo Twimlet
      https://www.twilio.com/labs/twimlets/echo
  
      [2] Echo Funlet
      https://github.com/twilio-labs/function-templates
                                    /tree/master/funlet-echo
  
      [3] Echo Funlet: Discussion
      https://github.com/twilio-labs/function-templates/issues/18
  */
  