diff --git a/handlers/main.py b/handlers/main.py index b2de14d..273131d 100755 --- a/handlers/main.py +++ b/handlers/main.py @@ -25,7 +25,7 @@ from libraries.gaesessions import get_current_session -from models import accounts, phone_numbers, calls +from models import accounts, phone_numbers, calls, messages from helpers import application @@ -142,8 +142,59 @@ def get(self,Sid): @webapp_decorator.check_logged_in def post(self,Sid): - ALLOWED_PARAMETERS = ['From','Body','FromCity','FromState','FromZip','FromCounty','ToCity','ToState','ToZip','ToCounty'] - + self.data['PhoneNumber'] = phone_numbers.Phone_Number.all().filter('AccountSid = ',self.data['Account'].Sid).filter('Sid = ',Sid).get() + if self.data['PhoneNumber'] is not None: + REQUIRED = ['From','Body'] + ALLOWED_PARAMETERS = ['FromCity','FromState','FromZip','FromCounty','ToCity','ToState','ToZip','ToCounty'] + Valid = True + Any = False + Blank = False + for param in REQUIRED: + if self.request.get(param,'') == '': + Valid = False + for param in ALLOWED_PARAMETERS: + if self.request.get(param,'') != '': + Any = True + else: + Blank = True + if Any and Blank: + Valid = False + if Valid: + logging.info(self.data['PhoneNumber'].PhoneNumber) + Message, Valid, self.data['TwilioCode'],self.data['TwilioMsg'] = messages.Message.new( + To = self.data['PhoneNumber'].PhoneNumber, + From = self.request.get('From'), + Body = self.request.get('Body'), + request = self.request, + AccountSid = self.data['Account'].Sid, + Direction = 'incoming', + Status = 'sent' + ) + if Valid: + Message.put() + Payload = Message.get_dict() + #This is some really really bad bad form processing + Payload = {} + for param in ALLOWED_PARAMETERS: + Payload[param] = self.request.get(param) + #urlfetch.fetch(url,method) + self.redirect('/phone-numbers/'+self.data['PhoneNumber'].Sid) + logging.info('URL FETCHING THINGS!') + else: + logging.info('error') + logging.info(self.data['TwilioCode']) + self.data['Arguments'] = {} + for key in self.request.arguments(): + self.data['Arguments'][key] = self.request.get(key,'') + logging.info(self.data['Arguments']) + FakeSms.get(self,Sid) + else: + self.data['Arguments'] = {} + for key in self.request.argument(): + self.data['Arguments'][key] = self.request.get(key,'') + FakeSms.get(self,Sid) + else: + self.redirect('/phone-numbers') class FakeVoice(webapp.RequestHandler): """ Parameter Description diff --git a/models/messages.py b/models/messages.py index c483c8b..c58590c 100644 --- a/models/messages.py +++ b/models/messages.py @@ -19,6 +19,7 @@ class Message(base.CommonModel): Price = db.FloatProperty() StatusCallback = db.StringProperty() + """ @classmethod def new(cls, request, AccountSid, **kwargs): property_dictionary = {} @@ -40,7 +41,7 @@ def new(cls, request, AccountSid, **kwargs): ), True, 0, '' else: return '', False, TwilioCode, TwilioMsg - + """ @classmethod def new_Sid(self): return 'SM'+sha256(str(random())).hexdigest() diff --git a/templates/base.html b/templates/base.html index 93a960e..08ad14c 100644 --- a/templates/base.html +++ b/templates/base.html @@ -54,8 +54,6 @@ .error{ background:#ee9999; margin-right:20px; - } - #Additional,#Phone,#Textarea{ padding:10px; } .hide{ diff --git a/templates/fake-sms.html b/templates/fake-sms.html index 2fd9785..478dec5 100644 --- a/templates/fake-sms.html +++ b/templates/fake-sms.html @@ -15,6 +15,14 @@

Fake an Inbound SMS

Phone Number - {{data.PhoneNumber.PhoneNumber}}

{% if data.PhoneNumber.SmsUrl %} + {% if data.TwilioCode %} +

+ An error has occurred.
+ {{data.TwilioCode}}
+ {{data.TwilioMsg}} + +

+ {% endif %}

In order to submit Additional Parameters, all of them must be valid.

@@ -29,45 +37,46 @@

Phone Number - {{data.PhoneNumber.PhoneNumber}}

Sms Fallback Url: {{data.PhoneNumber.SmsFallbackUrl}} - Method: {{data.PhoneNumber.SmsFallbackMethod }}

- +

- {{data.PhoneNumber.PhoneNumber}} + {{data.PhoneNumber.PhoneNumber}}

- +

2010-04-01

Additional Parameters

- +

- +

- +

- +

- +

- +

- +

- + +

+

+

- -

{% else %} You must set a SMS Url before inbound calls can be received. @@ -85,6 +94,7 @@

Additional Parameters

phone_number.val('+1'+pn); return true; }else{ + phone_number.val('+'+pn); return false; } }