diff --git a/app-ajax.py b/app-ajax.py index 3c957a7..9e4d6de 100755 --- a/app-ajax.py +++ b/app-ajax.py @@ -86,7 +86,7 @@ def submitMessage(): returndata = json.dumps({'error': 'Unable to send SMS'}) else: msgTS = time.strftime("%Y-%m-%dT%H:%m:%SZ") - appdb.logsms_db(msg_id, msgTS, 'outbound', targetDid, fromDid, 0.0040, message) + appdb.logsms_db(msg_id, msgTS, 'outbound', targetDid, fromDid, 0.0040, 'pending', message) returndata = json.dumps({"msg" : message, "fromdid" : fromDid, 'targetdid' : targetDid,}) return returndata diff --git a/appdb.py b/appdb.py index 26214b6..6e4ac5e 100755 --- a/appdb.py +++ b/appdb.py @@ -15,15 +15,12 @@ sqlpass = config.get("sql","sqlpass") sqldb = config.get("sql","sqldb") -def logsms_db(msg_id, msg_ts, direction, to_did, from_did, cost, msg): +def logsms_db(msg_id, msg_ts, direction, to_did, from_did, cost, status, msg): #This statement logs a SMS to the smslog table. db = pymysql.connect(host=sqlhost, user=sqluser, passwd=sqlpass, db=sqldb) cur = db.cursor() - if direction == 'inbound': - status = 'success' - else: - status = 'pending' - cur.execute("INSERT INTO messages (`timestamp`, `provider_timestamp`,`direction`, `source_number`, `dest_number`, `cost`,`pid`,`status, `body`)VALUES \ + + cur.execute("INSERT INTO messages (`timestamp`, `provider_timestamp`,`direction`, `source_number`, `dest_number`, `cost`,`pid`,`status`, `body`)VALUES \ (%s, %s, %s, %s, %s, %s, %s, %s, %s)",(int(time.time()),msg_ts, direction, from_did, to_did, cost, msg_id, status, msg)) db.commit() db.close() diff --git a/callback-sms.py b/callback-sms.py index ce54231..a67ea73 100755 --- a/callback-sms.py +++ b/callback-sms.py @@ -40,8 +40,9 @@ def smsinbound(): body = json_content['data']['attributes']['body'] msg_timestamp = json_content['data']['attributes']['timestamp'] smsRate = json_content['data']['attributes']['amount_display'].replace('$','') + status = 'success' - appdb.logsms_db(msg_id, msg_timestamp, 'inbound', reply_from, reply_to, smsRate, body) # Lets log to our silly db. + appdb.logsms_db(msg_id, msg_timestamp, 'inbound', reply_from, reply_to, smsRate, status, body) # Lets log to our silly db. #This command seems to make this function happen twice. # appsms.sendsms(reply_to, reply_from, "Message received. Please wait for a reply.") return "0"