More modules

Moved sms sending to a module and removed it from callback-sms.py
pull/2/head
Hailey Clark 6 years ago
parent 679b593a95
commit 2a9d5fe7af
  1. 31
      appsms.py
  2. 42
      callback-sms.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

@ -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
smsRate = json_content['data']['attributes']['amount_display'].strip('$')
appdb.logsms_db(msg_id, msg_timestamp, 'inbound', reply_from, reply_to, msg_amount, body) # Lets log to our silly db.
appdb.logsms_db(msg_id, msg_timestamp, 'inbound', reply_from, reply_to, smsRate, body) # Lets log to our silly db.
sendreply(reply_to, reply_from, "Message received. Please wait for a reply.")
appsms.sendreply(reply_to, reply_from, "Message received. Please wait for a reply.")
return "0"
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 "0"
return "-1"
#################
## Main loop

Loading…
Cancel
Save