Esempio n. 1
0
    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)
Esempio n. 2
0
    def get(self):

        # validate it is in fact coming from twilio
        if config.ACCOUNT_SID == self.request.get('AccountSid'):
            logging.debug(
                "PHONE request was confirmed to have come from Twilio.")
        else:
            logging.error("was NOT VALID.  It might have been spoofed!")
            self.response.out.write(errorResponse("Illegal caller"))
            return

        # pull the route and stopID out of the request body and
        # pad it with a zero on the front if the message forgot
        # to include it (that's how they are stored in the DB)
        routeID = memcache.get(self.request.get('AccountSid'))
        memcache.delete(self.request.get('AccountSid'))

        stopID = self.request.get('Digits')
        if len(stopID) == 3:
            stopID = "0" + stopID

        # hack - creating a string out of the details to conform to other interfaces
        requestArgs = "%s %s" % (routeID, stopID)

        ## magic ##
        logging.info('starting the magic... %s' % requestArgs)
        textBody = api_bridge.getarrivals(requestArgs, 1)
        logging.debug('phone results are %s' % textBody)

        # create an event to log the event
        task = Task(url='/loggingtask',
                    params={
                        'phone': self.request.get('Caller'),
                        'inboundBody': requestArgs,
                        'sid': self.request.get('SmsSid'),
                        'outboundBody': textBody,
                    })
        task.add('eventlogger')

        # transform the text a smidge so it can be pronounced more easily...
        # 1. strip the colons
        textBody = textBody.replace(':', ' ')
        # 2. add a space between p-and-m and a-and-m
        textBody = textBody.replace('pm', 'p m').replace('am', 'a m')
        logging.debug('transformed results into %s' % textBody)

        # setup the response
        r = twilio.Response()
        r.append(
            twilio.Say(textBody,
                       voice=twilio.Say.MAN,
                       language=twilio.Say.ENGLISH,
                       loop=1))

        self.response.out.write(r)
Esempio n. 3
0
    def get(self):

        # validate it is in fact coming from twilio
        if config.ACCOUNT_SID == self.request.get("AccountSid"):
            logging.debug("PHONE request was confirmed to have come from Twilio.")
        else:
            logging.error("was NOT VALID.  It might have been spoofed!")
            self.response.out.write(errorResponse("Illegal caller"))
            return

        # pull the route and stopID out of the request body and
        # pad it with a zero on the front if the message forgot
        # to include it (that's how they are stored in the DB)
        routeID = memcache.get(self.request.get("AccountSid"))
        memcache.delete(self.request.get("AccountSid"))

        stopID = self.request.get("Digits")
        if len(stopID) == 3:
            stopID = "0" + stopID

        # hack - creating a string out of the details to conform to other interfaces
        requestArgs = "%s %s" % (routeID, stopID)

        ## magic ##
        logging.info("starting the magic... %s" % requestArgs)
        textBody = api_bridge.getarrivals(requestArgs, 1)
        logging.debug("phone results are %s" % textBody)

        # create an event to log the event
        task = Task(
            url="/loggingtask",
            params={
                "from": self.request.get("Caller"),
                "to": self.request.get("Called"),
                "inboundBody": requestArgs,
                "sid": self.request.get("SmsSid"),
                "outboundBody": textBody,
            },
        )
        task.add("eventlogger")

        # transform the text a smidge so it can be pronounced more easily...
        # 1. strip the colons
        textBody = textBody.replace(":", " ")
        # 2. add a space between p-and-m and a-and-m
        textBody = textBody.replace("pm", "p m").replace("am", "a m")
        logging.debug("transformed results into %s" % textBody)

        # setup the response
        r = twilio.Response()
        r.append(twilio.Say(textBody, voice=twilio.Say.MAN, language=twilio.Say.ENGLISH, loop=1))

        self.response.out.write(r)
Esempio n. 4
0
  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
Esempio n. 5
0
    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
Esempio n. 6
0
    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)
        else:
            ## magic ##
            response = api_bridge.getarrivals(msg, 4)

        # 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
Esempio n. 7
0
    def post(self):
      message = xmpp.Message(self.request.POST)
      logging.info("XMPP request! Sent form %s with message %s" % (message.sender,message.body))

      ## 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)
Esempio n. 8
0
  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):

        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)

        ## 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!\nhttp://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={
                        'phone': inbound_message.sender,
                        'inboundBody': body,
                        'sid': 'email',
                        'outboundBody': response,
                    })
        task.add('eventlogger')

        self.response.set_status(200)
        return
Esempio n. 10
0
    def post(self):
        message = xmpp.Message(self.request.POST)
        logging.info("XMPP request! Sent form %s with message %s" %
                     (message.sender, message.body))

        ## 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)