|
|
@@ -23,12 +23,23 @@ class EmailsService:
|
|
|
"dynamic code",
|
|
|
"one time password"
|
|
|
]
|
|
|
+
|
|
|
+ SENDER_BLACKLIST = [
|
|
|
+ "etsy",
|
|
|
+ "dsw",
|
|
|
+ ]
|
|
|
|
|
|
@staticmethod
|
|
|
def _is_subject_blacklisted(subject: str) -> bool:
|
|
|
if not subject: return False
|
|
|
lower = subject.lower()
|
|
|
return any(kw.lower() in lower for kw in EmailsService.SUBJECT_BLACKLIST)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def _is_sender_blacklisted(sender: str) -> bool:
|
|
|
+ if not sender: return False
|
|
|
+ lower = sender.lower()
|
|
|
+ return any(kw.lower() in lower for kw in EmailsService.SENDER_BLACKLIST)
|
|
|
|
|
|
@staticmethod
|
|
|
def _summarize(text: str, limit: int = 120) -> str:
|
|
|
@@ -82,6 +93,10 @@ class EmailsService:
|
|
|
if EmailsService._is_subject_blacklisted(rec.subject or ""):
|
|
|
logger.info(f"Email {rec.uid} skipped: subject '{rec.subject}' is in blacklist.")
|
|
|
return
|
|
|
+
|
|
|
+ if EmailsService._is_sender_blacklisted(rec.sender or ""):
|
|
|
+ logger.info(f"Email {rec.uid} skipped: subject '{rec.sender}' is in blacklist.")
|
|
|
+ return
|
|
|
|
|
|
# 1. 尝试创建订单事件 (OrderEventService 内部会根据 rec.recipient 匹配订单)
|
|
|
try:
|
|
|
@@ -116,8 +131,8 @@ class EmailsService:
|
|
|
|
|
|
# 优先级:数据库用户字段 > 订单输入的联系方式
|
|
|
email_to = (user.email if user else None) or user_inputs.get("email")
|
|
|
- phone = (user.phone if user else None) or user_inputs.get("phone")
|
|
|
- country_code = str(user_inputs.get("phone_country_code") or "")
|
|
|
+ # phone = (user.phone if user else None) or user_inputs.get("phone")
|
|
|
+ # country_code = str(user_inputs.get("phone_country_code") or "")
|
|
|
|
|
|
# 4. 构造通知内容
|
|
|
summary = EmailsService._summarize(rec.body_text or "")
|
|
|
@@ -140,43 +155,43 @@ class EmailsService:
|
|
|
)
|
|
|
|
|
|
# --- WhatsApp 推送任务 ---
|
|
|
- if phone:
|
|
|
- # 确保国家代码不带 +
|
|
|
- code = str(user_inputs.get("phone_country_code") or "").replace("+", "")
|
|
|
- # 去掉手机号开头的 0
|
|
|
- clean_phone = str(phone).lstrip('0')
|
|
|
+ # if phone:
|
|
|
+ # # 确保国家代码不带 +
|
|
|
+ # code = str(user_inputs.get("phone_country_code") or "").replace("+", "")
|
|
|
+ # # 去掉手机号开头的 0
|
|
|
+ # clean_phone = str(phone).lstrip('0')
|
|
|
|
|
|
- # 组合纯数字部分
|
|
|
- digits = f"{code}{clean_phone}"
|
|
|
- # 再次利用正则确保只剩数字(以防 code 包含特殊字符)
|
|
|
- digits = re.sub(r"\D", "", digits)
|
|
|
-
|
|
|
- if "@lid" in str(phone):
|
|
|
- chat_id = phone
|
|
|
- elif digits:
|
|
|
- # 使用不带 + 的纯数字拼接后缀
|
|
|
- chat_id = f"{digits}@c.us"
|
|
|
- else:
|
|
|
- return
|
|
|
-
|
|
|
- message = (
|
|
|
- f"🔔 *Progress Update*\n\n"
|
|
|
- f"We received an update for your appointment:\n"
|
|
|
- f"_{summary}_\n\n"
|
|
|
- f"Please log in to your dashboard or check your email for full details."
|
|
|
- )
|
|
|
-
|
|
|
- await NotificationService.post_message(
|
|
|
- db=db,
|
|
|
- channel="whatsapp",
|
|
|
- payload={
|
|
|
- "template_id": "order_event_update",
|
|
|
- "receiver": chat_id,
|
|
|
- "payload": {
|
|
|
- "message": message,
|
|
|
- "order_no": order.id,
|
|
|
- },
|
|
|
- },
|
|
|
- )
|
|
|
+ # # 组合纯数字部分
|
|
|
+ # digits = f"{code}{clean_phone}"
|
|
|
+ # # 再次利用正则确保只剩数字(以防 code 包含特殊字符)
|
|
|
+ # digits = re.sub(r"\D", "", digits)
|
|
|
+
|
|
|
+ # if "@lid" in str(phone):
|
|
|
+ # chat_id = phone
|
|
|
+ # elif digits:
|
|
|
+ # # 使用不带 + 的纯数字拼接后缀
|
|
|
+ # chat_id = f"{digits}@c.us"
|
|
|
+ # else:
|
|
|
+ # return
|
|
|
+
|
|
|
+ # message = (
|
|
|
+ # f"🔔 *Progress Update*\n\n"
|
|
|
+ # f"We received an update for your appointment:\n"
|
|
|
+ # f"_{summary}_\n\n"
|
|
|
+ # f"Please log in to your dashboard or check your email for full details."
|
|
|
+ # )
|
|
|
+
|
|
|
+ # await NotificationService.post_message(
|
|
|
+ # db=db,
|
|
|
+ # channel="whatsapp",
|
|
|
+ # payload={
|
|
|
+ # "template_id": "order_event_update",
|
|
|
+ # "receiver": chat_id,
|
|
|
+ # "payload": {
|
|
|
+ # "message": message,
|
|
|
+ # "order_no": order.id,
|
|
|
+ # },
|
|
|
+ # },
|
|
|
+ # )
|
|
|
|
|
|
logger.info(f"Notification tasks queued for Email {rec.uid} (Order: {order.id})")
|