Exemple #1
0
    def do_auto_respond():
        sms_message = request.form.get("sms-message", "")
        voice_message = request.form.get("voice-message", "")

        if len(sms_message) == 0 and len(voice_message) == 0:
            flash("Please provide a message", "danger")
            return redirect("/auto-respond")

        sms_url = ""
        voice_url = ""

        if len(sms_message) > 0:
            twiml = "<Response><Sms>{}</Sms></Response>".format(sms_message)
            sms_url = echo_twimlet(twiml)

        if len(voice_message) > 0:
            twiml = "<Response><Say>{}</Say></Response>".format(voice_message)
            voice_url = echo_twimlet(twiml)

        try:
            client = twilio()
            client.phone_numbers.update(
                request.form["twilio_number"],
                friendly_name="[RRKit] Auto-Respond",
                voice_url=voice_url,
                voice_method="GET",
                sms_url=sms_url,
                sms_method="GET",
            )

            flash("Auto-Respond has been configured", "success")
        except Exception:
            flash("Error configuring number", "danger")

        return redirect("/auto-respond")
    def do_auto_respond():
        sms_message = request.form.get('sms-message', '')
        voice_message = request.form.get('voice-message', '')

        if len(sms_message) == 0 and len(voice_message) == 0:
            flash('Please provide a message', 'danger')
            return redirect('/auto-respond')

        sms_url = ''
        voice_url = ''

        if len(sms_message) > 0:
            twiml = '<Response><Sms>{}</Sms></Response>'.format(sms_message)
            sms_url = echo_twimlet(twiml)

        if len(voice_message) > 0:
            twiml = '<Response><Say>{}</Say></Response>'.format(voice_message)
            voice_url = echo_twimlet(twiml)

        try:
            client = twilio()
            client.phone_numbers.update(request.form['twilio_number'],
                                        friendly_name='[RRKit] Auto-Respond',
                                        voice_url=voice_url,
                                        voice_method='GET',
                                        sms_url=sms_url,
                                        sms_method='GET')

            flash('Auto-Respond has been configured', 'success')
        except Exception:
            flash('Error configuring number', 'danger')

        return redirect('/auto-respond')
Exemple #3
0
    def do_auto_respond():
        sms_message = request.form.get('sms-message', '')
        voice_message = request.form.get('voice-message', '')

        if len(sms_message) == 0 and len(voice_message) == 0:
            flash('Please provide a message', 'danger')
            return redirect('/auto-respond')

        sms_url = ''
        voice_url = ''

        if len(sms_message) > 0:
            twiml = '<Response><Sms>{}</Sms></Response>'.format(sms_message)
            sms_url = echo_twimlet(twiml)

        if len(voice_message) > 0:
            twiml = '<Response><Say>{}</Say></Response>'.format(voice_message)
            voice_url = echo_twimlet(twiml)

        try:
            client = twilio()
            client.phone_numbers.update(request.form['twilio_number'],
                                        friendly_name='[RRKit] Auto-Respond',
                                        voice_url=voice_url,
                                        voice_method='GET',
                                        sms_url=sms_url,
                                        sms_method='GET')

            flash('Auto-Respond has been configured', 'success')
        except Exception:
            flash('Error configuring number', 'danger')

        return redirect('/auto-respond')
Exemple #4
0
    def do_ringdown():
        numbers = parse_numbers(request.form.get("numbers", ""))
        data = {"stack": numbers, "sorry": request.form.get("sorry", "")}

        url = "{}/handle?{}".format(request.base_url, urlencode(data, True))

        twiml = "<Response><Say>System is down for maintenance</Say></Response>"
        fallback_url = echo_twimlet(twiml)

        try:
            client = twilio()
            client.phone_numbers.update(
                request.form["twilio_number"],
                friendly_name="[RRKit] Ringdown",
                voice_url=url,
                voice_method="GET",
                voice_fallback_url=fallback_url,
                voice_fallback_method="GET",
            )

            flash("Number configured", "success")
        except Exception:
            flash("Error configuring number", "danger")

        return redirect("/ringdown")
