import re


def get_user_response_text(user_event):
  """
  Returns the user response text, either from a direct user text message or
  encoded in a suggested reply postback data
  in the form: '^.*reply:<non-empty user reply>$'.

  Args:
      user_event (dict): The user event as a dictionary.

  Returns:
      A :str: The user response text or None if
          the UserEvent was for something else.
  """
  response_text = None

  if 'text' in user_event:
    response_text = user_event['text']
  elif 'suggestionResponse' in user_event:
    reply_text_regex = re.compile(r'^.*reply:(.+)$')

    # Assumes reply text is encoded in suggested reply
    # in the format '^.*reply:<non-empty user reply>$'
    match = reply_text_regex.match(user_event['suggestionResponse']['postbackData'])

    if match:
      response_text = match.group(1)
  elif 'location' in user_event:  # Special case for location
    response_text = 'location'

  return response_text