Add Django site, Docker packaging, and beta/prod Gitea deploys.
Unignore site/ (was blocked by mkdocs /site rule), add compose/Docker/uv tooling, and split deploys so push to main goes to beta while prod stays manual.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
"""SMTP2GO SMS REST API."""
|
||||
|
||||
import logging
|
||||
|
||||
import requests
|
||||
from django.conf import settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def send_sms(message) -> str:
|
||||
contact = message.contact
|
||||
if not contact.phone:
|
||||
raise ValueError("Contact has no phone number")
|
||||
|
||||
api_key = settings.SMTP2GO_SMS_API_KEY
|
||||
if not api_key:
|
||||
raise RuntimeError("SMTP2GO_SMS_API_KEY is not configured")
|
||||
|
||||
campaign = message.campaign
|
||||
body = message.body_snapshot or campaign.body_override or (
|
||||
campaign.template.body if campaign.template else ""
|
||||
)
|
||||
|
||||
payload = {
|
||||
"api_key": api_key,
|
||||
"to": contact.phone,
|
||||
"text": body[:1600],
|
||||
}
|
||||
response = requests.post(
|
||||
settings.SMTP2GO_SMS_API_URL,
|
||||
json=payload,
|
||||
timeout=30,
|
||||
)
|
||||
response.raise_for_status()
|
||||
data = response.json() if response.content else {}
|
||||
# SMTP2GO returns varying shapes; store a useful id when present.
|
||||
return str(
|
||||
data.get("data", {}).get("sms_id")
|
||||
or data.get("request_id")
|
||||
or f"sms-{message.pk}"
|
||||
)
|
||||
Reference in New Issue
Block a user