def on_receive(self): log.info("Twilio.on_receive: %s" % web.input()) log.info("self.request('To'): %s" % self.request('To')) if not sms.validate(self.request): return self.text('') message = self.request('Body') to = int(self.request('To')) # this is evidently the most elegant way to do a reverse look-up in a dictionary to_city = [k for k, v in self.phone_numbers.iteritems() if v == to][0] #log.info('to_city: %s' % to_city) if util.check_bad_words(message): log.info('Twilio: Bad word(s) in text message') return self.error('Bad word(s) in message') user = Users.get_or_create(self.db, phone=self.request('From'), location=self.request('FromZip'), city_id=to_city) if user.blocked: log.info("--> user is blocked!") return self.text('') try: mId = self.db.insert("messages", user_id=user.id, message=message, sms=1, outgoing=0) except Exception, e: log.error(e) return self.text('')
def receive(self): # TODO: could do more w/ validation if not sms.validate(self.request): return self.text('') phone = util.cleanUSPhone(self.request('From')) message = self.request('Body') userId = mUser.findUserByPhone(self.db, phone) if (not phone or not message): log.error( "*** sms received but idea not created. missing phone or message" ) else: if (message.lower() == 'stop'): return mMessaging.stopSMS(self.db, phone) else: if (mIdea.createIdea(self.db, message, -1, 'sms', userId, None, phone)): mMessaging.sendSMSConfirmation(self.db, phone) return True else: return False
def receive(self): # TODO: could do more w/ validation if not sms.validate(self.request): return self.text('') phone = util.cleanUSPhone(self.request('From')) message = self.request('Body') userId = mUser.findUserByPhone(self.db, phone) if (not phone or not message): log.error("*** sms received but idea not created. missing phone or message") else: if (message.lower() == 'stop'): return mMessaging.stopSMS(self.db, phone) else: if (mIdea.createIdea(self.db, message, -1, 'sms', userId, None, phone)): mMessaging.sendSMSConfirmation(self.db, phone) return True else: return False
def on_receive(self): log.info("Twilio.on_receive: %s" % web.input()) log.info("self.request('To'): %s" % self.request('To')) if not sms.validate(self.request): return self.text('') message = self.request('Body') to = int(self.request('To')) # this is evidently the most elegant way to do a reverse look-up in a dictionary to_city = [k for k, v in self.phone_numbers.iteritems() if v==to][0] #log.info('to_city: %s' % to_city) if util.check_bad_words(message): log.info('Twilio: Bad word(s) in text message') return self.error('Bad word(s) in message') user = Users.get_or_create(self.db, phone=self.request('From'), location=self.request('FromZip'), city_id=to_city) if user.blocked: log.info("--> user is blocked!") return self.text('') try: mId = self.db.insert("messages", user_id=user.id, message=message, sms=1, outgoing=0) except Exception, e: log.error(e) return self.text('')