import json
import os
import random
import sys
sys.path.append('vendored')
from algoliasearch import algoliasearch


def _getJokes(query):
    client = algoliasearch.Client(
        os.environ['ALGOLIA_APP_ID'],
        os.environ['ALGOLIA_API_KEY']
    )

    jokes = client.init_index('jokes')

    return jokes.search(query)


def norris(event, context):
    query_params = event.get('queryStringParameters') or {}
    query = query_params.get('text', '')
    results = _getJokes(query)
    item = random.choice(results['hits'])
    body = {
        'response_type': 'in_channel',
        'text': item['joke']
    }

    response = {
        'statusCode': 200,
        'body': json.dumps(body)
    }

    return response

@@ -29,16 +29,47 @@
  random%0A
+import logging%0Aimport urlparse%0A
 import s
@@ -141,16 +141,77 @@
 earch%0A%0A%0A
+logger = logging.getLogger()%0Alogger.setLevel(logging.INFO)%0A%0A%0A
 def _get
@@ -423,42 +423,70 @@
 def 
-norris(event, con
+_getQuery(event):%0A    body = event.get('body') or '
 text
-):
+='
 %0A    
-query_
 para
@@ -494,88 +494,175 @@
 s = 
-event.get('queryStringParameters') or %7B%7D%0A    query = query_params.get('text', ''
+urlparse.parse_qs(body, True)%0A    logger.info('got params%7B%7D'.format(params))%0A%0A    return params%5B'text'%5D.pop()%0A%0A%0Adef norris(event, context):%0A    query = _getQuery(event
 )%0A  

Add Logging