Пример #1
0
 def test_black_list_works_verb_class_view(self):
     with override_settings(DEBUG=False):
         request = self.factory.post(
             self.verb_class_uri, {
                 'From': str(self.blocked_caller.phone_number),
                 'callsid': 'some-call-sid',
             })
         response = VerbView.as_view()(request)
         r = VoiceResponse()
         r.reject()
         self.assertEqual(
             response.content,
             str(r).encode('utf-8'),
         )
     with override_settings(DEBUG=True):
         request = self.factory.post(
             self.verb_class_uri, {
                 'From': str(self.blocked_caller.phone_number),
                 'callsid': 'some-call-sid',
             })
         response = VerbView.as_view()(request)
         r = VoiceResponse()
         r.reject()
         self.assertEqual(
             response.content,
             str(r).encode('utf-8'),
         )
Пример #2
0
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:
        # get the `From` data from the request's payload.
        # Only supporting GET and POST.
        data = request.GET if request.method == 'GET' else request.POST
        frm = data['From']
        caller = Caller.objects.get(phone_number=frm)
        if caller.blacklisted:
            twilio_request = decompose(request)
            if twilio_request.type == 'voice':
                r = VoiceResponse()
                r.reject()
            else:
                # SMS does not allow to selectively reject SMS.
                # So, we respond with nothing, and twilio does not forward
                # the message back to the sender.
                r = Message()
            return HttpResponse(str(r), content_type='application/xml')
    except Exception:
        pass

    return None
Пример #3
0
def verb_view(request):
    """
    A simple test view that returns a ``twilio.Verb`` object.
    """
    r = VoiceResponse()
    r.reject()
    return r
Пример #4
0
def twilio_voicemail(matrix_id,send_notification):
    twilio_client = util.getTwilioClient(matrix_id)
    call = twilio_client.calls(request.values["CallSid"]).fetch()
    to_number = call.to
    from_number = call.from_
    try:
        call_status = request.values["DialCallStatus"]
    except:
        call_status = request.values["CallStatus"]
    json_config = util.getIncomingNumberConfig(matrix_id, to_number)
    url = util.getAppserviceAddress().rstrip('/') + urllib.parse.urlparse(request.url).path
    response = VoiceResponse()
    if json_config["voicemail_enabled"] and call_status != "completed":
        room_id = util.findRoomId(matrix_id,[to_number] + [from_number])
        author = util.getBotMatrixId()
        if send_notification:
            util.sendMsgToRoom(room_id,author, "missed call")
        response.say(json_config["voicemail_tts"])
        kwargs = {
            "timeout":                  json_config["voicemail_timeout"], 
            "transcribe":               json_config["voicemail_transcribe"], 
            "playBeep":                 True, 
            "recordingStatusCallback":  util.adjustUrl(url,"voicemail_recording"),
            "action":                   util.adjustUrl(url,"reject"),
            "transcribeCallback":       util.adjustUrl(url,"voicemail_transcription")
        }
        response.record(**kwargs)
    else:
        response.reject()
    return str(response)
Пример #5
0
def verb_view(request):
    """
    A simple test view that returns a ``twilio.Verb`` object.
    """
    r = VoiceResponse()
    r.reject()
    return r
Пример #6
0
    def test_reject(self):
        """ should be a Reject with default reason """
        r = VoiceResponse()
        r.reject()

        assert_equal(
            self.strip(r),
            '<?xml version="1.0" encoding="UTF-8"?><Response><Reject /></Response>'
        )
Пример #7
0
def twilio_dial_number(number):
    if not "accept" in request.values.get("SpeechResult","accept").lower():
        response = VoiceResponse()
        response.reject()
        return str(response)
    response = VoiceResponse()
    dial = Dial(answerOnBridge=True)
    dial.number(number)
    response.append(dial)
    response.hangup()
    return str(response)
Пример #8
0
def call():
    numbers = ['720-938-7168', '774-232-6921', '513-675-5664', '310-502-9285']
    response = VoiceResponse()
    caller = request.values['From']
    if not validateNumber(caller):
        response.reject()
    else:
        response.say('Thank you for calling LikeWallet!  Please remain on the line and the next available representative will assist you.', voice='woman', language='en')
        dial = Dial()
        for number in numbers:
            dial.number(number)
            response.append(dial)

    return str(response)
Пример #9
0
    def voice():
        """
        Picks up phone, initiates prompt and send text to tenant
        """

        whitelisted_numbers = app.config["ALLOWED_NUMBERS"]
        caller_number = request.form.get('Caller')

        if caller_number != whitelisted_numbers:
            response = VoiceResponse()
            print("REJECTING THE CALL!!!")
            response.reject()
            return str(response)
        else:
            # Set global key for manipulation
            global TENANT_KEY

            # Reset key value and message the tenants that someone is at the gate
            TENANT_KEY = False
            send_message('Someone is at the gate. Let them in?')
            print("Message sent to tenants")

            # Start Prompt
            response = VoiceResponse()

            # TODO Remove this feature because we cannot protect the traffic between the Guest and the app
            # Using the twillio API
            gather = Gather(action='/verify',
                            finishOnKey='#',
                            input='dtmf',
                            timeout='10')

            # Setup guest input
            gather.say(
                "Greetings, If you know the code enter it now and press pound. Otherwise, wait for the gatekeepers.",
                voice='man',
                language='en-gb',
                action='/verify')

            response.append(gather)

            # Added just in case the guest decides to wait
            response.redirect('/verify')
            return str(response)
