Beispiel #1
0
def kannel_view():
    secret = request.args.get('secret')

    # only allow requests that contain the gateway secret
    if secret != current_app.config.get('MESSAGING_SECRET'):
        return ''

    form = KannelForm(request.args)
    if form.validate():
        msg = form.get_message()
        incoming = services.messages.log_message(
            event=g.event,
            sender=msg.get('sender'),
            text=msg.get('text'),
            direction='IN',
            timestamp=msg.get('timestamp'))

        response, submission, had_errors = parse_message(form)

        if current_app.config.get(u'TRANSLITERATE_OUTPUT'):
            response = unidecode(response)

        outgoing = services.messages.log_message(
            event=g.event,
            recipient=msg.get('sender'),
            text=response,
            direction='OUT',
            timestamp=msg.get('timestamp'))

        update_datastore(incoming, outgoing, submission, had_errors)

        return response
    return ""
Beispiel #2
0
def telerivet_view():
    secret = request.form.get('secret')

    if secret != current_app.config.get('MESSAGING_SECRET'):
        return ''

    form = TelerivetForm(request.form)
    if form.validate():
        msg = form.get_message()
        incoming = services.messages.log_message(
            event=g.event, sender=msg.get('sender'), text=msg.get('text'),
            direction='IN', timestamp=msg.get('timestamp'))

        response_text, submission, had_errors = parse_message(form)
        response = {'messages': [{'content': response_text}]}
        http_response = make_response(json.dumps(response))
        http_response.headers['Content-Type'] = 'application/json'

        outgoing = services.messages.log_message(
            event=g.event, recipient=msg.get('sender'), text=response_text,
            direction='OUT', timestamp=msg.get('timestamp'))

        update_datastore(incoming, outgoing, submission, had_errors)

        return http_response
    return ""
Beispiel #3
0
def telerivet_view():
    secret = request.form.get('secret')

    if secret != current_app.config.get('MESSAGING_SECRET'):
        return ''

    form = TelerivetForm(request.form)
    if form.validate():
        msg = form.get_message()
        incoming = services.messages.log_message(
            event=g.event,
            sender=msg.get('sender'),
            text=msg.get('text'),
            direction='IN',
            timestamp=msg.get('timestamp'))

        response_text, submission, had_errors = parse_message(form)
        response = {'messages': [{'content': response_text}]}
        http_response = make_response(json.dumps(response))
        http_response.headers['Content-Type'] = 'application/json'

        outgoing = services.messages.log_message(
            event=g.event,
            recipient=msg.get('sender'),
            text=response_text,
            direction='OUT',
            timestamp=msg.get('timestamp'))

        update_datastore(incoming, outgoing, submission, had_errors)

        return http_response
    return ""
Beispiel #4
0
def telerivet_view():
    secret = request.form.get('secret')

    if secret != current_app.config.get('MESSAGING_SECRET'):
        return ''

    # if the sender is the same as the recipient, then don't respond
    if re.sub(r'[^\d]', '', request.form.get('from_number')) == re.sub(
            r'[^\d]', '', request.form.get('to_number')):
        return ''

    form = TelerivetForm(request.form)
    if form.validate():
        msg = form.get_message()
        incoming = services.messages.log_message(
            event=g.event,
            sender=msg.get('sender'),
            text=msg.get('text'),
            direction='IN',
            timestamp=msg.get('timestamp'))

        response_text, submission, had_errors = parse_message(form)
        if current_app.config.get(u'TRANSLITERATE_OUTPUT'):
            response_text = unidecode(response_text)
        response = {'messages': [{'content': response_text}]}
        http_response = make_response(json.dumps(response))
        http_response.headers['Content-Type'] = 'application/json'

        outgoing = services.messages.log_message(
            event=g.event,
            recipient=msg.get('sender'),
            text=response_text,
            direction='OUT',
            timestamp=msg.get('timestamp'))

        update_datastore(incoming, outgoing, submission, had_errors)

        return http_response
    return ""
Beispiel #5
0
def kannel_view():
    secret = request.args.get('secret')

    # only allow requests that contain the gateway secret
    if secret != current_app.config.get('MESSAGING_SECRET'):
        return ''

    form = KannelForm(request.args)
    if form.validate():
        msg = form.get_message()
        incoming = services.messages.log_message(
            event=g.event, sender=msg.get('sender'), text=msg.get('text'),
            direction='IN', timestamp=msg.get('timestamp'))

        response, submission, had_errors = parse_message(form)

        outgoing = services.messages.log_message(
            event=g.event, recipient=msg.get('sender'), text=response,
            direction='OUT', timestamp=msg.get('timestamp'))

        update_datastore(incoming, outgoing, submission, had_errors)

        return response
    return ""