mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-25 04:12:44 +03:00
cee050a2e4
# Description Issue: #1445 Epic: #1232 ## ⚠️ À rajouter en variables d'environnement ```env RESEND_CONTACT_SALES_FROM=contact_sales@resend.dev RESEND_CONTACT_SALES_TO=<change-me> ```
39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
from fastapi import APIRouter
|
|
from logger import get_logger
|
|
from models import ContactsSettings
|
|
from pydantic import BaseModel
|
|
|
|
from utils.send_email import send_email
|
|
|
|
class ContactMessage(BaseModel):
|
|
customer_email: str
|
|
content: str
|
|
|
|
router = APIRouter()
|
|
logger = get_logger(__name__)
|
|
|
|
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,
|
|
}
|
|
send_email(params)
|
|
|
|
@router.post("/contact")
|
|
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"}
|