Пример #10
0
def twilio_call(matrix_id):
    twilio_client = util.getTwilioClient(matrix_id)
    direction = request.values['Direction']
    to_number = request.values['To']
    from_number = request.values['From']
    call_status = request.values["CallStatus"]
    forwarded_from = request.values.get("ForwardedFrom", None)
    json_config = util.getIncomingNumberConfig(matrix_id, to_number)
    url = util.getAppserviceAddress().rstrip('/') + urllib.parse.urlparse(request.url).path
    response = VoiceResponse()
    if direction == 'inbound':
        from_hunt_number = False
        for entry in json_config["hunt_numbers"]:
            if entry[0] == from_number or entry[0] == forwarded_from:
                from_hunt_number = True
                matching_hunt_number = entry[0]
                break

        loop_detected = False
        if from_hunt_number:
            ringing_calls = twilio_client.calls.list(status="ringing",to=matching_hunt_number,limit=2)
            queued_calls = twilio_client.calls.list(status="queued",to=matching_hunt_number,limit=2)
            for call in ringing_calls + queued_calls:
                loop_detected = True
                parent_call = twilio_client.calls(call.parent_call_sid).fetch()
                parent_call.update(url=util.adjustUrl(url,"voicemail-no-notify"))

        if json_config["hunt_enabled"] and not from_hunt_number:
            dial = Dial(action = util.adjustUrl(url,"voicemail"),timeout=json_config["hunt_timeout"],answerOnBridge=True)
            for pair in json_config["hunt_numbers"]:
                if pair[2] == "":
                    url = util.getAppserviceAddress() + "/twilio/check-accept"
                elif pair[2] == "key":
                    url = util.getAppserviceAddress() + "/twilio/check-key"
                elif pair[2] == "speech":
                    url = util.getAppserviceAddress() + "/twilio/check-speech"
                dial.number(pair[0], send_digits=pair[1], url=url)
            response.append(dial)
        elif not loop_detected:
            return twilio_voicemail(True)
        else:
            response.reject()
    return str(response)
Пример #11
0
 def test_blacklist_works(self):
     with override_settings(DEBUG=False):
         request = self.factory.post(self.str_uri, {'From': '+13333333333'})
         response = str_view(request)
         r = VoiceResponse()
         r.reject()
         self.assertEqual(
             response.content,
             str(r).encode('utf-8'),
         )
     with override_settings(DEBUG=True):
         request = self.factory.post(self.str_uri, {'From': '+13333333333'})
         response = str_view(request)
         r = VoiceResponse()
         r.reject()
         self.assertEqual(
             response.content,
             str(r).encode('utf-8'),
         )
Пример #12
0
 def test_black_list_works_verb_class_view(self):
     with override_settings(DEBUG=False):
         request = self.factory.post(self.verb_class_uri, {'From': str(self.blocked_caller.phone_number),
                                                           'callsid': 'some-call-sid', })
         response = VerbView.as_view()(request)
         r = VoiceResponse()
         r.reject()
         self.assertEqual(
             response.content,
             str(r).encode('utf-8'),
         )
     with override_settings(DEBUG=True):
         request = self.factory.post(self.verb_class_uri, {'From': str(self.blocked_caller.phone_number),
                                                           'callsid': 'some-call-sid', })
         response = VerbView.as_view()(request)
         r = VoiceResponse()
         r.reject()
         self.assertEqual(
             response.content,
             str(r).encode('utf-8'),
         )
Пример #13
0
def record():
    #Add check for spam caller here, sample code follows
    response = VoiceResponse()
    block_call = False
    phoneNumber = request.form.get('From')
    # response.say(phoneNumber)
    data = pd.read_csv('Blacklist.csv', dtype=object)
    phoneNumbers=data.Numbers.tolist()
    print(phoneNumbers)
    if phoneNumber[1:] in phoneNumbers:
                block_call = True
    if block_call:
        response.say('Hello. This Number is BlackListed.')
        response.reject()
    response.say('Hello. Please leave a message after the beep.')

    response.record()

    response.hangup()

    return str(response)
Пример #14
0
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:
        frm = request.GET['From'] if request.method == 'GET' else request.POST[
            'From']
        caller = Caller.objects.get(phone_number=frm)
        if caller.blacklisted:
            r = VoiceResponse()
            r.reject()
            return HttpResponse(str(r), content_type='application/xml')
    except Exception:
        pass

    return None
Пример #15
0
 def post(self, request):
     r = VoiceResponse()
     r.reject()
     return r
Пример #16
0
from twilio.twiml.voice_response import Reject, VoiceResponse

response = VoiceResponse()
response.reject(reason='busy')

print(response)
Пример #17
0
from twilio.twiml.voice_response import Reject, VoiceResponse

response = VoiceResponse()
response.reject()

print(response)
Пример #18
0
def twilio_reject():
    response = VoiceResponse()
    response.reject()
    return str(response)
Пример #19
0
 def post(self, request):
     r = VoiceResponse()
     r.reject()
     return r