urmi-ai/backend/app/urmiotp_catalog.py
2026-10-07 02:50:28 +05:30

122 lines
6.4 KiB
Python

OTP_TEMPLATES = (
{
"type": "general_verification",
"name": "URMI General Verification OTP",
"content": "Your URMI verification code for {message_label} is {#var#}. It is valid for {#var#} minutes. - URMI",
"sample": "Your URMI verification code for {message_label} is 583921. It is valid for 10 minutes. - URMI",
"uses": [
"Phone or email verification", "Signup and registration", "KYC or identity verification",
"Invitation acceptance", "General verification",
],
"variables": ["Product identification ({message_label})", "OTP ({#var#})", "Validity duration in minutes ({#var#})"],
},
{
"type": "login_authentication",
"name": "URMI Login Authentication OTP",
"content": "Your URMI login verification code for {message_label} is {#var#}. It is valid for {#var#} minutes. - URMI",
"sample": "Your URMI login verification code for {message_label} is 583921. It is valid for 10 minutes. - URMI",
"uses": ["Normal or passwordless login", "MFA and 2FA", "Admin login", "Authentication"],
"variables": ["Product identification ({message_label})", "OTP ({#var#})", "Validity duration in minutes ({#var#})"],
},
{
"type": "account_recovery",
"name": "URMI Account Recovery OTP",
"content": "Your URMI account recovery code for {message_label} is {#var#}. It is valid for {#var#} minutes. - URMI",
"sample": "Your URMI account recovery code for {message_label} is 583921. It is valid for 10 minutes. - URMI",
"uses": ["Forgot password", "Password reset", "Account or locked-account recovery"],
"variables": ["Product identification ({message_label})", "OTP ({#var#})", "Validity duration in minutes ({#var#})"],
},
{
"type": "account_change",
"name": "URMI Account Change OTP",
"content": "Your URMI verification code to update your account for {message_label} is {#var#}. It is valid for {#var#} minutes. - URMI",
"sample": "Your URMI verification code to update your account for {message_label} is 583921. It is valid for 10 minutes. - URMI",
"uses": ["Change mobile number or email", "Change password", "MFA or security setting changes"],
"variables": ["Product identification ({message_label})", "OTP ({#var#})", "Validity duration in minutes ({#var#})"],
},
{
"type": "action_authorization",
"name": "URMI Action Authorization OTP",
"content": "Your URMI authorization code for this action on {message_label} is {#var#}. It is valid for {#var#} minutes. - URMI",
"sample": "Your URMI authorization code for this action on {message_label} is 583921. It is valid for 10 minutes. - URMI",
"uses": ["Sensitive or high-risk operations", "API key changes", "Account deletion", "Ownership changes"],
"variables": ["Product identification ({message_label})", "OTP ({#var#})", "Validity duration in minutes ({#var#})"],
},
{
"type": "transaction_verification",
"name": "URMI Transaction Verification OTP",
"content": "Your URMI transaction verification code for {message_label} is {#var#}. It is valid for {#var#} minutes. - URMI",
"sample": "Your URMI transaction verification code for {message_label} is 583921. It is valid for 10 minutes. - URMI",
"uses": ["Payment authorization", "Transfers and withdrawals", "Financial transaction confirmation"],
"variables": ["Product identification ({message_label})", "OTP ({#var#})", "Validity duration in minutes ({#var#})"],
},
{
"type": "device_verification",
"name": "URMI Device Verification OTP",
"content": "Your URMI device verification code for {message_label} is {#var#}. It is valid for {#var#} minutes. - URMI",
"sample": "Your URMI device verification code for {message_label} is 583921. It is valid for 10 minutes. - URMI",
"uses": ["Device registration or pairing", "Device activation", "IoT ownership verification", "Device transfer"],
"variables": ["Product identification ({message_label})", "OTP ({#var#})", "Validity duration in minutes ({#var#})"],
},
)
def render_templates_for_project(message_label: str) -> list[dict]:
rendered: list[dict] = []
for template in OTP_TEMPLATES:
rendered.append(
{
**template,
"content": template["content"].replace("{message_label}", message_label),
"sample": template["sample"].replace("{message_label}", message_label),
}
)
return rendered
# DLT-approved SMS body for Ultronsms (template ID 1777178797989033323).
# All UrmiOTP template_type values are delivered using this registered text.
URMI_OTP_SMS_CONFIG = {
"sender_id": "URMIAI",
"pe_id": "1701178780498045011",
"dlt_template_id": "1777178797989033323",
"message_template": (
"Your URMI app verification code is {otp} for {message_label}. "
"It is valid for {validity_minutes} minutes. "
"Do not share it to anyone - URMI AI"
),
}
def build_dlt_otp_message(variables: dict[str, str], message_label: str) -> str:
otp_value = variables.get("otp", "").strip()
validity = variables.get("validity_minutes", "").strip()
label = message_label.strip()
if not otp_value or not validity:
raise ValueError("variables.otp and variables.validity_minutes are required")
if not label:
raise ValueError("message_label is required")
return URMI_OTP_SMS_CONFIG["message_template"].format(
otp=otp_value,
message_label=label,
validity_minutes=validity,
)
OTP_API_DOCUMENTATION = {
"method": "POST",
"path": "/api/v1/otp/generate",
"implemented": True,
"summary": "Generate and deliver an OTP using one of Urmi's unified verification templates.",
"parameters": {
"project_name": "Your approved UrmiOTP project name.",
"template_type": "One of the supported template type identifiers.",
"variables": "Values for OTP and validity duration ({#var#} placeholders), in template order.",
"message_label": "Registered with your project; fills the {message_label} slot as your product identification. URMI branding stays fixed.",
},
"example": {
"project_name": "acme-login",
"template_type": "login_authentication",
"variables": {"otp": "583921", "validity_minutes": "10"},
},
}