send confirmation email after form submission

This commit is contained in:
Mazyar
2025-12-07 10:52:31 +03:30
parent b8a10f355e
commit fbf99177a9
3 changed files with 400 additions and 2 deletions
+50 -1
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"tm/pkg/logger"
orm "tm/pkg/mongo"
"tm/pkg/notification"
"tm/pkg/response"
)
@@ -33,13 +34,15 @@ type Service interface {
type contactService struct {
repo ContactRepository
logger logger.Logger
sdk notification.SDK
}
// NewService creates a new contact service
func NewService(repo ContactRepository, logger logger.Logger) Service {
func NewService(repo ContactRepository, logger logger.Logger, sdk notification.SDK) Service {
return &contactService{
repo: repo,
logger: logger,
sdk: sdk,
}
}
@@ -68,6 +71,52 @@ func (s *contactService) Create(ctx context.Context, form *CreateContactForm) (*
return nil, fmt.Errorf("failed to create contact: %w", err)
}
// Send confirmation email
s.sdk.SendNotification(ctx, &notification.NotificationRequest{
UserID: contact.GetID(),
Title: "Contact Form Submission Confirmation",
Message: GenerateContactConfirmationEmailTemplate(&ContactEmailTemplateData{
FullName: contact.FullName,
Email: contact.Email,
Phone: contact.Phone,
Message: contact.Message,
ContactID: contact.GetID(),
SubmittedAt: contact.CreatedAt,
CompanyName: "Opplens",
CompanyURL: "https://opplens.com",
SupportEmail: "info@opplens.com",
}),
Type: "confirmation",
Priority: "normal",
EventType: notification.EventTypeEmail,
Methods: notification.NotificationMethods{
Email: contact.Email,
},
})
// Notify admin/internal team
s.sdk.SendNotification(ctx, &notification.NotificationRequest{
UserID: contact.GetID(),
Title: fmt.Sprintf("New Contact Form Submission from %s", contact.FullName),
Message: GenerateContactConfirmationEmailTemplate(&ContactEmailTemplateData{
FullName: contact.FullName,
Email: contact.Email,
Phone: contact.Phone,
Message: contact.Message,
ContactID: contact.GetID(),
SubmittedAt: contact.CreatedAt,
CompanyName: "Opplens",
CompanyURL: "https://opplens.com",
SupportEmail: "info@opplens.com",
}),
Type: "alert",
Priority: "normal",
EventType: notification.EventTypeEmail,
Methods: notification.NotificationMethods{
Email: "info@opplens.com",
},
})
s.logger.Info("Contact message created successfully", map[string]interface{}{
"id": contact.GetID(),
"email": form.Email,