def post(self): message = xmpp.Message(self.request.POST) logging.info("XMPP request! Sent form %s with message %s" % (message.sender,message.body)) # normalize the XMPP requests if message.sender.find('@'): caller = message.sender.split('/')[0] else: caller = message.sender.get('from') if message.body.lower().find('parking') > -1: logging.info('parking request via XMPP') response = api_bridge.getparking() elif message.body.lower().find('help') > -1: response = "Bus arrivals: stopID -or- routeID stopID Parking: 'parking' Stats: 'stats' Help: 'help'" elif message.body.lower().find('stats') > -1: response = meta.getStats(caller) else: ## magic ## response = api_bridge.getarrivals(message.body,10) # to make it a little easier to read, add newlines before each route report line response = response.replace('Route','\nRoute') # create an event to log the request task = Task(url='/loggingtask', params={'from':caller, 'to':message.to, 'inboundBody':message.body, 'sid':'xmpp', 'outboundBody':response,}) task.add('eventlogger') # reply to the chat request message.reply(response)
def post(self): # validate it is in fact coming from twilio if config.ACCOUNT_SID != self.request.get('AccountSid'): logging.error("Inbound request was NOT VALID. It might have been spoofed!") self.response.out.write(errorResponse("Illegal caller")) return # who called? and what did they ask for? phone = self.request.get("From") msg = self.request.get("Body") logging.info("New inbound request from %s with message, %s" % (self.request.get('From'),msg)) if paywall.isUserValid(phone) is False: if paywall.isUserVirgin(phone) is True: logging.info('Brand new caller - welcome them') paywall.welcomeSolicitor(phone) else: # ignore caller logging.info('We have seen this number before. Ignore this request') return # interrogate the message body to determine what to do if msg.lower().find('parking') > -1: response = api_bridge.getparking() elif msg.lower().find('help') > -1: response = "Bus arrival requests are either, stopID -or- routeID stopID Send 'parking' to find parking details" elif msg.lower().find('stats') > -1: response = meta.getStats(phone) else: ## magic ## response = api_bridge.getarrivals(msg,4) if len(response) > 140: response = response[0:140] # create an event to log the request task = Task(url='/loggingtask', params={'from':self.request.get('From'), 'to':self.request.get('To'), 'inboundBody':self.request.get('Body'), 'sid':self.request.get('SmsSid'), 'outboundBody':response,}) task.add('eventlogger') # setup the response SMS r = twilio.Response() r.append(twilio.Sms(response)) self.response.out.write(r) return
def post(self): inbound_message = mail.InboundEmailMessage(self.request.body) logging.info("Email request! Sent from %s with message subject %s" % (inbound_message.sender,inbound_message.subject)) body = inbound_message.subject logging.debug("email body arguments %s" % body) # ignore anything sent by ourselves to avoid an infinite loop if inbound_message.sender == config.EMAIL_SENDER_ADDRESS: self.response.set_status(200) return if body.lower().find('parking') > -1: logging.info('parking request via email') response = api_bridge.getparking() else: ## magic ## response = api_bridge.getarrivals(body,10) # to make it a little easier to read, add newlines before each route report line response = response.replace('Route','\nRoute') # send back the reply with the results header = "Thanks for your request! Here are your results...\n\n" footer = "\n\nThank you for using SMSMyBus!\nhttps://www.smsmybus.com" # setup the response email message = mail.EmailMessage() message.sender = config.EMAIL_SENDER_ADDRESS #message.bcc = config.EMAIL_BCC_ADDRESS message.to = inbound_message.sender message.subject = 'Your Metro schedule estimates for stop %s' % getStopID(body) message.body = header + response + footer logging.debug('sending results to %s' % message.to) message.send() # create an event to log the event task = Task(url='/loggingtask', params={'from':inbound_message.sender, 'to':inbound_message.to, 'inboundBody':body, 'sid':'email', 'outboundBody':response,}) task.add('eventlogger') self.response.set_status(200) return
def post(self): # validate it is in fact coming from twilio if config.ACCOUNT_SID != self.request.get('AccountSid'): logging.error("Inbound request was NOT VALID. It might have been spoofed!") self.response.out.write(errorResponse("Illegal caller")) return # who called? and what did they ask for? phone = self.request.get("From") msg = self.request.get("Body") logging.info("New inbound request from %s with message, %s" % (self.request.get('From'),msg)) # look out for the abusers if filter_the_abusers(phone): # don't reply! return # interrogate the message body to determine what to do if msg.lower().find('invite') > -1: # ... an invitation request response = sendInvite(self.request) elif msg.lower().find('parking') > -1: response = api_bridge.getparking() else: ## magic ## response = api_bridge.getarrivals(msg,4) if len(response) > 140: response = response[0:140] # create an event to log the request task = Task(url='/loggingtask', params={'phone':self.request.get('From'), 'inboundBody':self.request.get('Body'), 'sid':self.request.get('SmsSid'), 'outboundBody':response,}) task.add('eventlogger') # setup the response SMS #smsBody = "Route %s, Stop %s" % (routeID, stopID) + "\n" + response r = twilio.Response() r.append(twilio.Sms(response)) self.response.out.write(r) return
def post(self): message = xmpp.Message(self.request.POST) logging.info("XMPP request! Sent form %s with message %s" % (message.sender,message.body)) if message.body.lower().find('parking') > -1: logging.info('parking request via XMPP') response = api_bridge.getparking() else: ## magic ## response = api_bridge.getarrivals(message.body,10) # to make it a little easier to read, add newlines before each route report line response = response.replace('Route','\nRoute') # create an event to log the request task = Task(url='/loggingtask', params={'phone':message.sender, 'inboundBody':message.body, 'sid':'xmpp', 'outboundBody':response,}) task.add('eventlogger') # reply to the chat request message.reply(response)