Skip to content
This repository
tree: 10047a7c16
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 30 lines (22 sloc) 0.871 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
"""Useful utility functions."""


from django.http import HttpResponse
from twilio.twiml import Response

from django_twilio.models import Caller


def get_blacklisted_response(request):
    """Analyze the incoming Twilio request to determine whether or not to
reject services. We'll only reject services if the user requesting service
is on our blacklist.

:param obj request: The Django HttpRequest object to analyze.
:rtype: HttpResponse.
:returns: HttpResponse if the user requesting services is blacklisted, None
otherwise.
"""
    try:
        caller = Caller.objects.get(phone_number=request.REQUEST['From'])
        if caller.blacklisted:
            r = Response()
            r.reject()
            return HttpResponse(str(r), mimetype='application/xml')
    except (KeyError, Caller.DoesNotExist):
        pass

    return None
Something went wrong with that request. Please try again.