コード例 #1
0
ファイル: phone.py プロジェクト: HackingMadison/smsmybus-dev
    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)
コード例 #2
0
ファイル: phone.py プロジェクト: HackingMadison/smsmybus-dev
    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 testSayLoop(self):
     """should say hello monkey and loop 3 times"""
     r = twilio.Response()
     r.append(twilio.Say("Hello Monkey", loop=3))
     r = self.strip(r)
     self.assertEquals(
         r, '<Response><Say loop="3">Hello Monkey</Say></Response>')
コード例 #4
0
def index():
    response = ["<?xml version='1.0' encoding='utf-8' ?>\n"]
    r = twilio.Response()
    s = twilio.Say(
        'Hello, Thank you for calling 10 jen. 10 jen develops and provides enterprise grade support for Mongo D B.'
    )
    r.append(s)
    return r.__repr__()
コード例 #5
0
 def testSayLoopWoman(self):
     """should say have a woman say hello monkey and loop 3 times"""
     r = twilio.Response()
     r.append(twilio.Say("Hello Monkey", loop=3, voice=twilio.Say.WOMAN))
     r = self.strip(r)
     self.assertEquals(
         r,
         '<Response><Say loop="3" voice="woman">Hello Monkey</Say></Response>'
     )
コード例 #6
0
ファイル: response.py プロジェクト: neilhanyd/TwilioSimple
    def say(self,
            to_say,
            voice=VOICE_WOMAN,
            language=LANGUAGE_ENGLISH,
            loop=0):
        self.last_verb = twilio_official.Say(to_say, voice, language, loop)
        self.twilio_response.append(self.last_verb)

        return self
コード例 #7
0
ファイル: phone.py プロジェクト: HackingMadison/smsmybus-dev
    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)
コード例 #8
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())
コード例 #9
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>'
     )
コード例 #10
0
def do():
    try:
        logger.info('In do')
        config = confighelper.get_config()
        logger.info('Obtained config')
        response = ["<?xml version='1.0' encoding='utf-8' ?>\n"]
        r = twilio.Response()
        issues = mongohelper.get_issues_to_escalate(config, timedelta)
        if len(issues) > 0:
            say_msg = [
                'The following issues have been opened for at least 50 minutes'
            ]
            for issue in issues:
                say_msg.append(', ')
                say_msg.append(issue['_id'])
            s = twilio.Say(''.join(say_msg))
            mongohelper.mark_issues_as_escalated(config, issues)
        else:
            s = twilio.Say('All escalations have been taken care of')
        r.append(s)
        response.append(r.__repr__())
        return ''.join(response)
    except Exception, e:
        logger.warning(e)
コード例 #11
0
ファイル: views.py プロジェクト: jwineinger/twilcast
def handle_group_choice_response(request):
    from models import BroadcastCall
    from .contacts.models import ContactGroup
    from django.db.models import get_model

    choice = request.POST.get('Digits', '')
    group = ContactGroup.objects.filter(order=choice)

    if group:
        user = get_model('auth',
                         'User').objects.get(pk=request.COOKIES['user_id'])
        bc = BroadcastCall.objects.create(
            created_by_id=request.COOKIES['user_id'], )
        # M2M has to be set after the BC is created
        bc.contact_groups = [g for g in group]

        response = twilml.get_recording_twilml(
            reverse('recordcallback_for_broadcastcall', args=[bc.pk]))
    else:
        response = twilml.get_group_list_twilml()
        response.verbs.insert(
            0, twilio.Say("Invalid choice. ", voice=twilio.Say.MAN))
    return response
コード例 #12
0
    Redirect
    Record
    Pause
    Number
    Conference
    Sms
"""

import twilio

# ===========================================================================
# Using Say, Dial, and Play
r = twilio.Response()
r.append(
    twilio.Say("Hello World",
               voice=twilio.Say.MAN,
               language=twilio.Say.FRENCH,
               loop=10))
r.append(twilio.Dial("4155551212", timeLimit=45))
r.append(twilio.Play("http://www.mp3.com"))
print r
""" outputs:
<Response>
    <Say voice="man" language="fr" loop="10">Hello World</Say>
    <Dial timeLimit="45">4155551212</Dial>
    <Play>http://www.mp3.com</Play>
</Response>
"""

# The same XML can be created above using the convenience methods
r = twilio.Response()
r.addSay("Hello World",
コード例 #13
0
 def testSayBadAppend(self):
     """ should raise exceptions for wrong appending"""
     self.improperAppend(twilio.Say(""))
コード例 #14
0
 def testSayAddAttribute(self):
     """add attribute"""
     r = twilio.Say("", foo="bar")
     r = self.strip(r)
     self.assertEquals(r, '<Say foo="bar"/>')
コード例 #15
0
 def testSayHelloWorld(self):
     """should say hello monkey"""
     r = twilio.Response()
     r.append(twilio.Say("Hello World"))
     r = self.strip(r)
     self.assertEquals(r, "<Response><Say>Hello World</Say></Response>")
コード例 #16
0
 def testEmptySay(self):
     """should be a say with no text"""
     r = twilio.Response()
     r.append(twilio.Say(""))
     self.assertEquals(self.strip(r), "<Response><Say/></Response>")