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


Python VoiceResponse.hangup方法代码示例

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


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

示例1: example

# 需要导入模块: from twilio.twiml.voice_response import VoiceResponse [as 别名]
# 或者: from twilio.twiml.voice_response.VoiceResponse import hangup [as 别名]
def example():
    """
    Some example usage of different twilio resources.
    """
    client = Client(ACCOUNT_SID, AUTH_TOKEN)

    # Get all messages
    all_messages = client.messages.list()
    print('There are {} messages in your account.'.format(len(all_messages)))

    # Get only last 10 messages...
    some_messages = client.messages.list(limit=10)
    print('Here are the last 10 messages in your account:')
    for m in some_messages:
        print(m)

    # Get messages in smaller pages...
    all_messages = client.messages.list(page_size=10)
    print('There are {} messages in your account.'.format(len(all_messages)))

    print('Sending a message...')
    new_message = client.messages.create(to='XXXX', from_='YYYY', body='Twilio rocks!')

    print('Making a call...')
    new_call = client.calls.create(to='XXXX', from_='YYYY', method='GET')

    print('Serving TwiML')
    twiml_response = VoiceResponse()
    twiml_response.say('Hello!')
    twiml_response.hangup()
    twiml_xml = twiml_response.to_xml()
    print('Generated twiml: {}'.format(twiml_xml))
开发者ID:kanyapnp,项目名称:twilio-python,代码行数:34,代码来源:basic_usage.py

示例2: call_status_update_callback

# 需要导入模块: from twilio.twiml.voice_response import VoiceResponse [as 别名]
# 或者: from twilio.twiml.voice_response.VoiceResponse import hangup [as 别名]
def call_status_update_callback(request):
    call_data = request.GET
    logger.debug(call_data['employee'])
    try:
        user = User.objects.get(pk=call_data['employee'])
    except Exception as e:
        user = User.objects.get(pk=1)
        logger.warn(e)
        Log.objects.create(type="Call Summary Error (Getting User)", 
                           message=e,
                           user=user)

    try:
        call_log = Call.objects.get(twilio_id=call_data.get('ParentCallSid', 0))
    except Exception as e:
        logger.debug(e)
        logger.debug("New Call Created")
        call_log = Call()

    call_log.twilio_id = request.GET.get(u'ParentCallSid', call_log.twilio_id)
    call_log.type = call_log.type or call_data.get('Direction', call_log.type) 
    call_log.incoming_number = call_log.incoming_number or call_data.get('From', call_log.incoming_number)
    call_log.employee = user
    call_log.save()

    resp = VoiceResponse()
    resp.hangup()
    return HttpResponse(resp)
开发者ID:charliephairoj,项目名称:backend,代码行数:30,代码来源:views.py

示例3: record

# 需要导入模块: from twilio.twiml.voice_response import VoiceResponse [as 别名]
# 或者: from twilio.twiml.voice_response.VoiceResponse import hangup [as 别名]
def record():
    """Returns TwiML which prompts the caller to record a message"""
    # Start our TwiML response
    response = VoiceResponse()

    # Use <Say> to give the caller some instructions
    response.say('Hello. Please leave a message after the beep.')

    # Use <Record> to record the caller's message
    response.record()

    # End the call with <Hangup>
    response.hangup()

    return str(response)
开发者ID:GilbertoBotaro,项目名称:api-snippets,代码行数:17,代码来源:example.6.x.py

示例4: recording_callback

# 需要导入模块: from twilio.twiml.voice_response import VoiceResponse [as 别名]
# 或者: from twilio.twiml.voice_response.VoiceResponse import hangup [as 别名]
def recording_callback(request):
    call_data = request.POST
    call_log = Call.objects.get(twilio_id=call_data.get('CallSid', 0))

    call_log.duration = call_data.get('RecordingDuration', call_log.duration)
    call_log.recording_url = call_data.get('RecordingUrl', call_log.recording_url)

    call_log.save()

    resp = VoiceResponse()
    resp.hangup()

    try:
        email_call_summary(call_log.employee.email, call_log)
    except Exception as e:
        logger.warn(e)

        try: 
            employee = call_log.employee
        except AttributeError as f:
            logger.warn(f)
            employee = User.objects.get(pk=1)
            #Error for getting user
            Log.objects.create(type="Call Summary Error (Getting user for sending email)", 
                           message=f,
                           user=employee)

        try:
            Log.objects.create(type="Call Summary Error", 
                            message=e,
                            user=employee)
        except ValueError as e:
            logger.warn(e)
            Log.objects.create(type="Call Summary Error", 
                            message=e,
                            user=User.objects.get(pk=1))
        email_call_summary('[email protected]', call_log, 'error call summary')


    return HttpResponse(resp)
