示例#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(""))
示例#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

        routeID = self.request.get('Digits')
        if len(routeID) == 1:
            routeID = "0" + routeID
        memcache.add(self.request.get('AccountSid'), routeID)

        # setup the response to get the recording from the caller
        r = twilio.Response()
        g = r.append(
            twilio.Gather(action=config.URL_BASE + "phone/listenforstop",
                          method=twilio.Gather.GET,
                          timeout=5,
                          numDigits=4,
                          finishOnKey="#"))
        g.append(
            twilio.Say(
                "Enter the four digit stop number using the keypad. Press the pound key to submit.",
                voice=twilio.Say.MAN,
                language=twilio.Say.ENGLISH,
                loop=1))

        logging.debug("now asking the caller to enter their stop number...")
        self.response.out.write(r)
示例#3
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()
        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))
        self.response.out.write(r)
示例#4
0
    def gather(self,
               action_url,
               method=HTTP_METHOD_GET,
               num_digits=1,
               finish_on_key='#',
               timeout=5):
        self.last_verb = twilio_official.Gather(action_url, method, num_digits, \
         timeout, finish_on_key)
        self.twilio_response.append(self.last_verb)

        return self
示例#5
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())
示例#6
0
 def testNestedSayPlayPause(self):
     """ a gather with a say, play, and pause"""
     r = twilio.Response()
     g = twilio.Gather()
     g.append(twilio.Say("Hey"))
     g.append(twilio.Play("hey.mp3"))
     g.append(twilio.Pause())
     r.append(g)
     r = self.strip(r)
     self.assertEquals(
         r,
         '<Response><Gather><Say>Hey</Say><Play>hey.mp3</Play><Pause/></Gather></Response>'
     )
示例#7
0
def get_menu_twilml():
    response = twilio.Response()

    # typos are intentional to get Twilio to pronounce correctly
    gather = twilio.Gather(action=reverse('handle_menu_response'), )
    gather.addSay(
        """
        Press one to enter a quick config code.
        Press two to pick a group to broadcast to.
        """,
        voice=twilio.Say.MAN,
    )
    response.append(gather)
    response.addSay("I'm sorry. I did not hear a selection. Goodbye.",
                    voice=twilio.Say.MAN)
    response.addHangup()
    return response
示例#8
0
def get_config_code_twilml():
    """
    After the call is started, Twilio makes a request to this method in order
    to get the TwilML to configure the call.

    This method returns TwilML which instructs Twilio to say a message and and
    record up to one minute from the call recipient. If no audio is recorded
    before a 5 second timeout is reached, another message is played instructing
    the user to initiate another call.
    """
    response = twilio.Response()

    gather = twilio.Gather(action=reverse('handle_config_code_response'), )
    gather.addSay("Please enter your quick config code.", voice=twilio.Say.MAN)
    response.append(gather)
    response.addSay(
        "I'm sorry. I did not hear a code. Please call back. Goodbye.",
        voice=twilio.Say.MAN)
    response.addHangup()
    return response
示例#9
0
def get_group_list_twilml():
    from .contacts.models import ContactGroup
    response = twilio.Response()

    groups = ContactGroup.objects.all().order_by('order')
    groups_text = "".join(
        ["For %s, press %s. " % (g.name, g.order) for g in groups])

    gather = twilio.Gather(action=reverse('handle_group_choice_response'), )
    gather.addSay(
        """
        At any time, enter the number for the group you wish to broadcast to.
        """ + groups_text,
        voice=twilio.Say.MAN,
    )
    response.append(gather)
    response.addSay("I'm sorry. I did not hear a selection. Goodbye.",
                    voice=twilio.Say.MAN)
    response.addHangup()
    return response
示例#10
0
"""

# The same XML can be created above using the convenience methods
r = twilio.Response()
r.addSay("Hello World",
         voice=twilio.Say.MAN,
         language=twilio.Say.FRENCH,
         loop=10)
r.addDial("4155551212", timeLimit=45)
r.addPlay("http://www.mp3.com")
print r

# ===========================================================================
# Using Gather, Redirect
r = twilio.Response()
g = r.append(twilio.Gather(numDigits=1))
g.append(twilio.Say("Press 1"))
r.append(twilio.Redirect())
print r
""" outputs:
<Response>
    <Gather numDigits="1">
        <Say>Press 1</Say>
    </Gather>
    <Redirect/>
</Response>
"""

# ===========================================================================
# Adding a Say verb multiple times
r = twilio.Response()
示例#11
0
 def testAddAttribute(self):
     """add attribute"""
     r = twilio.Gather(foo="bar")
     r = self.strip(r)
     self.assertEquals(r, '<Gather foo="bar"/>')
示例#12
0
 def testEmpty(self):
     """ a gather with nothing inside"""
     r = twilio.Response()
     r.append(twilio.Gather())
     r = self.strip(r)
     self.assertEquals(r, '<Response><Gather/></Response>')