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


Python CallLog.backend_api方法代码示例

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


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

示例1: initiate_outbound_call

# 需要导入模块: from corehq.apps.sms.models import CallLog [as 别名]
# 或者: from corehq.apps.sms.models.CallLog import backend_api [as 别名]
def initiate_outbound_call(recipient, form_unique_id, submit_partial_form,
    include_case_side_effects, max_question_retries, verified_number=None,
    unverified_number=None, case_id=None, case_for_case_submission=False,
    timestamp=None):
    """
    Returns True if the call was queued successfully, or False if an error
    occurred.
    """
    call_log_entry = None
    try:
        if not verified_number and not unverified_number:
            return False
        phone_number = (verified_number.phone_number if verified_number
            else unverified_number)
        call_log_entry = CallLog(
            couch_recipient_doc_type=recipient.doc_type,
            couch_recipient=recipient.get_id,
            phone_number="+%s" % str(phone_number),
            direction=OUTGOING,
            date=timestamp or datetime.utcnow(),
            domain=recipient.domain,
            form_unique_id=form_unique_id,
            submit_partial_form=submit_partial_form,
            include_case_side_effects=include_case_side_effects,
            max_question_retries=max_question_retries,
            current_question_retry_count=0,
            case_id=case_id,
            case_for_case_submission=case_for_case_submission,
        )
        backend = get_ivr_backend(recipient, verified_number, unverified_number)
        if not backend:
            return False
        kwargs = backend.get_cleaned_outbound_params()
        module = __import__(backend.outbound_module,
            fromlist=["initiate_outbound_call"])
        call_log_entry.backend_api = module.API_ID
        call_log_entry.save()
        return module.initiate_outbound_call(call_log_entry, **kwargs)
    except Exception:
        if call_log_entry:
            call_log_entry.error = True
            call_log_entry.error_message = "Internal Server Error"
            call_log_entry.save()
        raise
开发者ID:jmaina,项目名称:commcare-hq,代码行数:46,代码来源:api.py

示例2: initiate_outbound_call

# 需要导入模块: from corehq.apps.sms.models import CallLog [as 别名]
# 或者: from corehq.apps.sms.models.CallLog import backend_api [as 别名]
def initiate_outbound_call(verified_number, form_unique_id, submit_partial_form, include_case_side_effects, max_question_retries):
    call_log_entry = CallLog(
        couch_recipient_doc_type = verified_number.owner_doc_type,
        couch_recipient          = verified_number.owner_id,
        phone_number             = "+" + str(verified_number.phone_number),
        direction                = OUTGOING,
        date                     = datetime.utcnow(),
        domain                   = verified_number.domain,
        form_unique_id           = form_unique_id,
        submit_partial_form      = submit_partial_form,
        include_case_side_effects = include_case_side_effects,
        max_question_retries     = max_question_retries,
        current_question_retry_count = 0,
    )
    backend = verified_number.ivr_backend
    kwargs = backend.get_cleaned_outbound_params()
    module = __import__(backend.outbound_module, fromlist=["initiate_outbound_call"])
    call_log_entry.backend_api = module.API_ID
    call_log_entry.save()
    return module.initiate_outbound_call(call_log_entry, **kwargs)
开发者ID:NoahCarnahan,项目名称:commcare-hq,代码行数:22,代码来源:api.py

示例3: initiate_outbound_call

# 需要导入模块: from corehq.apps.sms.models import CallLog [as 别名]
# 或者: from corehq.apps.sms.models.CallLog import backend_api [as 别名]
def initiate_outbound_call(recipient, form_unique_id, submit_partial_form,
        include_case_side_effects, max_question_retries, messaging_event_id,
        verified_number=None, unverified_number=None, case_id=None,
        case_for_case_submission=False, timestamp=None):
    """
    Returns False if an error occurred and the call should be retried.
    Returns True if the call should not be retried (either because it was
    queued successfully or because an unrecoverable error occurred).
    """
    call_log_entry = None
    logged_event = MessagingEvent.objects.get(pk=messaging_event_id)
    logged_subevent = logged_event.create_ivr_subevent(recipient,
        form_unique_id, case_id=case_id)

    if not verified_number and not unverified_number:
        log_error(MessagingEvent.ERROR_NO_PHONE_NUMBER,
            logged_subevent=logged_subevent)
        return True

    backend = get_ivr_backend(recipient, verified_number, unverified_number)
    if not backend:
        log_error(MessagingEvent.ERROR_NO_SUITABLE_GATEWAY,
            logged_subevent=logged_subevent)
        return True

    phone_number = (verified_number.phone_number if verified_number
        else unverified_number)

    call_log_entry = CallLog(
        couch_recipient_doc_type=recipient.doc_type,
        couch_recipient=recipient.get_id,
        phone_number='+%s' % str(phone_number),
        direction=OUTGOING,
        date=timestamp or datetime.utcnow(),
        domain=recipient.domain,
        form_unique_id=form_unique_id,
        submit_partial_form=submit_partial_form,
        include_case_side_effects=include_case_side_effects,
        max_question_retries=max_question_retries,
        current_question_retry_count=0,
        case_id=case_id,
        case_for_case_submission=case_for_case_submission,
        messaging_subevent_id=logged_subevent.pk,
    )

    ivr_data, error = get_first_ivr_response_data(recipient,
        call_log_entry, logged_subevent)
    if error:
        return True
    if ivr_data:
        logged_subevent.xforms_session = ivr_data.session
        logged_subevent.save()

    try:
        kwargs = backend.get_cleaned_outbound_params()
        module = __import__(backend.outbound_module,
            fromlist=['initiate_outbound_call'])

        call_log_entry.backend_api = module.API_ID
        call_log_entry.save()

        result = module.initiate_outbound_call(call_log_entry,
            logged_subevent, ivr_data=ivr_data, **kwargs)
        logged_subevent.completed()
        return result
    except GatewayConnectionError:
        log_error(MessagingEvent.ERROR_GATEWAY_ERROR,
            call_log_entry, logged_subevent)
        raise
    except Exception:
        log_error(MessagingEvent.ERROR_INTERNAL_SERVER_ERROR,
            call_log_entry, logged_subevent)
        raise
开发者ID:sheelio,项目名称:commcare-hq,代码行数:75,代码来源:api.py


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