开发者ID:charliephairoj,项目名称:backend,代码行数:42,代码来源:views.py

示例5: post

# 需要导入模块: from twilio.twiml.voice_response import VoiceResponse [as 别名]
# 或者: from twilio.twiml.voice_response.VoiceResponse import hangup [as 别名]
    def post(self, request, *args, **kwargs):
        from twilio.request_validator import RequestValidator
        from temba.flows.models import FlowSession

        signature = request.META.get("HTTP_X_TWILIO_SIGNATURE", "")
        url = "https://" + request.get_host() + "%s" % request.get_full_path()

        channel_uuid = kwargs.get("uuid")
        call_sid = self.get_param("CallSid")
        direction = self.get_param("Direction")
        status = self.get_param("CallStatus")
        to_number = self.get_param("To")
        to_country = self.get_param("ToCountry")
        from_number = self.get_param("From")

        # Twilio sometimes sends un-normalized numbers
        if to_number and not to_number.startswith("+") and to_country:  # pragma: no cover
            to_number, valid = URN.normalize_number(to_number, to_country)

        # see if it's a twilio call being initiated
        if to_number and call_sid and direction == "inbound" and status == "ringing":

            # find a channel that knows how to answer twilio calls
            channel = self.get_ringing_channel(uuid=channel_uuid)
            if not channel:
                response = VoiceResponse()
                response.say("Sorry, there is no channel configured to take this call. Goodbye.")
                response.hangup()
                return HttpResponse(str(response))

            org = channel.org

            if self.get_channel_type() == "T" and not org.is_connected_to_twilio():
                return HttpResponse("No Twilio account is connected", status=400)

            client = self.get_client(channel=channel)
            validator = RequestValidator(client.auth[1])
            signature = request.META.get("HTTP_X_TWILIO_SIGNATURE", "")

            url = "https://%s%s" % (request.get_host(), request.get_full_path())

            if validator.validate(url, request.POST, signature):
                from temba.ivr.models import IVRCall

                # find a contact for the one initiating us
                urn = URN.from_tel(from_number)
                contact, urn_obj = Contact.get_or_create(channel.org, urn, channel)

                flow = Trigger.find_flow_for_inbound_call(contact)

                if flow:
                    call = IVRCall.create_incoming(channel, contact, urn_obj, channel.created_by, call_sid)
                    session = FlowSession.create(contact, connection=call)

                    call.update_status(
                        request.POST.get("CallStatus", None), request.POST.get("CallDuration", None), "T"
                    )
                    call.save()

                    FlowRun.create(flow, contact, session=session, connection=call)
                    response = Flow.handle_call(call)
                    return HttpResponse(str(response))

                else:

                    # we don't have an inbound trigger to deal with this call.
                    response = channel.generate_ivr_response()

                    # say nothing and hangup, this is a little rude, but if we reject the call, then
                    # they'll get a non-working number error. We send 'busy' when our server is down
                    # so we don't want to use that here either.
                    response.say("")
                    response.hangup()

                    # if they have a missed call trigger, fire that off
                    Trigger.catch_triggers(contact, Trigger.TYPE_MISSED_CALL, channel)

                    # either way, we need to hangup now
                    return HttpResponse(str(response))

        # check for call progress events, these include post-call hangup notifications
        if request.POST.get("CallbackSource", None) == "call-progress-events":
            if call_sid:
                from temba.ivr.models import IVRCall

                call = IVRCall.objects.filter(external_id=call_sid).first()
                if call:
                    call.update_status(
                        request.POST.get("CallStatus", None), request.POST.get("CallDuration", None), "TW"
                    )
                    call.save()
                    return HttpResponse("Call status updated")
            return HttpResponse("No call found")

        return HttpResponse("Not Handled, unknown action", status=400)  # pragma: no cover
开发者ID:teehamaral,项目名称:rapidpro,代码行数:97,代码来源:handlers.py

示例6: VoiceResponse

# 需要导入模块: from twilio.twiml.voice_response import VoiceResponse [as 别名]
# 或者: from twilio.twiml.voice_response.VoiceResponse import hangup [as 别名]
from twilio.twiml.voice_response import Hangup, VoiceResponse

response = VoiceResponse()
response.hangup()

print(response)
开发者ID:GilbertoBotaro,项目名称:api-snippets,代码行数:8,代码来源:hangup-1.6.x.py


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