old_contents: from flask import abort, Flask, request
  from functools import wraps
  from twilio import twiml
  from twilio.util import RequestValidator
  
  import os
  
  
  app = Flask(__name__)
  
  def validate_twilio_request(f):
      """Validates that incoming requests genuinely originated from Twilio"""
      @wraps(f)
      def decorated_function(*args, **kwargs):
          # Create an instance of the RequestValidator class
          validator = RequestValidator(os.environ.get('TWILIO_AUTH_TOKEN'))
  
          # Validate the request using its URL, POST data,
          # and X-TWILIO-SIGNATURE header
          request_valid = validator.validate(
              request.url,
              request.form,
              request.headers.get('X-TWILIO-SIGNATURE'))
  
          # Continue processing the request if it's valid, return a 403 error if
          # it's not
          if request_valid:
              return f(*args, **kwargs)
          else:
              return abort(403)
      return decorated_function
  
  @app.route('/voice', methods=['POST'])
  @validate_twilio_request
  def incoming_call():
      """Twilio Voice URL - receives incoming calls from Twilio"""
      # Create a new TwiML response
      resp = twiml.Response()
  
      # <Say> a message to the caller
      from_number = request.form['From']
      body = """
      Thanks for calling!
  
      Your phone number is {0}. I got your call because of Twilio's webhook.
  
      Goodbye!""".format(' '.join(from_number))
      resp.say(body)
  
      # Return the TwiML
      return str(resp)
  
  @app.route('/message', methods=['POST'])
  @validate_twilio_request
  def incoming_message():
      """Twilio Messaging URL - receives incoming messages from Twilio"""
      # Create a new TwiML response
      resp = twiml.Response()
  
      # <Message> a text back to the person who texted us
      body = "Your text to me was {0} characters long. Webhooks are neat :)" \
          .format(len(request.form['Body']))
      resp.message(body)
  
      # Return the TwiML
      return str(resp)
  
  if __name__ == '__main__':
      app.run()
  
new_contents: from flask import abort, Flask, request
  from functools import wraps
  from twilio import twiml
  from twilio.util import RequestValidator
  
  import os
  
  
  app = Flask(__name__)
  
  def validate_twilio_request(f):
      """Validates that incoming requests genuinely originated from Twilio"""
      @wraps(f)
      def decorated_function(*args, **kwargs):
          # Create an instance of the RequestValidator class
          validator = RequestValidator(os.environ.get('TWILIO_AUTH_TOKEN'))
  
          # Validate the request using its URL, POST data,
          # and X-TWILIO-SIGNATURE header
          request_valid = validator.validate(
              request.url,
              request.form,
              request.headers.get('X-TWILIO-SIGNATURE', ''))
  
          # Continue processing the request if it's valid, return a 403 error if
          # it's not
          if request_valid:
              return f(*args, **kwargs)
          else:
              return abort(403)
      return decorated_function
  
  @app.route('/voice', methods=['POST'])
  @validate_twilio_request
  def incoming_call():
      """Twilio Voice URL - receives incoming calls from Twilio"""
      # Create a new TwiML response
      resp = twiml.Response()
  
      # <Say> a message to the caller
      from_number = request.values['From']
      body = """
      Thanks for calling!
  
      Your phone number is {0}. I got your call because of Twilio's webhook.
  
      Goodbye!""".format(' '.join(from_number))
      resp.say(body)
  
      # Return the TwiML
      return str(resp)
  
  @app.route('/message', methods=['POST'])
  @validate_twilio_request
  def incoming_message():
      """Twilio Messaging URL - receives incoming messages from Twilio"""
      # Create a new TwiML response
      resp = twiml.Response()
  
      # <Message> a text back to the person who texted us
      body = "Your text to me was {0} characters long. Webhooks are neat :)" \
          .format(len(request.values['Body']))
      resp.message(body)
  
      # Return the TwiML
      return str(resp)
  
  if __name__ == '__main__':
      app.run(debug=True)
  
subject: Update to support GET and POST requests