old_contents: #!/usr/bin/env python
  
  from __future__ import print_function
  from future.standard_library import install_aliases
  install_aliases()
  
  from urllib.parse import urlparse, urlencode
  from urllib.request import urlopen, Request
  from urllib.error import HTTPError
  
  import json
  import os
  
  from flask import Flask
  from flask import request
  from flask import make_response
  
  from nric import NRICValidator
  
  # Flask app should start in global layout
  app = Flask(__name__)
  
  
  @app.route('/webhook', methods=['POST'])
  def webhook():
      req = request.get_json(silent=True, force=True)
  
      print("Request:")
      print(json.dumps(req, indent=4))
  
      res = processRequest(req)
  
      res = json.dumps(res, indent=4)
      # print(res)
      r = make_response(res)
      r.headers['Content-Type'] = 'application/json'
      return r
  
  
  def processRequest(req):
      #if req.get("result").get("action") != "nricsearch":
      #    return {}
      
      result = req.get("result")
      parameters = result.get("parameters")
      nric = parameters.get("NRIC")
      check = NRICValidator.is_valid(nric)
      
      res = makeWebhookResult(check)
      return res
  
  
  def makeWebhookResult(check):
  
      if check == true:
          speech = "Safe and sound!"
      elif check == false:
          speech = "Fake NRIC?"
      else:
          speech = "what in the world"
  
      print("Response:")
      print(speech)
  
      return {
          "speech": speech,
          "displayText": speech,
          # "data": data,
          # "contextOut": [],
          "source": "nricsearch"
      }
  
  
  if __name__ == '__main__':
      port = int(os.getenv('PORT', 5000))
  
      print("Starting app on port %d" % port)
  
      app.run(debug=False, port=port, host='0.0.0.0')
  
new_contents: #!/usr/bin/env python
  
  from __future__ import print_function
  from future.standard_library import install_aliases
  install_aliases()
  
  from urllib.parse import urlparse, urlencode
  from urllib.request import urlopen, Request
  from urllib.error import HTTPError
  
  import json
  import os
  
  from flask import Flask
  from flask import request
  from flask import make_response
  
  from nric import NRICValidator
  
  # Flask app should start in global layout
  app = Flask(__name__)
  
  
  @app.route('/webhook', methods=['POST'])
  def webhook():
      req = request.get_json(silent=True, force=True)
  
      print("Request:")
      print(json.dumps(req, indent=4))
  
      res = processRequest(req)
  
      res = json.dumps(res, indent=4)
      # print(res)
      r = make_response(res)
      r.headers['Content-Type'] = 'application/json'
      return r
  
  
  def processRequest(req):
      #if req.get("result").get("action") != "nricsearch":
      #    return {}
      
      result = req.get("result")
      parameters = result.get("parameters")
      nric = parameters.get("NRIC")
      check = NRICValidator.is_valid(nric)
      
      res = makeWebhookResult(check)
      return res
  
  
  def makeWebhookResult(check):
  
      speech = check
     """ if check == true:
          speech = "Safe and sound!"
      elif check == false:
          speech = "Fake NRIC?"
      else:
          speech = "what in the world" """
  
      print("Response:")
      print(speech)
  
      return {
          "speech": speech,
          "displayText": speech,
          # "data": data,
          # "contextOut": [],
          "source": "nricsearch"
      }
  
  
  if __name__ == '__main__':
      port = int(os.getenv('PORT', 5000))
  
      print("Starting app on port %d" % port)
  
      app.run(debug=False, port=port, host='0.0.0.0')
  
subject: debug nric validator