Beispiel #1
0
def getaroom():
    sender_no = request.values.get('msisdn')
    body = request.values.get('text')
    encoding = request.values.get('type')

    valid = True

    if sender_no is None or body is None:
        logger.error("RECEIVED INVALID MESSAGE.")
        valid = False
    else:
        if config.LOG_MESSAGES:
            mlogger.log_message(sender_no, body, mlogger.MessageDirection.INBOUND)

        if rate_limit_service.is_banned(sender_no):
            logger.warn("Number banned! - %s - %s", (body, sender_no))
            return "Number banned"


        logger.info("Received request - %s - %s" % (body, sender_no))

    if not valid:
        return "Invalid message"

    return response_service.parse_sms_main(body, sender_no, encoding)
Beispiel #2
0
def getaroom():
    sender_no = request.values.get('msisdn')
    body = request.values.get('text')
    encoding = request.values.get('type')

    valid = True

    if sender_no is None or body is None:
        logger.error("RECEIVED INVALID MESSAGE.")
        valid = False
    else:
        if config.LOG_MESSAGES:
            mlogger.log_message(sender_no, body,
                                mlogger.MessageDirection.INBOUND)

        if rate_limit_service.is_banned(sender_no):
            logger.warn("Number banned! - %s - %s", (body, sender_no))
            return "Number banned"

        logger.info("Received request - %s - %s" % (body, sender_no))

    if not valid:
        return "Invalid message"

    return response_service.parse_sms_main(body, sender_no, encoding)
Beispiel #3
0
def send_sms(number, message, msg_type = "text"):
    if config.DEBUG_SMS:
        print("SMS DEBUG:\n%s\nfrom: %s\n===========" % (message, number))
        return

    msg = {
        'reqtype': 'json',
        'api_key': config.NEXMO_API_KEY,
        'api_secret': config.NEXMO_API_SECRET,
        'from': config.NEXMO_PHONE_NO,
        'to': number,
        'text': message,
        'type': msg_type
    }
    sms = NexmoMessage(msg)
    sms.set_text_info(msg['text'])
    response = sms.send_request()
    if not response:
        logger.error("[NEXMO] Failed to send response: %s [to] %s" % (message, number))
        print "Failed to send response"

    if config.LOG_MESSAGES:
        mlogger.log_message(number, message, mlogger.MessageDirection.OUTBOUND)
Beispiel #4
0
def send_sms(number, message, msg_type="text"):
    if config.DEBUG_SMS:
        print("SMS DEBUG:\n%s\nfrom: %s\n===========" % (message, number))
        return

    msg = {
        'reqtype': 'json',
        'api_key': config.NEXMO_API_KEY,
        'api_secret': config.NEXMO_API_SECRET,
        'from': config.NEXMO_PHONE_NO,
        'to': number,
        'text': message,
        'type': msg_type
    }
    sms = NexmoMessage(msg)
    sms.set_text_info(msg['text'])
    response = sms.send_request()
    if not response:
        logger.error("[NEXMO] Failed to send response: %s [to] %s" %
                     (message, number))
        print "Failed to send response"

    if config.LOG_MESSAGES:
        mlogger.log_message(number, message, mlogger.MessageDirection.OUTBOUND)