Exemple #5
0
    def do_simplehelp():

        data = parse_form(request.form)
        url = "{}/handle?{}".format(request.base_url, urlencode(data, True))

        r = Response()
        r.say('System is down for maintenance')
        fallback_url = echo_twimlet(r.toxml())

        try:
            client = twilio()
            client.phone_numbers.update(
                request.form['twilio_number'],
                friendly_name='[RRKit] Simple Help Line',
                voice_url=url,
                voice_method='GET',
                voice_fallback_url=fallback_url,
                voice_fallback_method='GET')

            flash('Help menu configured', 'success')
        except Exception as e:
            print(e)
            flash('Error configuring help menu', 'danger')

        return redirect('/simplehelp')
    def do_ringdown():
        numbers = parse_numbers(request.form.get('numbers', ''))
        data = {
            'stack': numbers,
            'sorry': request.form.get('sorry', '')
        }

        url = "{}/handle?{}".format(request.base_url, urlencode(data, True))

        twiml = '<Response><Say>System is down for maintenance</Say></Response>'
        fallback_url = echo_twimlet(twiml)

        try:
            client = twilio()
            client.phone_numbers.update(request.form['twilio_number'],
                                        friendly_name='[RRKit] Ringdown',
                                        voice_url=url,
                                        voice_method='GET',
                                        voice_fallback_url=fallback_url,
                                        voice_fallback_method='GET')

            flash('Number configured', 'success')
        except Exception:
            flash('Error configuring number', 'danger')

        return redirect('/ringdown')
Exemple #7
0
    def do_broadcast():
        numbers = parse_numbers(request.form.get('numbers', ''))
        twiml = "<Response><Say>{}</Say></Response>"
        url = echo_twimlet(twiml.format(request.form.get('message', '')))
        media = check_is_valid_url(request.form.get('media', ''))

        client = twilio()

        for number in numbers:
            try:
                if request.form['method'] == 'sms':
                    client.messages.create(
                        to=number,
                        from_=request.form.get('twilio_number', None),
                        body=request.form.get('message', ''),
                        media_url=media,
                    )
                else:
                    client.calls.create(url=url,
                                        to=number,
                                        from_=request.form['twilio_number'])
                flash("Sent {} the message".format(number), 'success')
            except Exception:
                flash("Failed to send to {}".format(number), 'danger')

        return redirect('/broadcast')
    def do_simplehelp():

        data = parse_form(request.form)
        url = "{}/handle?{}".format(request.base_url, urlencode(data, True))

        r = Response()
        r.say('System is down for maintenance')
        fallback_url = echo_twimlet(r.toxml())

        try:
            client = twilio()
            client.phone_numbers.update(
                request.form['twilio_number'],
                friendly_name='[RRKit] Simple Help Line',
                voice_url=url,
                voice_method='GET',
                voice_fallback_url=fallback_url,
                voice_fallback_method='GET'
            )

            flash('Help menu configured', 'success')
        except Exception as e:
            print(e)
            flash('Error configuring help menu', 'danger')

        return redirect('/simplehelp')
    def do_broadcast():
        numbers = parse_numbers(request.form.get('numbers', ''))
        twiml = "<Response><Say>{}</Say></Response>"
        url = echo_twimlet(twiml.format(request.form.get('message', '')))
        media = check_is_valid_url(request.form.get('media', ''))

        client = twilio()

        for number in numbers:
            try:
                if request.form['method'] == 'sms':
                    client.messages.create(
                        to=number,
                        from_=request.form.get('twilio_number', None),
                        body=request.form.get('message', ''),
                        media_url=media,
                    )
                else:
                    client.calls.create(
                        url=url,
                        to=number,
                        from_=request.form['twilio_number']
                    )
                flash("Sent {} the message".format(number), 'success')
            except Exception:
                flash("Failed to send to {}".format(number), 'danger')

        return redirect('/broadcast')
    def do_broadcast():
        with open(os.path.join(app.root_path, app.config['NUMBERSDB']), 'r') as f:
            numbers = parse_numbers('\n'.join(json.loads(f.read())))
        twiml = "<Response><Say>{}</Say></Response>"
        url = echo_twimlet(twiml.format(request.form.get('message', '')))

        client = twilio()

        for number in numbers:
            try:
                if request.form['method'] == 'sms':
                    client.messages.create(
                        body=request.form['message'],
                        to=number,
                        from_=request.form['twilio_number']
                    )
                else:
                    client.calls.create(
                        url=url,
                        to=number,
                        from_=request.form['twilio_number']
                    )
                flash("Sent {} the message".format(number), 'success')
            except Exception:
                flash("Failed to send to {}".format(number), 'danger')

        return redirect('/broadcast')
