application.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:apiai-smooch-docker 作者: claytantor 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号