diff --git a/appsms.py b/appsms.py new file mode 100644 index 0000000..addc0cc --- /dev/null +++ b/appsms.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +#appsms.py +import time +import configparser +from flowroutenumbersandmessaging.flowroutenumbersandmessaging_client import FlowroutenumbersandmessagingClient + +fr_api_url = "https://api.flowroute.com/v2.2/messages" + +config = configparser.ConfigParser() +config.read('config.ini') +basic_auth_user_name = config.get("flowroute","fr_access_key") +basic_auth_password = config.get("flowroute","fr_secret_key") + +client = FlowroutenumbersandmessagingClient(basic_auth_user_name, basic_auth_password) +messages_controller = client.messages + +def sendreply(reply_to, reply_from, msg): + request_body = '{ \ + "data": { "type": "message", \ + "attributes": { \ + "to": "' + str(reply_to) + '", \ + "from": "' + str(reply_from) + '", \ + "body": "' + msg + '" \ + } } }' + + result = messages_controller.send_a_message(request_body) + if result: + msg_id = result['data']['id'] + appdb.logsms_db(msg_id, '', 'outbound', reply_to, reply_from, smsRate, msg) # Lets log to our silly db. + return True + return False diff --git a/callback-sms.py b/callback-sms.py index af22a09..e2699b4 100755 --- a/callback-sms.py +++ b/callback-sms.py @@ -10,29 +10,21 @@ import sys import string import re import io -import appdb +import appdb, appsms import configparser from flask import Flask, render_template, request -from flowroutenumbersandmessaging.flowroutenumbersandmessaging_client import FlowroutenumbersandmessagingClient -smsRate = 0.0040 -fr_api_url = "https://api.flowroute.com/v2.1/messages" - - - +smsRate = 0.0040 ######################## ## Code starts here app = Flask(__name__) app.debug = True -config = configparser.ConfigParser() -config.read('config.ini') -basic_auth_user_name = config.get("flowroute","fr_access_key") -basic_auth_password = config.get("flowroute","fr_secret_key") - -client = FlowroutenumbersandmessagingClient(basic_auth_user_name, basic_auth_password) -messages_controller = client.messages +######### +# This is so bare I don't need a config right now. +#config = configparser.ConfigParser() +#config.read('config.ini') ############################# ## Callback defs go here @@ -46,29 +38,13 @@ def inboundsms(): msg_id = json_content['data']['id'] body = json_content['data']['attributes']['body'] msg_timestamp = json_content['data']['attributes']['timestamp'] - #msg_amount = re.search("\$?(\d.\d{1,5})",json_content['data']['attributes']['amount_display']) - msg_amount = 0.0040 - - appdb.logsms_db(msg_id, msg_timestamp, 'inbound', reply_from, reply_to, msg_amount, body) # Lets log to our silly db. + smsRate = json_content['data']['attributes']['amount_display'].strip('$') - sendreply(reply_to, reply_from, "Message received. Please wait for a reply.") - return "0" + appdb.logsms_db(msg_id, msg_timestamp, 'inbound', reply_from, reply_to, smsRate, body) # Lets log to our silly db. -def sendreply(reply_to, reply_from, msg): - request_body = '{ \ - "data": { "type": "message", \ - "attributes": { \ - "to": "' + str(reply_to) + '", \ - "from": "' + str(reply_from) + '", \ - "body": "' + msg + '" \ - } } }' + appsms.sendreply(reply_to, reply_from, "Message received. Please wait for a reply.") + return "0" - result = messages_controller.send_a_message(request_body) - if result: - msg_id = result['data']['id'] - appdb.logsms_db(msg_id, '', 'outbound', reply_to, reply_from, smsRate, msg) # Lets log to our silly db. - return "0" - return "-1" ################# ## Main loop