Exemple #11
0
    def do_town_hall():
        numbers = parse_numbers(request.form.get("numbers", ""))
        twiml = "<Response><Dial><Conference>{}</Conference></Dial></Response>"
        room = request.form.get("room", "town-hall")
        url = echo_twimlet(twiml.format(room))

        client = twilio()

        for number in numbers:
            try:
                client.calls.create(url=url, to=number, from_=request.form["twilio_number"])
                flash("{} contacted to join {}".format(number, room), "success")
            except Exception:
                flash("Unable to contact {}".format(number))

        return redirect("/town-hall")
Exemple #12
0
    def do_broadcast():
        numbers = parse_numbers(request.form.get("numbers", ""))
        twiml = "<Response><Say>{}</Say></Response>"
        url = echo_twimlet(twiml.format(request.form.get("message", "")))

        client = twilio()

        for number in numbers:
            try:
                if request.form["method"] == "sms":
                    client.messages.create(body=request.form["message"], to=number, from_=request.form["twilio_number"])
                else:
                    client.calls.create(url=url, to=number, from_=request.form["twilio_number"])
                flash("Sent {} the message".format(number), "success")
            except Exception:
                flash("Failed to send to {}".format(number), "danger")

        return redirect("/broadcast")
Exemple #13
0
    def do_town_hall():
        numbers = parse_numbers(request.form.get('numbers', ''))
        twiml = '<Response><Dial><Conference>{}</Conference></Dial></Response>'
        room = request.form.get('room', 'town-hall')
        url = echo_twimlet(twiml.format(room))

        client = twilio()

        for number in numbers:
            try:
                client.calls.create(url=url,
                                    to=number,
                                    from_=request.form['twilio_number'])
                flash('{} contacted to join {}'.format(number, room),
                      'success')
            except Exception:
                flash('Unable to contact {}'.format(number))

        return redirect('/town-hall')
Exemple #14
0
    def do_forwarder():
        normalized = convert_to_e164(request.form.get("number", ""))

        if not normalized:
            flash("Phone number is invalid, please try again", "danger")
            return redirect("/forwarder")

        twiml = "<Response><Dial>{}</Dial></Response>".format(normalized)
        url = echo_twimlet(twiml)

        try:
            client = twilio()
            client.phone_numbers.update(
                request.form["twilio_number"], friendly_name="[RRKit] Forwarder", voice_url=url, voice_method="GET"
            )

            flash("Number configured", "success")
        except Exception:
            flash("Error configuring number", "danger")

        return redirect("/forwarder")
    def do_town_hall():
        numbers = parse_numbers(request.form.get('numbers', ''))
        twiml = '<Response><Dial><Conference>{}</Conference></Dial></Response>'
        room = request.form.get('room', 'town-hall')
        url = echo_twimlet(twiml.format(room))

        client = twilio()

        for number in numbers:
            try:
                client.calls.create(
                    url=url,
                    to=number,
                    from_=request.form['twilio_number']
                )
                flash(
                    '{} contacted to join {}'.format(number, room), 'success')
            except Exception:
                flash('Unable to contact {}'.format(number))

        return redirect('/town-hall')
    def do_forwarder():
        normalized = convert_to_e164(request.form.get('number', ''))

        if not normalized:
            flash('Phone number is invalid, please try again', 'danger')
            return redirect('/forwarder')

        twiml = '<Response><Dial>{}</Dial></Response>'.format(normalized)
        url = echo_twimlet(twiml)

        try:
            client = twilio()
            client.phone_numbers.update(request.form['twilio_number'],
                                        friendly_name='[RRKit] Forwarder',
                                        voice_url=url,
                                        voice_method='GET')

            flash('Number configured', 'success')
        except Exception:
            flash('Error configuring number', 'danger')

        return redirect('/forwarder')
