|
|
@ -4,16 +4,21 @@ import requests |
|
|
|
import json |
|
|
|
import json |
|
|
|
import pprint |
|
|
|
import pprint |
|
|
|
import time |
|
|
|
import time |
|
|
|
|
|
|
|
import sqlite3 |
|
|
|
|
|
|
|
import datetime |
|
|
|
from flask import Flask, request |
|
|
|
from flask import Flask, request |
|
|
|
from flowroutenumbersandmessaging.flowroutenumbersandmessaging_client import FlowroutenumbersandmessagingClient |
|
|
|
from flowroutenumbersandmessaging.flowroutenumbersandmessaging_client import FlowroutenumbersandmessagingClient |
|
|
|
import sys |
|
|
|
import sys |
|
|
|
reload(sys) |
|
|
|
reload(sys) |
|
|
|
sys.setdefaultencoding('utf-8') |
|
|
|
sys.setdefaultencoding('utf-8') |
|
|
|
|
|
|
|
|
|
|
|
counter = 1 |
|
|
|
counter = 1 |
|
|
|
|
|
|
|
|
|
|
|
basic_auth_user_name = os.environ.get('FR_ACCESS_KEY') |
|
|
|
basic_auth_user_name = os.environ.get('FR_ACCESS_KEY') |
|
|
|
basic_auth_password = os.environ.get('FR_SECRET_KEY') |
|
|
|
basic_auth_password = os.environ.get('FR_SECRET_KEY') |
|
|
|
from_number = os.environ.get('FROM_NUMBER') |
|
|
|
from_number = os.environ.get('FROM_NUMBER') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client = FlowroutenumbersandmessagingClient(basic_auth_user_name, basic_auth_password) |
|
|
|
client = FlowroutenumbersandmessagingClient(basic_auth_user_name, basic_auth_password) |
|
|
|
messages_controller = client.messages |
|
|
|
messages_controller = client.messages |
|
|
|
|
|
|
|
|
|
|
@ -30,19 +35,19 @@ def inboundsms(): |
|
|
|
json_content = request.json |
|
|
|
json_content = request.json |
|
|
|
reply_to = json_content['data']['attributes']['from'] |
|
|
|
reply_to = json_content['data']['attributes']['from'] |
|
|
|
reply_from = json_content['data']['attributes']['to'] |
|
|
|
reply_from = json_content['data']['attributes']['to'] |
|
|
|
|
|
|
|
msg_id = json_content['data']['id'] |
|
|
|
body = json_content['data']['attributes']['body'].decode('utf-8') |
|
|
|
body = json_content['data']['attributes']['body'].decode('utf-8') |
|
|
|
|
|
|
|
|
|
|
|
pprint.pprint(body) |
|
|
|
pprint.pprint(body) |
|
|
|
if body.lower() == u'count'.lower(): |
|
|
|
if body.lower() == u'count'.lower(): |
|
|
|
sendreply(reply_to, from_number, "There have been " + str(counter) + " messages sent to this system.") |
|
|
|
sendreply(reply_to, reply_from, "There have been " + str(counter) + " messages sent to this system.") |
|
|
|
elif body.lower() == u'help'.lower(): |
|
|
|
elif body.lower() == u'help'.lower(): |
|
|
|
sendreply(reply_to, from_number, "Right now only the command 'count' works.") |
|
|
|
sendreply(reply_to, reply_from, "Right now only the command 'count' works.") |
|
|
|
else: #Echo a reply |
|
|
|
else: #Echo a reply |
|
|
|
sendreply(reply_to, from_number, "What? You should type 'help' for a list of valid commands") |
|
|
|
sendreply(reply_to, reply_from, "What? You should type 'help' for a list of valid commands") |
|
|
|
|
|
|
|
|
|
|
|
file = open("sms-logs.txt","a") |
|
|
|
logsqlite(msg_id, reply_from, reply_to, body) # Lets log to our silly db. |
|
|
|
file.write(reply_to +': ' + body + "\n") |
|
|
|
|
|
|
|
file.close() |
|
|
|
|
|
|
|
counter += 1 |
|
|
|
counter += 1 |
|
|
|
return '0' |
|
|
|
return '0' |
|
|
|
|
|
|
|
|
|
|
@ -51,6 +56,14 @@ def smscount(): |
|
|
|
print("Returning the count of " + str(counter) + ".") |
|
|
|
print("Returning the count of " + str(counter) + ".") |
|
|
|
return str(counter) |
|
|
|
return str(counter) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def logsqlite(msg_id, to_did, from_did, msg): |
|
|
|
|
|
|
|
smsdb = sqlite3.connect('sms.db') |
|
|
|
|
|
|
|
smscursor = smsdb.cursor() |
|
|
|
|
|
|
|
smscursor.execute("INSERT INTO sms VALUES (?,?,?,?,?)", (msg_id,datetime.datetime.now(),to_did, from_did, msg)) |
|
|
|
|
|
|
|
smsdb.commit() |
|
|
|
|
|
|
|
smsdb.close() |
|
|
|
|
|
|
|
return '0' |
|
|
|
|
|
|
|
|
|
|
|
def sendreply(reply_to, reply_from, msg): |
|
|
|
def sendreply(reply_to, reply_from, msg): |
|
|
|
request_body = '{ \ |
|
|
|
request_body = '{ \ |
|
|
|
"data": { \ |
|
|
|
"data": { \ |
|
|
|