本文整理汇总了Python中corehq.apps.sms.models.CallLog.couch_recipient方法的典型用法代码示例。如果您正苦于以下问题:Python CallLog.couch_recipient方法的具体用法?Python CallLog.couch_recipient怎么用?Python CallLog.couch_recipient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.sms.models.CallLog
的用法示例。
在下文中一共展示了CallLog.couch_recipient方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ivr_in
# 需要导入模块: from corehq.apps.sms.models import CallLog [as 别名]
# 或者: from corehq.apps.sms.models.CallLog import couch_recipient [as 别名]
def ivr_in(request):
"""
Handles tropo call requests
"""
if request.method == "POST":
data = json.loads(request.body)
phone_number = data["session"]["from"]["id"]
# TODO: Implement tropo as an ivr backend. In the meantime, just log the call.
if phone_number:
cleaned_number = strip_plus(phone_number)
v = VerifiedNumber.by_extensive_search(cleaned_number)
else:
v = None
# Save the call entry
msg = CallLog(
phone_number=cleaned_number,
direction=INCOMING,
date=datetime.utcnow(),
backend_api=SQLTropoBackend.get_api_id(),
)
if v is not None:
msg.domain = v.domain
msg.couch_recipient_doc_type = v.owner_doc_type
msg.couch_recipient = v.owner_id
msg.save()
t = Tropo()
t.reject()
return HttpResponse(t.RenderJson())
else:
return HttpResponseBadRequest("Bad Request")
示例2: incoming
# 需要导入模块: from corehq.apps.sms.models import CallLog [as 别名]
# 或者: from corehq.apps.sms.models.CallLog import couch_recipient [as 别名]
def incoming(phone_number, backend_api):
cleaned_number = phone_number
if len(cleaned_number) > 0 and cleaned_number[0] == "+":
cleaned_number = cleaned_number[1:]
# Try to look up the verified number entry
v = VerifiedNumber.view("sms/verified_number_by_number",
key=cleaned_number,
include_docs=True
).one()
# If none was found, try to match only the last digits of numbers in the database
if v is None:
v = VerifiedNumber.view("sms/verified_number_by_suffix",
key=cleaned_number,
include_docs=True
).one()
# Save the call entry
msg = CallLog(
phone_number = cleaned_number,
direction = INCOMING,
date = datetime.utcnow(),
backend_api = backend_api
)
if v is not None:
msg.domain = v.domain
msg.couch_recipient_doc_type = v.owner_doc_type
msg.couch_recipient = v.owner_id
msg.save()
示例3: log_call
# 需要导入模块: from corehq.apps.sms.models import CallLog [as 别名]
# 或者: from corehq.apps.sms.models.CallLog import couch_recipient [as 别名]
def log_call(phone_number, gateway_session_id, backend_module=None):
cleaned_number = strip_plus(phone_number)
v = VerifiedNumber.by_extensive_search(cleaned_number)
call = CallLog(
phone_number=cleaned_number,
direction=INCOMING,
date=datetime.utcnow(),
backend_api=backend_module.API_ID if backend_module else None,
gateway_session_id=gateway_session_id,
)
if v:
call.domain = v.domain
call.couch_recipient_doc_type = v.owner_doc_type
call.couch_recipient = v.owner_id
call.save()
示例4: ivr_in
# 需要导入模块: from corehq.apps.sms.models import CallLog [as 别名]
# 或者: from corehq.apps.sms.models.CallLog import couch_recipient [as 别名]
def ivr_in(request):
"""
Handles tropo call requests
"""
if request.method == "POST":
data = json.loads(request.raw_post_data)
phone_number = data["session"]["from"]["id"]
####
# TODO: Implement tropo as an ivr backend. In the meantime, just log the call.
cleaned_number = phone_number
if cleaned_number is not None and len(cleaned_number) > 0 and cleaned_number[0] == "+":
cleaned_number = cleaned_number[1:]
# Try to look up the verified number entry
v = VerifiedNumber.view("sms/verified_number_by_number",
key=cleaned_number,
include_docs=True
).one()
# If none was found, try to match only the last digits of numbers in the database
if v is None:
v = VerifiedNumber.view("sms/verified_number_by_suffix",
key=cleaned_number,
include_docs=True
).one()
# Save the call entry
msg = CallLog(
phone_number = cleaned_number,
direction = INCOMING,
date = datetime.utcnow(),
backend_api = TropoBackend.get_api_id(),
)
if v is not None:
msg.domain = v.domain
msg.couch_recipient_doc_type = v.owner_doc_type
msg.couch_recipient = v.owner_id
msg.save()
####
t = Tropo()
t.reject()
return HttpResponse(t.RenderJson())
else:
return HttpResponseBadRequest("Bad Request")
示例5: incoming
# 需要导入模块: from corehq.apps.sms.models import CallLog [as 别名]
# 或者: from corehq.apps.sms.models.CallLog import couch_recipient [as 别名]
#.........这里部分代码省略.........
answer_is_valid = True
responses = _get_responses(recipient.domain, recipient._id, input_data, yield_responses=True, session_id=call_log_entry.xforms_session_id)
else:
call_log_entry.current_question_retry_count += 1
responses = [current_q]
else:
responses = []
else:
responses = []
ivr_responses = []
hang_up = False
for response in responses:
if response.is_error:
error_occurred = True
call_log_entry.current_question_retry_count += 1
if response.text_prompt is None:
ivr_responses = []
break
else:
ivr_responses.append(format_ivr_response(response.text_prompt, app))
elif response.event.type == "question":
ivr_responses.append(format_ivr_response(response.event.caption, app))
elif response.event.type == "form-complete":
hang_up = True
if answer_is_valid and not error_occurred:
call_log_entry.current_question_retry_count = 0
if call_log_entry.max_question_retries is not None and call_log_entry.current_question_retry_count > call_log_entry.max_question_retries:
# Force hang-up
ivr_responses = []
if len(ivr_responses) == 0:
hang_up = True
input_length = None
if hang_up:
if call_log_entry.xforms_session_id is not None:
# Process disconnect
session = get_session_by_session_id(call_log_entry.xforms_session_id)
if session.end_time is None:
if call_log_entry.submit_partial_form:
submit_unfinished_form(session.session_id, call_log_entry.include_case_side_effects)
else:
session.end(completed=False)
session.save()
else:
# Set input_length to let the ivr gateway know how many digits we need to collect.
# Have to get the current question again, since the last XFormsResponse in responses
# may not have an event if it was a response to a constraint error.
if error_occurred:
current_q = current_question(call_log_entry.xforms_session_id)
else:
current_q = responses[-1]
input_length = get_input_length(current_q)
call_log_entry.save()
return HttpResponse(backend_module.get_http_response_string(gateway_session_id, ivr_responses, collect_input=(not hang_up), hang_up=hang_up, input_length=input_length))
# If not processed, just log the call
if call_log_entry:
# No need to log, already exists
return HttpResponse("")
cleaned_number = phone_number
if cleaned_number is not None and len(cleaned_number) > 0 and cleaned_number[0] == "+":
cleaned_number = cleaned_number[1:]
# Try to look up the verified number entry
v = VerifiedNumber.view("sms/verified_number_by_number",
key=cleaned_number,
include_docs=True
).one()
# If none was found, try to match only the last digits of numbers in the database
if v is None:
v = VerifiedNumber.view("sms/verified_number_by_suffix",
key=cleaned_number,
include_docs=True
).one()
# Save the call entry
msg = CallLog(
phone_number=cleaned_number,
direction=INCOMING,
date=datetime.utcnow(),
backend_api=backend_module.API_ID if backend_module else None,
gateway_session_id=gateway_session_id,
)
if v is not None:
msg.domain = v.domain
msg.couch_recipient_doc_type = v.owner_doc_type
msg.couch_recipient = v.owner_id
msg.save()
return HttpResponse("")