<commit_before>import os

from flask import Flask
from flask import request


# Flask app should start in global layout
app = Flask(__name__)


@app.route('/', methods=['GET', 'POST'])
def index():
    return 'Hi, Here is wingjay ABot'
    

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')<commit_msg>add webhook function for apiai<commit_after>import os
import json

from flask import Flask
from flask import request
from flask import make_response


# Flask app should start in global layout
app = Flask(__name__)


@app.route('/', methods=['GET', 'POST'])
def index():
    return 'Hi, Here is wingjay ABot'
    

@app.route('/webhook', methods=['GET', 'POST'])
def webhook():
	# req = request.get_json(silent=True, force=True)
	req = _mock_request_from_apiai()

	print("Request:")
	print(json.dumps(req, indent=4))

	ai_action = req.get("result").get("action")
	if ai_action:
		result = process(ai_action)
	else:
		result = {'test':1, 'test2':2}

	response = make_response(result)
	response.headers['Content-Type'] = 'application/json'
	return response


def process(action):
	print "process action"
	print action
	return action


def _mock_request_from_apiai():
	return {
    "originalRequest": None, 
    "result": {
        "fulfillment": {
            "speech": ""
        }, 
        "speech": "", 
        "source": "agent", 
        "actionIncomplete": False, 
        "resolvedQuery": "weather in London", 
        "action": "yahooWeatherForecast", 
        "score": 1.0, 
        "metadata": {
            "webhookUsed": "true", 
            "intentId": "471fd4d3-d755-40ac-bcb7-85f01c404f57", 
            "intentName": "weather"
        }, 
        "parameters": {
            "geo-city": "London"
        }, 
         "contexts": []
     	}, 
	    "timestamp": "2016-10-13T07:49:21.419Z", 
	    "sessionId": "81e229ed-d013-4b19-9ef6-7b1cdd5827d9", 
	    "id": "f9c03e3b-97b3-4d38-b2ca-d83b0598d5d2", 
	    "status": {
	        "errorType": "success", 
	        "code": 200
	    }
	}

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')
{'fraction_non_alphanumeric': 0.15539947322212466, 'fraction_numerical': 0.04433713784021071, 'mean_word_length': 2.936096718480138, 'pattern_counts': {'":': 23, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6967703', 'n_tokens_mistral': 891, 'n_tokens_neox': 790, 'n_words': 182}