def smooch_events():
"""
the firehose of events that the webhooks subscribed to,
this will send all messages from people who visit your website
to this endmpoint, the robot then parses those messages and
does a postback of its response.
"""
# this is actually everything people say to the robot, may be good
# to send this to a log file or database
# print json.dumps(request.json)
# get the singletons
smooch_api = LocalProxy(get_smooch_api)
robot = LocalProxy(get_robot)
for message in request.json['messages']:
response = robot.query(message['text'])
if 'status' in response and response['status']['errorType'] == 'success' and 'result' in response and 'fulfillment' in response['result'] and 'speech' in response['result']['fulfillment']:
smooch_api.postback_message(response['result']['fulfillment']['speech'], message['authorId'])
data = {'message':'succeed'}
resp = Response(json.dumps(data), status=200, mimetype='application/json')
return resp
评论列表
文章目录