Exemple #17
0
    def do_forwarder():
        normalized = convert_to_e164(request.form.get('number', ''))

        if not normalized:
            flash('Phone number is invalid, please try again', 'danger')
            return redirect('/forwarder')

        twiml = '<Response><Dial>{}</Dial></Response>'.format(normalized)
        url = echo_twimlet(twiml)

        try:
            client = twilio()
            client.phone_numbers.update(request.form['twilio_number'],
                                        friendly_name='[RRKit] Forwarder',
                                        voice_url=url,
                                        voice_method='GET')

            flash('Number configured', 'success')
        except Exception:
            flash('Error configuring number', 'danger')

        return redirect('/forwarder')
Exemple #18
0
    def do_ringdown():
        numbers = parse_numbers(request.form.get('numbers', ''))
        data = {'stack': numbers, 'sorry': request.form.get('sorry', '')}

        url = "{}/handle?{}".format(request.base_url, urlencode(data, True))

        twiml = '<Response><Say>System is down for maintenance</Say></Response>'
        fallback_url = echo_twimlet(twiml)

        try:
            client = twilio()
            client.phone_numbers.update(request.form['twilio_number'],
                                        friendly_name='[RRKit] Ringdown',
                                        voice_url=url,
                                        voice_method='GET',
                                        voice_fallback_url=fallback_url,
                                        voice_fallback_method='GET')

            flash('Number configured', 'success')
        except Exception:
            flash('Error configuring number', 'danger')

        return redirect('/ringdown')
Exemple #19
0
    def do_simplehelp():

        data = parse_form(request.form)
        url = "{}/handle?{}".format(request.base_url, urlencode(data, True))
        twiml = "<Response><Say>System is down for maintenance</Say></Response>"
        fallback_url = echo_twimlet(twiml)

        try:
            client = twilio()
            client.phone_numbers.update(
                request.form["twilio_number"],
                friendly_name="[RRKit] Simple Help Line",
                voice_url=url,
                voice_method="GET",
                voice_fallback_url=fallback_url,
                voice_fallback_method="GET",
            )

            flash("Help menu configured", "success")
        except Exception as e:
            print (e)
            flash("Error configuring help menu", "danger")

        return redirect("/simplehelp")
    def do_volunteer_signup():
        def create_spreadsheet():
            global google_client
            global spreadsheet_key
            (user, password) = get_google_creds(app.config)
            google_client = gdata.docs.client.DocsClient(
                source='VolunteerSignup')
            google_client.client_login(user,
                                       password,
                                       source='VolunteerSignup',
                                       service='writely')
            document = gdata.docs.data.Resource(type='spreadsheet',
                                                title=request.form.get(
                                                    'file-name', 'signup'))
            document = google_client.CreateResource(document)
            spreadsheet_key = document.GetId().split("%3A")[1]

        def update_column_names():
            global google_client
            global spreadsheet_key
            google_client = gdata.spreadsheet.service.SpreadsheetsService()
            google_client.ClientLogin(user, password)
            google_client.UpdateCell(1, 1, 'name', spreadsheet_key)
            google_client.UpdateCell(1, 2, 'phone', spreadsheet_key)
            google_client.UpdateCell(1, 3, 'response', spreadsheet_key)

        numbers = parse_numbers(request.form.get('numbers', ''))

        # Update phone number url for replys
        url = "{}/handle?{}".format(request.base_url, request.query_string)
        twiml = '<Response><Say>System is down for maintenance</Say></Response>'
        fallback_url = echo_twimlet(twiml)

        try:
            client = twilio()
            client.phone_numbers.update(
                request.form['twilio_number'],
                friendly_name='[RRKit] Volunteer Signup',
                sms_url=url,
                sms_method='POST',
                sms_fallback_url=fallback_url,
                sms_fallback_method='GET')

        except Exception as e:
            print(e)
            flash('Error configuring phone number', 'danger')

        create_spreadsheet()
        update_column_names()

        client = twilio()
        # Since the value of the form is a PN sid need to fetch the number
        global phone_number
        phoneNumber = client.phone_numbers.get(request.form['twilio_number'])
        phone_number = phoneNumber.phone_number

        for number in numbers:
            try:
                client.messages.create(body=request.form['message'],
                                       to=number,
                                       from_=phoneNumber.phone_number)
                flash("Sent {} the message.".format(number), 'success')
            except Exception:
                flash("Failed to send to {}".format(number), 'danger')

        return redirect('/volunteer-signup')
