Beispiel #1
0
 def testImproperNesting(self):
     """ bad nesting"""
     verb = twilio.Gather()
     self.assertRaises(twilio.TwilioException, verb.append, twilio.Gather())
     self.assertRaises(twilio.TwilioException, verb.append, twilio.Record())
     self.assertRaises(twilio.TwilioException, verb.append, twilio.Hangup())
     self.assertRaises(twilio.TwilioException, verb.append,
                       twilio.Redirect())
     self.assertRaises(twilio.TwilioException, verb.append, twilio.Dial())
     self.assertRaises(twilio.TwilioException, verb.append,
                       twilio.Conference(""))
     self.assertRaises(twilio.TwilioException, verb.append, twilio.Sms(""))
Beispiel #2
0
 def testActionMethod(self):
     """ Test the action and method parameters on Sms"""
     r = twilio.Response()
     r.append(
         twilio.Sms("Hello",
                    method="POST",
                    action="example.com?id=34&action=hey"))
     r = self.strip(r)
     self.assertEquals(
         r,
         '<Response><Sms action="example.com?id=34&amp;action=hey" method="POST">Hello</Sms></Response>'
     )
Beispiel #3
0
    def sms(self,
            msg,
            receiver_num,
            sender_num,
            method=None,
            action_url=None,
            status_callback=None):
        self.last_verb = twilio_official.Sms(msg, receiver_num, sender_num, \
         method, action_url, status_callback)
        self.twilio_response.append(self.last_verb)

        return self
Beispiel #4
0
 def improperAppend(self, verb):
     self.assertRaises(twilio.TwilioException, verb.append, twilio.Say(""))
     self.assertRaises(twilio.TwilioException, verb.append, twilio.Gather())
     self.assertRaises(twilio.TwilioException, verb.append, twilio.Play(""))
     self.assertRaises(twilio.TwilioException, verb.append, twilio.Record())
     self.assertRaises(twilio.TwilioException, verb.append, twilio.Hangup())
     self.assertRaises(twilio.TwilioException, verb.append,
                       twilio.Redirect())
     self.assertRaises(twilio.TwilioException, verb.append, twilio.Dial())
     self.assertRaises(twilio.TwilioException, verb.append,
                       twilio.Conference(""))
     self.assertRaises(twilio.TwilioException, verb.append, twilio.Sms(""))
     self.assertRaises(twilio.TwilioException, verb.append, twilio.Pause())
Beispiel #5
0
 def testToFromAction(self):
     """ Test the to, from, and status callback"""
     r = twilio.Response()
     r.append(
         twilio.Sms("Hello, World",
                    to=1231231234,
                    sender=3453453456,
                    statusCallback="example.com?id=34&action=hey"))
     r = self.strip(r)
     self.assertEquals(
         r,
         '<Response><Sms from="3453453456" statusCallback="example.com?id=34&amp;action=hey" to="1231231234">Hello, World</Sms></Response>'
     )
Beispiel #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
Beispiel #7
0
 def testBadAppend(self):
     """ should raise exceptions for wrong appending"""
     self.improperAppend(twilio.Sms("Hello"))
Beispiel #8
0
 def testBody(self):
     """Test hello world"""
     r = twilio.Response()
     r.append(twilio.Sms("Hello, World"))
     r = self.strip(r)
     self.assertEquals(r, '<Response><Sms>Hello, World</Sms></Response>')
Beispiel #9
0
 def testEmpty(self):
     """Test empty sms verb"""
     r = twilio.Response()
     r.append(twilio.Sms(""))
     r = self.strip(r)
     self.assertEquals(r, '<Response><Sms/></Response>')