mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-15 17:43:03 +03:00
f48dab4a7d
# Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
from fastapi import APIRouter
|
|
from logger import get_logger
|
|
from modules.contact_support.controller.settings import ContactsSettings
|
|
from packages.emails.send_email import send_email
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class ContactMessage(BaseModel):
|
|
customer_email: str
|
|
content: str
|
|
|
|
|
|
contact_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,
|
|
}
|
|
|
|
return send_email(params)
|
|
|
|
|
|
@contact_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"}
|