Exemple #21
0
def fallback(message='Sorry the service is down for maintenance'):
    twiml = '<Response><Say>{}</Say></Response>'.format(message)
    return echo_twimlet(twiml)
    def do_volunteer_signup():

        def create_spreadsheet():
            global google_client
            global spreadsheet_key
            (user, password) = get_google_creds(app.config)
            google_client = gdata.docs.client.DocsClient(source='VolunteerSignup')
            google_client.client_login(user, password, source='VolunteerSignup', service='writely')
            document = gdata.docs.data.Resource(type='spreadsheet', title=request.form.get('file-name', 'signup'))
            document = google_client.CreateResource(document)
            spreadsheet_key = document.GetId().split("%3A")[1]

        def update_column_names():
            global google_client
            global spreadsheet_key
            google_client = gdata.spreadsheet.service.SpreadsheetsService()
            google_client.ClientLogin(user, password)
            google_client.UpdateCell(1, 1, 'name', spreadsheet_key)
            google_client.UpdateCell(1, 2, 'phone', spreadsheet_key)
            google_client.UpdateCell(1, 3, 'response', spreadsheet_key)

        numbers = parse_numbers(request.form.get('numbers', ''))

        # Update phone number url for replys
        url = "{}/handle?{}".format(request.base_url, request.query_string)
        twiml = '<Response><Say>System is down for maintenance</Say></Response>'
        fallback_url = echo_twimlet(twiml)

        try:
            client = twilio()
            client.phone_numbers.update(request.form['twilio_number'],
                                        friendly_name='[RRKit] Volunteer Signup',
                                        sms_url=url,
                                        sms_method='POST',
                                        sms_fallback_url=fallback_url,
                                        sms_fallback_method='GET')

        except Exception as e:
            print(e)
            flash('Error configuring phone number', 'danger')

        create_spreadsheet()
        update_column_names()

        client = twilio()
        # Since the value of the form is a PN sid need to fetch the number
        global phone_number
        phoneNumber = client.phone_numbers.get(request.form['twilio_number'])
        phone_number = phoneNumber.phone_number

        for number in numbers:
            try:
                client.messages.create(
                    body=request.form['message'],
                    to=number,
                    from_= phoneNumber.phone_number
                )
                flash("Sent {} the message.".format(number), 'success')
            except Exception:
                flash("Failed to send to {}".format(number), 'danger')

        return redirect('/volunteer-signup')
Exemple #23
0
def fallback(message="Sorry the service is down for maintenance"):
    twiml = "<Response><Say>{}</Say></Response>".format(message)
    return echo_twimlet(twiml)