summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-02-19 22:20:27 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-02-19 22:20:27 +0800
commitf984329bde1784473b9a4e36afc9efd5b46cd06f (patch)
treed86f85685ed305a30bfbbe3820b8e57cbf68b121
parentf2194946f34e5b3259430ffaed72dc658123a46a (diff)
Implement new SMS template
-rw-r--r--jimbrella/sms.py27
1 files changed, 19 insertions, 8 deletions
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})