From f984329bde1784473b9a4e36afc9efd5b46cd06f Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Sat, 19 Feb 2022 22:20:27 +0800 Subject: Implement new SMS template --- jimbrella/sms.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'jimbrella/sms.py') diff --git a/jimbrella/sms.py b/jimbrella/sms.py index e83dc54..c8f013c 100644 --- a/jimbrella/sms.py +++ b/jimbrella/sms.py @@ -10,7 +10,7 @@ class SMS: """SMS notification client. This client talks to Aliyun's shit-in-a-box API when JImbrella needs to - remind a tenant to return their overdue umbrella. + notify a tenant of some significant event. """ def __init__(self): @@ -23,23 +23,34 @@ class SMS: def _send( self, - phone_numbers: str, - sign_name: str, + phone_number: str, template_code: str, template_param: dict, ): """Call API to send generic SMS""" req = dysmsapi_models.SendSmsRequest( - phone_numbers=phone_numbers, - sign_name=sign_name, + phone_numbers=phone_number, + sign_name="JIBelief", template_code=template_code, template_param=json.dumps(template_param), ) resp = self.client.send_sms(req) if resp.body.code != "OK": logging.warning( - "API call to send SMS notification to %s failed", phone_numbers + "API call to send SMS notification to %s failed (%s: %s)", + phone_number, + resp.body.code, + resp.body.message, ) - def remind_overdue(self, tenant_phone: str, tenant_name: str, key: int): - self._send(tenant_phone, "TBD", "TBD", {"name": tenant_name, "key": key}) + def borrow_success(self, phone: str, name: str, date: str, umbid: int): + """Current template: jimbrella_takeaway_0 + + ${name}同学,您已于${date}成功借用${umbid}号信用伞,请在三日内归还 + """ + self._send( + phone, "SMS_234140902", {"name": name, "date": date, "umbid": umbid} + ) + + def remind_overdue(self, phone: str, name: str, date: str, umbid: int): + self._send(phone, "TBD", {"name": name, "date": date, "umbid": umbid}) -- cgit v1.2.3