o2o-site-AEO/solution/backend/services/external/alimtalk.py
Mina Choi 11d30bb3d1 [chore] solution,admin,ontology: 코드 주석을 한 줄로 — 히스토리 주석 삭제
여러 줄 주석이 설명보다 경위(예전·실측·지적)를 적고 있어 읽는 사람이 결론을 찾기 어려웠다.

- ts·tsx·js·mjs·css·py 478개: 여러 줄 주석은 첫 문장 한 줄로, 과거형·날짜 문장은 삭제
- 주석 위치는 TypeScript 파서·파이썬 tokenize/ast 로 찾는다 — 문자열 안의 # · /* 는 건드리지 않는다
- eslint·ts·noqa·type: ignore 같은 지시 주석은 그대로 둔다

파이썬 275개 정리 전후 AST 동일, TS 298개 주석 뺀 토큰 동일(빈 JSX 주석 10곳만 차이).
site·frontend·admin tsc, site vitest 105 passed

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 16:05:19 +09:00

58 lines
1.8 KiB
Python

"""알림톡 대행사 계약은 여기 한 곳에만 둔다."""
import hashlib
import hmac
from config import social_config as config
import secrets
from datetime import datetime, timezone
def is_configured():
return all(
config.get(k)
for k in (
"ALIMTALK_API_KEY",
"ALIMTALK_API_SECRET",
"ALIMTALK_PROFILE_ID",
"ALIMTALK_SENDER",
"ALIMTALK_TEMPLATE_CODE",
)
)
async def send(to, template_code, variables, *, client):
date = datetime.now(timezone.utc).isoformat()
salt = secrets.token_hex(16)
signature = hmac.new(
config.required("ALIMTALK_API_SECRET").encode(),
(date + salt).encode(),
hashlib.sha256,
).hexdigest()
res = await client.post(
"https://api.solapi.com/messages/v4/send-many/detail",
headers={
"Authorization": f"HMAC-SHA256 apiKey={config.required('ALIMTALK_API_KEY')}, date={date}, salt={salt}, signature={signature}"
},
json={
"messages": [
{
"to": to,
"from": config.required("ALIMTALK_SENDER"),
"type": "ATA",
"kakaoOptions": {
"pfId": config.required("ALIMTALK_PROFILE_ID"),
"templateId": template_code,
"variables": variables,
"disableSms": True,
},
}
],
"allowDuplicates": False,
},
)
if res.status_code not in (200, 201):
raise RuntimeError("ALIMTALK_SEND_FAILED")
data = res.json()
if data.get("failedMessageList") or not data.get("groupInfo"):
raise RuntimeError("ALIMTALK_SEND_FAILED")