Пример #1
0
def handle_transcription():
    """Notify via email"""
    from_number = request.values.get('From', None)
    to_number = request.values.get('To', None)
    voicemail = request.values.get('RecordingUrl', None)
    transcript_status = request.values.get('TranscriptionStatus', None)
    
    mail_text = u'''{} has a new voicemail from {}.

Recording: {}

'''.format(to_number, from_number, voicemail)
    
    if (transcript_status == "completed"):
        mail_text = mail_text + u"""Transcription:

{}
""".format(request.values.get('TranscriptionText', None))
    
    try:
        mailer.start()
        message = marrow.mailer.Message(author=FROM_EMAIL, to=TO_EMAIL)
        message.subject = VOICEMAIL_SUBJECT.format(from_num=from_number, to_num=to_number)
        message.plain = mail_text
        mailer.send(message)
        mailer.stop()
    except:
        e = sys.exc_info()
        print 'A mailer error occurred: %s - %s' % (e[0], e[1])
        raise
    
    resp = twilio.twiml.Response()
    resp.hangup()
    return str(resp)
Пример #2
0
def handle_text():
    """Check number validity and reject or send email"""
    if not validator.validate(request.url, request.form,
                              request.headers.get('X-Twilio-Signature', '')):
        abort(403)

    from_number = request.values.get('From', None)
    addons = request.values.get('AddOns', None)

    if pass_number(from_number, addons):
        to_number = request.values.get('To', None)
        sms_body = request.values.get('Body', None)
        mms = request.values.get('NumMedia', None)
        mail_text = u'''{} has a new text from {}.

{}

'''.format(to_number, from_number, sms_body)

        if mms:
            mms = int(mms)
            if mms > 0:
                for m in range(0, mms):
                    mc = request.values.get('MediaUrl{}'.format(m), None)
                    mail_text = mail_text + '''Media content: {}
'''.format(mc)

        try:
            mailer.start()
            message = marrow.mailer.Message(author=FROM_EMAIL, to=TO_EMAIL)
            message.subject = TEXT_SUBJECT.format(from_num=from_number,
                                                  to_num=to_number)
            message.plain = mail_text
            mailer.send(message)
            mailer.stop()
        except:
            e = sys.exc_info()
            print 'A mailer error occurred: %s - %s' % (e[0], e[1])
            raise

    resp = twilio.twiml.Response()

    if TEXT_AUTORESPONSE:
        resp.message(unicode(TEXT_AUTORESPONSE, 'utf-8'))

    return str(resp)
Пример #3
0
def handle_text():
    """Check number validity and reject or send email"""
    from_number = request.values.get('From', None)
    addons = request.values.get('AddOns', None)
        
    if pass_number(from_number, addons):
        to_number = request.values.get('To', None)
        sms_body = request.values.get('Body', None)
        mms = request.values.get('NumMedia', None)
        mail_text = u'''{} has a new text from {}.

{}

'''.format(to_number, from_number, sms_body)

        if mms:
            mms = int(mms)
            if mms > 0:
                for m in range(0, mms):
                    mc = request.values.get('MediaUrl{}'.format(m), None)
                    mail_text = mail_text + '''Media content: {}
'''.format(mc)
        
        try:
            mailer.start()
            message = marrow.mailer.Message(author=FROM_EMAIL, to=TO_EMAIL)
            message.subject = TEXT_SUBJECT.format(from_num=from_number, to_num=to_number)
            message.plain = mail_text
            mailer.send(message)
            mailer.stop()
        except:
            e = sys.exc_info()
            print 'A mailer error occurred: %s - %s' % (e[0], e[1])
            raise

    resp = twilio.twiml.Response()
    
    if TEXT_AUTORESPONSE:
        resp.message(unicode(TEXT_AUTORESPONSE, 'utf-8'))
        
    return str(resp)
Пример #4
0
def handle_transcription():
    """Notify via email"""
    if not validator.validate(request.url, request.form,
                              request.headers.get('X-Twilio-Signature', '')):
        abort(403)

    from_number = request.values.get('From', None)
    to_number = request.values.get('To', None)
    voicemail = request.values.get('RecordingUrl', None)
    transcript_status = request.values.get('TranscriptionStatus', None)

    mail_text = u'''{} has a new voicemail from {}.

Recording: {}

'''.format(to_number, from_number, voicemail)

    if (transcript_status == "completed"):
        mail_text = mail_text + u"""Transcription:

{}
""".format(request.values.get('TranscriptionText', None))

    try:
        mailer.start()
        message = marrow.mailer.Message(author=FROM_EMAIL, to=TO_EMAIL)
        message.subject = VOICEMAIL_SUBJECT.format(from_num=from_number,
                                                   to_num=to_number)
        message.plain = mail_text
        mailer.send(message)
        mailer.stop()
    except:
        e = sys.exc_info()
        print 'A mailer error occurred: %s - %s' % (e[0], e[1])
        raise

    resp = twilio.twiml.Response()
    resp.hangup()
    return str(resp)