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)
评论列表
文章目录