Exemplo n.º 1
0
    def do_noticeboard():
        client = twilio()

        url = "{0}noticeboard/post".format(request.url_root)
        client.phone_numbers.update(request.form['twilio_number'],
                                    sms_url=url,
                                    sms_method='POST',
                                    friendly_name='[RRKit] Noticeboard')

        from_number = client.phone_numbers.get(request.form['twilio_number'])

        live_url = '{0}noticeboard/live/{1}'.format(request.url_root,
                                                    from_number.phone_number)
        numbers = parse_numbers(request.form['numbers'])
        body = request.form.get('message', '').replace('{URL}', live_url)
        media = check_is_valid_url(request.form.get('media', ''))

        for num in numbers:
            client.messages.create(to=num,
                                   from_=from_number.phone_number,
                                   body=body,
                                   media_url=media)
            flash('Sent {0} the message'.format(num), 'success')

        return redirect('/noticeboard')
Exemplo n.º 2
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')
Exemplo n.º 3
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')
Exemplo n.º 4
0
    def do_noticeboard():
        client = twilio()

        url = "{0}noticeboard/post".format(request.url_root)
        client.phone_numbers.update(request.form['twilio_number'],
                                    sms_url=url,
                                    sms_method='POST',
                                    friendly_name='[RRKit] Noticeboard')

        from_number = client.phone_numbers.get(request.form['twilio_number'])

        live_url = '{0}noticeboard/live/{1}'.format(
            request.url_root,
            from_number.phone_number
        )
        numbers = parse_numbers(request.form['numbers'])
        body = request.form.get('message', '').replace('{URL}', live_url)
        media = check_is_valid_url(request.form.get('media', ''))

        for num in numbers:
            client.messages.create(
                to=num,
                from_=from_number.phone_number,
                body=body,
                media_url=media
            )
            flash('Sent {0} the message'.format(num), 'success')


        return redirect('/noticeboard')
Exemplo n.º 5
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:
            r = Response()
            mms_media = check_is_valid_url(request.form.get('media', ''))
            if mms_media:
                r.message(sms_message).media(mms_media)
            else:
                r.message(sms_message)
            sms_url = echo_twimlet(r.toxml())

        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')
Exemplo n.º 6
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:
            r = Response()
            mms_media = check_is_valid_url(request.form.get('media', ''))
            if mms_media:
                r.message(sms_message).media(mms_media)
            else:
                r.message(sms_message)
            sms_url = echo_twimlet(r.toxml())

        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_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,
                                       media_url=check_is_valid_url(
                                           request.form.get('media', '')))
                flash("Sent {} the message.".format(number), 'success')
            except Exception:
                flash("Failed to send to {}".format(number), 'danger')

        return redirect('/volunteer-signup')
    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,
                    media_url=check_is_valid_url(request.form.get('media', ''))
                )
                flash("Sent {} the message.".format(number), 'success')
            except Exception:
                flash("Failed to send to {}".format(number), 'danger')

        return redirect('/volunteer-signup')