当前位置: 首页>>代码示例>>Python>>正文


Python Response.toxml方法代码示例

本文整理汇总了Python中twilio.twiml.Response.toxml方法的典型用法代码示例。如果您正苦于以下问题:Python Response.toxml方法的具体用法?Python Response.toxml怎么用?Python Response.toxml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twilio.twiml.Response的用法示例。


在下文中一共展示了Response.toxml方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_noticeboard_inbound

# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import toxml [as 别名]
    def handle_noticeboard_inbound():

        pusher_key = app.config.get('PUSHER_KEY', None)
        pusher_secret = app.config.get('PUSHER_SECRET', None)
        pusher_app_id = app.config.get('PUSHER_APP_ID', None)

        try:
            p = Pusher(pusher_app_id, pusher_key, pusher_secret)

            p['rrk_noticeboard_live'].trigger(
                'new_message',
                {
                    'image': request.values.get('MediaUrl0', None),
                    'body': request.values.get('Body', None),
                    'from': request.values.get('From', None)
                }
            )
        except:
            return '<Response />'

        to = request.values.get('To', '')
        r = Response()
        r.message(
            '''Thank you, your image has been posted
            to {0}noticeboard/live/{1}'''.format(request.url_root, to))
        return r.toxml()
开发者ID:Twilio-org,项目名称:rapid-response-kit,代码行数:28,代码来源:noticeboard.py

示例2: do_simplehelp

# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import toxml [as 别名]
    def do_simplehelp():

        data = parse_form(request.form)
        url = "{}/handle?{}".format(request.base_url, urlencode(data, True))

        r = Response()
        r.say('System is down for maintenance')
        fallback_url = echo_twimlet(r.toxml())

        try:
            client = twilio()
            client.phone_numbers.update(
                request.form['twilio_number'],
                friendly_name='[RRKit] Simple Help Line',
                voice_url=url,
                voice_method='GET',
                voice_fallback_url=fallback_url,
                voice_fallback_method='GET'
            )

            flash('Help menu configured', 'success')
        except Exception as e:
            print(e)
            flash('Error configuring help menu', 'danger')

        return redirect('/simplehelp')
开发者ID:Twilio-org,项目名称:rapid-response-kit,代码行数:28,代码来源:simplehelp.py

示例3: do_ringdown

# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import toxml [as 别名]
    def do_ringdown():
        numbers = parse_numbers(request.form.get('numbers', ''))
        data = {
            'stack': numbers,
            'sorry': request.form.get('sorry', '')
        }

        url = "{}/handle?{}".format(request.base_url, urlencode(data, True))

        r = Response()
        r.say('System is down for maintenance')
        fallback_url = echo_twimlet(r.toxml())

        try:
            client = twilio()
            client.phone_numbers.update(request.form['twilio_number'],
                                        friendly_name='[RRKit] Ringdown',
                                        voice_url=url,
                                        voice_method='GET',
                                        voice_fallback_url=fallback_url,
                                        voice_fallback_method='GET')

            flash('Number configured', 'success')
        except Exception:
            flash('Error configuring number', 'danger')

        return redirect('/ringdown')
开发者ID:Twilio-org,项目名称:rapid-response-kit,代码行数:29,代码来源:ringdown.py

示例4: setUp

# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import toxml [as 别名]
    def setUp(self):
        r = Response()
        with r.dial() as dial:
            dial.conference("TestConferenceAttributes", beep=False, waitUrl="",
                startConferenceOnEnter=True, endConferenceOnExit=True)
        xml = r.toxml()

        #parse twiml XML string with Element Tree and inspect structure
        tree = ET.fromstring(xml)
        self.conf = tree.find(".//Dial/Conference")
开发者ID:RobSpectre,项目名称:twilio-python,代码行数:12,代码来源:test_twiml.py

示例5: setUp

# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import toxml [as 别名]
    def setUp(self):
        r = Response()
        r.enqueue("TestEnqueueAttribute", action="act", method='GET',
                  waitUrl='wait', waitUrlMethod='POST')
        xml = r.toxml()

        #parse twiml XML string with Element Tree and inspect
        #structure
        tree = ET.fromstring(xml)
        self.conf = tree.find("./Enqueue")
开发者ID:beallio,项目名称:twilio-python,代码行数:12,代码来源:test_twiml.py

示例6: setUp

# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import toxml [as 别名]
    def setUp(self):
        r = Response()
        with r.enqueue(None, workflowSid="Workflow1") as e:
            e.task('{"selected_language":"en"}', priority="10", timeout="50")

        xml = r.toxml()

        # parse twiml XML string with Element Tree and inspect
        # structure
        tree = ET.fromstring(xml)
        self.enqueue = tree.find("./Enqueue")
        self.task = self.enqueue.find(".//Task")
开发者ID:Adomako-Bismark,项目名称:twilio-python,代码行数:14,代码来源:test_twiml.py

示例7: do_auto_respond

# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import toxml [as 别名]
    def do_auto_respond():
        sms_message = request.form.get('sms-message', '')
        voice_message = request.form.get('voice-message', '')

        if len(sms_message) == 0 and len(voice_message) == 0:
            flash('Please provide a message', 'danger')
            return redirect('/auto-respond')

        sms_url = ''
        voice_url = ''

        if len(sms_message) > 0:
            r = Response()
            mms_media = check_is_valid_url(request.form.get('media', ''))
            if mms_media:
                r.message(sms_message).media(mms_media)
            else:
                r.message(sms_message)
            sms_url = echo_twimlet(r.toxml())

        if len(voice_message) > 0:
            twiml = '<Response><Say>{}</Say></Response>'.format(voice_message)
            voice_url = echo_twimlet(twiml)

        try:
            client = twilio()
            client.phone_numbers.update(request.form['twilio_number'],
                                        friendly_name='[RRKit] Auto-Respond',
                                        voice_url=voice_url,
                                        voice_method='GET',
                                        sms_url=sms_url,
                                        sms_method='GET')

            flash('Auto-Respond has been configured', 'success')
        except Exception:
            flash('Error configuring number', 'danger')

        return redirect('/auto-respond')
开发者ID:Twilio-org,项目名称:rapid-response-kit,代码行数:40,代码来源:autorespond.py

示例8: sms

# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import toxml [as 别名]
def sms(request):
    resp = Response()
    from_number = request.POST["From"]
    body = request.POST["Body"]
    log_message("Got from number: " + from_number)
    try:
        user = OTTUser.objects.filter(phone_number=from_number[:10]).first()
    except:
        user = None

    try:
        body = int(body)
    except:
        body = "Sorry, I only understand numbers."

    if type(body) == int and user:
        result = Result(value=body, user=user, source=from_number)
        result.save()
        resp.message("Got response of %s for %s" % (body, user))
    elif user:
        resp.message(body)
    else:
        resp.message("Please sign up for an account at http://www.scaleofonetoten.com")
    return HttpResponse(resp.toxml(), content_type="text/xml")
开发者ID:jaredhaight,项目名称:scaleofonetoten,代码行数:26,代码来源:views.py

示例9: hello

# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import toxml [as 别名]
def hello(request):
	# if POSTed to by twilio...
	if request.method == 'POST':
		# gets body of text, else None
		identifier = request.POST.get('Body', None)
		# query = sub[0].lower() # first part is the query, lowercased to avoid those annoying issues
		number = request.POST.get('From', None) # gets the user's number

		dataset = Dataset.objects.get(number=number, identifier=identifier.lower()) # retrieves the corresponding dataset

		# twilio response
		r = Response() # makes messages object

		with r.message('Requested images:') as m:
			if dataset is not None:
				for element in dataset.elements.all():
					if element.is_media: # if it's a media URL, add it as a media tag to the response XML
						m.media(element.datum)
		
		# if query == 'hold': # hold on to a piece of data

		# elif query == 'give': # retrieve a piece of data

		# elif query == 'code':
		# 	pass
		# elif query == 'wiki': # wiki the term and return the intro
		# 	term = '%20'.join(sub[1:]) # rest of their submission put together with %20s
		# 	r.message(wiki(term))
		# else:
		# 	r.message('Invalid request')
		
		return HttpResponse(r.toxml(), content_type='text/xml')

	# if accessing the webpage via GET
	elif request.method == 'GET':
		return HttpResponse('bro why don\'t you just GET out of here.')
开发者ID:jjf32897,项目名称:sms2data,代码行数:38,代码来源:views.py

示例10: sms_write

# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import toxml [as 别名]
def sms_write(request):
	r = Response()
	r.message("Sup")
	return HttpResponse(r.toxml(), content_type='text/xml')
