本文整理汇总了Python中corehq.apps.sms.models.CallLog.inbound_call_exists方法的典型用法代码示例。如果您正苦于以下问题:Python CallLog.inbound_call_exists方法的具体用法?Python CallLog.inbound_call_exists怎么用?Python CallLog.inbound_call_exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.sms.models.CallLog
的用法示例。
在下文中一共展示了CallLog.inbound_call_exists方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fire_sms_callback_event
# 需要导入模块: from corehq.apps.sms.models import CallLog [as 别名]
# 或者: from corehq.apps.sms.models.CallLog import inbound_call_exists [as 别名]
def fire_sms_callback_event(reminder, handler, recipients, verified_numbers):
current_event = reminder.current_event
if handler.recipient in [RECIPIENT_CASE, RECIPIENT_USER]:
# If there are no recipients, just move to the next reminder event
if len(recipients) == 0:
return True
# If the callback has been received, skip sending the next timeout message
if reminder.callback_try_count > 0:
# Lookup the expected callback event
if reminder.event_initiation_timestamp is None:
event = None
else:
event = ExpectedCallbackEventLog.view("sms/expected_callback_event",
key=[reminder.domain, json_format_datetime(reminder.event_initiation_timestamp), recipients[0].get_id],
include_docs=True,
limit=1).one()
# NOTE: If last_fired is None, it means that the reminder fired for the first time on a timeout interval
if reminder.last_fired is not None and CallLog.inbound_call_exists(recipients[0].doc_type, recipients[0].get_id, reminder.last_fired):
reminder.skip_remaining_timeouts = True
if event is not None:
event.status = CALLBACK_RECEIVED
event.save()
return True
elif reminder.callback_try_count >= len(current_event.callback_timeout_intervals):
# On the last callback timeout, instead of sending the SMS again, log the missed callback
if event is not None:
event.status = CALLBACK_MISSED
event.save()
return True
else:
# It's the first time sending the sms, so create an expected callback event
event = ExpectedCallbackEventLog(
domain = reminder.domain,
date = reminder.event_initiation_timestamp,
couch_recipient_doc_type = recipients[0].doc_type,
couch_recipient = recipients[0].get_id,
status = CALLBACK_PENDING,
)
event.save()
return fire_sms_event(reminder, handler, recipients, verified_numbers, workflow=WORKFLOW_CALLBACK)
else:
# TODO: Implement sms callback for RECIPIENT_OWNER and RECIPIENT_SURVEY_SAMPLE
return False
示例2: fire
# 需要导入模块: from corehq.apps.sms.models import CallLog [as 别名]
# 或者: from corehq.apps.sms.models.CallLog import inbound_call_exists [as 别名]
def fire(self, reminder):
"""
Sends the message associated with the given CaseReminder's current event.
reminder The CaseReminder which to fire.
return True on success, False on failure
"""
# Get the proper recipient
recipient = reminder.recipient
# Retrieve the VerifiedNumber entry for the recipient
try:
verified_number = recipient.get_verified_number()
except Exception:
verified_number = None
# Get the language of the recipient
try:
lang = recipient.get_language_code()
except Exception:
lang = None
if reminder.method == "survey":
# Close all currently open sessions
sessions = XFormsSession.view("smsforms/open_sessions_by_connection",
key=[reminder.domain, recipient.get_id],
include_docs=True).all()
for session in sessions:
session.end(False)
session.save()
# Start the new session
try:
form_unique_id = reminder.current_event.form_unique_id
form = Form.get_form(form_unique_id)
app = form.get_app()
module = form.get_module()
except Exception as e:
print e
print "ERROR: Could not load survey form for handler " + reminder.handler_id + ", event " + str(reminder.current_event_sequence_num)
return False
session, responses = start_session(reminder.domain, recipient, app, module, form, reminder.case_id)
# Send out first message
if len(responses) > 0:
message = format_message_list(responses)
if verified_number is not None:
return send_sms_to_verified_number(verified_number, message)
else:
return True
else:
# If it is a callback reminder and the callback has been received, skip sending the next timeout message
if (reminder.method == "callback" or reminder.method == "callback_test") and len(reminder.current_event.callback_timeout_intervals) > 0 and (reminder.callback_try_count > 0):
if CallLog.inbound_call_exists(recipient.doc_type, recipient._id, reminder.last_fired):
reminder.callback_received = True
return True
elif len(reminder.current_event.callback_timeout_intervals) == reminder.callback_try_count:
# On the last callback timeout, instead of sending the SMS again, log the missed callback
event = EventLog(
domain = reminder.domain,
date = self.get_now(),
event_type = MISSED_EXPECTED_CALLBACK
)
if verified_number is not None:
event.couch_recipient_doc_type = verified_number.owner_doc_type
event.couch_recipient = verified_number.owner_id
event.save()
return True
reminder.last_fired = self.get_now()
message = reminder.current_event.message.get(lang, reminder.current_event.message[self.default_lang])
message = Message.render(message, case=reminder.case.case_properties())
if reminder.method == "sms" or reminder.method == "callback":
if verified_number is not None:
return send_sms_to_verified_number(verified_number, message)
elif self.recipient == RECIPIENT_USER:
# If there is no verified number, but the recipient is a CommCareUser, still try to send it
try:
phone_number = reminder.user.phone_number
except Exception:
# If the user has no phone number, we cannot send any SMS
return False
return send_sms(reminder.domain, reminder.user_id, phone_number, message)
else:
return False
elif reminder.method == "test" or reminder.method == "callback_test":
print(message)
return True