本文整理汇总了Python中corehq.apps.sms.mixin.MobileBackend.get方法的典型用法代码示例。如果您正苦于以下问题:Python MobileBackend.get方法的具体用法?Python MobileBackend.get怎么用?Python MobileBackend.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.sms.mixin.MobileBackend
的用法示例。
在下文中一共展示了MobileBackend.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_ivr_backend
# 需要导入模块: from corehq.apps.sms.mixin import MobileBackend [as 别名]
# 或者: from corehq.apps.sms.mixin.MobileBackend import get [as 别名]
def get_ivr_backend(recipient, verified_number=None, unverified_number=None):
if verified_number and verified_number.ivr_backend_id:
return MobileBackend.get(verified_number.ivr_backend_id)
else:
phone_number = verified_number.phone_number if verified_number else unverified_number
phone_number = strip_plus(str(phone_number))
prefixes = settings.IVR_BACKEND_MAP.keys()
prefixes = sorted(prefixes, key=lambda x: len(x), reverse=True)
for prefix in prefixes:
if phone_number.startswith(prefix):
return MobileBackend.get(settings.IVR_BACKEND_MAP[prefix])
return None
示例2: send_sms_with_backend
# 需要导入模块: from corehq.apps.sms.mixin import MobileBackend [as 别名]
# 或者: from corehq.apps.sms.mixin.MobileBackend import get [as 别名]
def send_sms_with_backend(domain, phone_number, text, backend_id):
msg = SMSLog(domain = domain,
phone_number = phone_number,
direction = OUTGOING,
date = datetime.utcnow(),
text = text)
if backend_id == "MOBILE_BACKEND_MACH":
try:
try:
msg.backend_api = mach_api.API_ID
except Exception:
pass
mach_api.send(msg)
msg.save()
return True
except Exception:
logging.exception("Exception while sending SMS to %s with backend %s" % (phone_number, backend_id))
return False
elif backend_id == "MOBILE_BACKEND_UNICEL":
try:
try:
msg.backend_api = unicel_api.API_ID
except Exception:
pass
unicel_api.send(msg)
msg.save()
return True
except Exception:
logging.exception("Exception while sending SMS to %s with backend %s" % (phone_number, backend_id))
return False
else:
try:
backend = MobileBackend.get(backend_id)
except Exception:
backend = None
if backend is None:
return False
try:
module = __import__(backend.outbound_module, fromlist=["send"])
try:
msg.backend_api = module.API_ID
except Exception:
pass
kwargs = backend.outbound_params
module.send(msg, **kwargs)
msg.save()
return True
except Exception as e:
logging.exception("Exception while sending SMS to %s with backend %s" % (phone_number, backend_id))
return False