开发者ID:ben-cunningham,项目名称:my-personal-party-dj,代码行数:6,代码来源:views.py

示例11: sms

# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import toxml [as 别名]
def sms(request):
    print '_________________'
    print request
    print '_________________'
    messageBody = request.POST.__getitem__('Body')
    messageBody = messageBody.lower()
    print messageBody
    phone_number = request.POST.__getitem__('From')
    print phone_number
    if len(phone_number) > 11:
        phone_number = phone_number[2:]
    elif phone_number == '86753':
        arr = messageBody.split(" ")
        first_name = arr[0]
        first_name = str(first_name)
        last_name = arr[1]
        last_name = str(last_name)
        name = first_name + " " + last_name
        name = name.title()
        user = User.objects.get(name = name)
        account_sid = "[ACCOUNTSID]"
        auth_token = "[AUTHTOKEN]"
        number = "+1" + user.phone_number
        user.delete()
        client = TwilioRestClient(account_sid, auth_token)
        message = client.messages.create(to=number, from_="+MYTWILIONUMBRE", body="An Uber has been ordered by Uber by Texting")
        return HttpResponse(r.toxml(), content_type='text/xml')


    try:
        user = User.objects.get(phone_number=phone_number)
        print "user state: " + user.state
        if user.state == 'req' or True:
            if messageBody == 'uberx' or messageBody == 'uberxl' or messageBody == 'uberblack' or messageBody == 'ubersuv':
                location_gps = maps.decodeAddressToCoordinates(user.current_location)
                destination_gps = maps.decodeAddressToCoordinates(user.destination)
                times = uberCall.time(location_gps["lat"], location_gps["lng"])
                for i in times['times']:
                    temp = i['display_name']
                    temp = str(temp)
                    temp = temp.lower()
                    if temp == messageBody:
                        msg = "Your ride can arrive in " + str(i['estimate']/60) + " minutes if you pay the incoming Venmo Payment"
                        break
                price_estimates = uberCall.priceReturnDict(location_gps["lat"], location_gps["lng"], destination_gps["lat"], destination_gps["lng"])
                note = "Uber for Texting " + str(random.randint(0,9))
                payload = {"access_token": "ACCESSTOKEN", "phone": phone_number, "amount": 0.00, "note": note}
                payload["amount"] = -1 * abs(int(price_estimates[messageBody]))
                payload["amount"] = -0.01
                r = requests.post("https://api.venmo.com/v1/payments", data=payload)
                user.name = re.findall('"([^"]*)"', r.text)[26]
                print user.name
                user.state = 'pend'
                user.ride = messageBody
                user.save()
            else:
                msg = "you sent a bad input..."
            r = Response()
            r.message(msg)
            return HttpResponse(r.toxml(), content_type='text/xml')
        else:
            msg = "not req stage"
            r = Response()
            r.message(msg)
            return HttpResponse(r.toxml(), content_type='text/xml')

    except User.DoesNotExist:
        print 'user does not exist yet'
        locationIdx = messageBody.find("location:")
        destinationIdx = messageBody.find("destination:")
        if locationIdx == -1 or destinationIdx == -1:
            print 'invalid locations'
            msg = "Please send text in format: \n location: [insert location] destination: [insert destination]"
            r = Response()
            r.message(msg)
            return HttpResponse(r.toxml(), content_type='text/xml')
        location = messageBody[locationIdx + 9: destinationIdx]
        destination = messageBody[destinationIdx + 12:]
        location_gps = maps.decodeAddressToCoordinates(location)
        destination_gps = maps.decodeAddressToCoordinates(destination)
        price_estimates = uberCall.price(location_gps["lat"], location_gps["lng"], destination_gps["lat"], destination_gps["lng"])
        print "price estimate: " + price_estimates
        if len(price_estimates) > 0:
            msg = "Text back the car model of your choice:\n" + price_estimates
            u = User(phone_number=str(phone_number), state='req')
            u.current_location = location
            u.destination = destination
            u.save()
        else:
            msg = "Sorry no cars are available in your area ):"
        r = Response()
        r.message(msg)
        return HttpResponse(r.toxml(), content_type='text/xml')
开发者ID:michaelmcchen,项目名称:uberText,代码行数:95,代码来源:views.py


注:本文中的twilio.twiml.Response.toxml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。