2023-07-18 10:47:59 +03:00
|
|
|
from logger import get_logger
|
2023-11-14 16:31:02 +03:00
|
|
|
from models import BrainSettings, BrainSubscription
|
2023-12-01 00:29:28 +03:00
|
|
|
from modules.brain.service.brain_service import BrainService
|
2023-11-14 16:31:02 +03:00
|
|
|
from packages.emails.send_email import send_email
|
2023-08-21 13:25:16 +03:00
|
|
|
from repository.brain_subscription import get_brain_url
|
2023-07-18 10:47:59 +03:00
|
|
|
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
2023-12-01 00:29:28 +03:00
|
|
|
brain_service = BrainService()
|
|
|
|
|
2023-07-18 10:47:59 +03:00
|
|
|
|
2023-07-20 16:15:43 +03:00
|
|
|
def resend_invitation_email(
|
|
|
|
brain_subscription: BrainSubscription,
|
|
|
|
inviter_email: str,
|
|
|
|
origin: str = "https://www.quivr.app",
|
|
|
|
):
|
2023-07-18 10:47:59 +03:00
|
|
|
brains_settings = BrainSettings() # pyright: ignore reportPrivateUsage=none
|
|
|
|
|
|
|
|
brain_url = get_brain_url(origin, brain_subscription.brain_id)
|
|
|
|
|
2023-12-01 00:29:28 +03:00
|
|
|
invitation_brain = brain_service.get_brain_details(brain_subscription.brain_id)
|
2023-08-01 17:25:02 +03:00
|
|
|
if invitation_brain is None:
|
|
|
|
raise Exception("Brain not found")
|
2023-08-03 11:37:13 +03:00
|
|
|
brain_name = invitation_brain.name
|
2023-07-20 16:15:43 +03:00
|
|
|
|
2023-07-18 10:47:59 +03:00
|
|
|
html_body = f"""
|
2023-07-20 16:15:43 +03:00
|
|
|
<p>Brain {brain_name} has been shared with you by {inviter_email}.</p>
|
2023-07-18 10:47:59 +03:00
|
|
|
<p><a href='{brain_url}'>Click here</a> to access your brain.</p>
|
|
|
|
"""
|
|
|
|
|
|
|
|
try:
|
2023-10-23 18:58:45 +03:00
|
|
|
r = send_email(
|
2023-07-20 16:15:43 +03:00
|
|
|
{
|
|
|
|
"from": brains_settings.resend_email_address,
|
|
|
|
"to": brain_subscription.email,
|
|
|
|
"subject": "Quivr - Brain Shared With You",
|
|
|
|
"html": html_body,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
logger.info("Resend response", r)
|
2023-07-18 10:47:59 +03:00
|
|
|
except Exception as e:
|
|
|
|
logger.error(f"Error sending email: {e}")
|
|
|
|
return
|
|
|
|
|
|
|
|
return r
|