Esempio n. 1
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. 2
0
    def post(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("Illegal caller")
            return

        # setup the response to get the recording from the caller
        r = twilio.Response()

        phone = self.request.get("From")
        if paywall.isUserValid(phone) is True:
            g = r.append(
                twilio.Gather(
                    action=config.URL_BASE + "phone/listenforbus", method=twilio.Gather.GET, timeout=10, finishOnKey="#"
                )
            )
            g.append(twilio.Say("Welcome to SMS My Bus!"))
            g.append(
                twilio.Say(
                    "Enter the bus number using the keypad. Press the pound key to submit.",
                    voice=twilio.Say.MAN,
                    language=twilio.Say.ENGLISH,
                    loop=1,
                )
            )
        else:
            g = r.append(
                twilio.Say(
                    "Welcome to SMS My Bus. This service requires a subscription. Please visit us at sms my bus dot com for details"
                )
            )

        self.response.out.write(r)