This commit is contained in:
Matthew Knight 2026-02-18 09:24:42 -08:00
parent 09a3155870
commit 793b1883a9
No known key found for this signature in database
2 changed files with 16 additions and 6 deletions

View File

@ -65,17 +65,22 @@ func (c *Client) SendPasswordResetEmail(to, name, token string) error {
return err
}
func (c *Client) SendTicketClosedNotification(to, name, ticketTitle, ticketID string) error {
func (c *Client) SendTicketClosedNotification(to, name, ticketTitle, ticketID, fromName string) error {
if c.server == nil {
return fmt.Errorf("email client not configured")
}
from := c.fromEmail
if fromName != "" {
from = fmt.Sprintf("\"%s\" <%s>", fromName, c.fromEmail)
}
ticketURL := fmt.Sprintf("%s/tickets/%s", c.baseURL, ticketID)
htmlBody := renderTicketClosedEmail(name, ticketTitle, ticketURL)
textBody := fmt.Sprintf("Hi %s,\n\nYour ticket \"%s\" has been resolved.\n\nView it at: %s", name, ticketTitle, ticketURL)
_, err := c.server.SendEmail(context.Background(), postmark.Email{
From: c.fromEmail,
From: from,
To: to,
Subject: fmt.Sprintf("Your ticket \"%s\" has been resolved", ticketTitle),
HTMLBody: htmlBody,
@ -105,17 +110,22 @@ func (c *Client) SendAccountApprovedEmail(to, name string) error {
return err
}
func (c *Client) SendTicketReplyNotification(to, name, ticketTitle, ticketID string) error {
func (c *Client) SendTicketReplyNotification(to, name, ticketTitle, ticketID, fromName string) error {
if c.server == nil {
return fmt.Errorf("email client not configured")
}
from := c.fromEmail
if fromName != "" {
from = fmt.Sprintf("\"%s\" <%s>", fromName, c.fromEmail)
}
ticketURL := fmt.Sprintf("%s/tickets/%s", c.baseURL, ticketID)
htmlBody := renderTicketReplyEmail(name, ticketTitle, ticketURL)
textBody := fmt.Sprintf("Hi %s,\n\nThere is a new reply on your ticket \"%s\".\n\nView it at: %s", name, ticketTitle, ticketURL)
_, err := c.server.SendEmail(context.Background(), postmark.Email{
From: c.fromEmail,
From: from,
To: to,
Subject: fmt.Sprintf("New reply on your ticket \"%s\"", ticketTitle),
HTMLBody: htmlBody,

View File

@ -83,7 +83,7 @@ func (h *WebhookHandler) handleIssueEvent(c *gin.Context, repo *models.Repo, pay
if err := h.deps.DB.First(&user, "id = ?", ticket.UserID).Error; err == nil {
go func() {
if err := h.deps.EmailClient.SendTicketClosedNotification(
user.Email, user.Name, payload.Issue.Title, ticket.ID.String(),
user.Email, user.Name, payload.Issue.Title, ticket.ID.String(), repo.Name+" Support",
); err != nil {
log.Error().Err(err).Msg("webhook: send notification error")
}
@ -117,7 +117,7 @@ func (h *WebhookHandler) handleCommentEvent(c *gin.Context, repo *models.Repo, p
if err := h.deps.DB.First(&user, "id = ?", ticket.UserID).Error; err == nil {
go func() {
if err := h.deps.EmailClient.SendTicketReplyNotification(
user.Email, user.Name, payload.Issue.Title, ticket.ID.String(),
user.Email, user.Name, payload.Issue.Title, ticket.ID.String(), repo.Name+" Support",
); err != nil {
log.Error().Err(err).Msg("webhook: send reply notification error")
}