views.py 文件源码

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

项目:text_support 作者: hackmh 项目源码 文件源码
def webhook():
    """
    Twilio will make a post request to `/webhook` everytime if receives a new
    text message. This endpoint should both record the texter in the database,
    and use Twilio to send a response. The status code will be 201 if
    successful, and have an appropriate error code if not.

    Returns:
        object: The rendered JSON response.
    """
    # pylint: disable=unused-variable

    if not request.values:
        return Response(status=400)

    phone_number = request.values.get("From")
    message_body = request.values.get("Body")

    if None in {phone_number, message_body}:
        return Response(status=400)

    Texter.record(phone_number)

    response = get_response(message_body)
    get_text_class().send_message(phone_number, response)

    return Response(status=201)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号