2023-10-23 18:58:45 +03:00
|
|
|
from fastapi import APIRouter
|
|
|
|
from logger import get_logger
|
2023-12-01 00:29:28 +03:00
|
|
|
from modules.contact_support.controller.settings import ContactsSettings
|
2023-11-14 16:31:02 +03:00
|
|
|
from packages.emails.send_email import send_email
|
2023-10-23 18:58:45 +03:00
|
|
|
from pydantic import BaseModel
|
|
|
|
|
2023-11-13 19:58:11 +03:00
|
|
|
|
2023-10-23 18:58:45 +03:00
|
|
|
class ContactMessage(BaseModel):
|
|
|
|
customer_email: str
|
|
|
|
content: str
|
|
|
|
|
2023-11-13 19:58:11 +03:00
|
|
|
|
2023-12-01 00:29:28 +03:00
|
|
|
contact_router = APIRouter()
|
2023-10-23 18:58:45 +03:00
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
2023-11-13 19:58:11 +03:00
|
|
|
|
2023-10-23 18:58:45 +03:00
|
|
|
def resend_contact_sales_email(customer_email: str, content: str):
|
|
|
|
settings = ContactsSettings()
|
|
|
|
mail_from = settings.resend_contact_sales_from
|
|
|
|
mail_to = settings.resend_contact_sales_to
|
|
|
|
body = f"""
|
|
|
|
<p>Customer email: {customer_email}</p>
|
|
|
|
<p>{content}</p>
|
|
|
|
"""
|
|
|
|
params = {
|
|
|
|
"from": mail_from,
|
|
|
|
"to": mail_to,
|
|
|
|
"subject": "Contact sales",
|
|
|
|
"reply_to": customer_email,
|
|
|
|
"html": body,
|
|
|
|
}
|
2023-11-13 19:58:11 +03:00
|
|
|
|
|
|
|
return send_email(params)
|
|
|
|
|
2023-10-23 18:58:45 +03:00
|
|
|
|
2023-12-01 00:29:28 +03:00
|
|
|
@contact_router.post("/contact")
|
2023-10-23 18:58:45 +03:00
|
|
|
def post_contact(message: ContactMessage):
|
|
|
|
try:
|
|
|
|
resend_contact_sales_email(message.customer_email, message.content)
|
|
|
|
except Exception as e:
|
|
|
|
logger.error(e)
|
|
|
|
return {"error": "There was an error sending the email"}
|