Skip to content

Commit 19b221a

Browse files
AchoArnoldCopilot
andcommitted
fix(api): restore webhook payload text
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f58a74e commit 19b221a

1 file changed

Lines changed: 5 additions & 22 deletions

File tree

api/pkg/emails/hermes_notification_email_factory.go

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type hermesNotificationEmailFactory struct {
1818
generator hermes.Hermes
1919
}
2020

21+
const webhookSendFailedEventPayloadPlaceholder = "__HTTPSMS_WEBHOOK_SEND_FAILED_EVENT_PAYLOAD__"
22+
2123
// NewHermesNotificationEmailFactory creates a new instance of the UserEmailFactory
2224
func NewHermesNotificationEmailFactory(config *HermesGeneratorConfig) NotificationEmailFactory {
2325
return &hermesNotificationEmailFactory{
@@ -94,7 +96,7 @@ func (factory *hermesNotificationEmailFactory) WebhookSendFailed(user *entities.
9496
{Key: "Error Message / HTTP Response", Value: payload.ErrorMessage},
9597
{
9698
Key: "Event Payload",
97-
Value: formattedPayload,
99+
Value: webhookSendFailedEventPayloadPlaceholder,
98100
UnsafeValue: formattedPayloadHTML,
99101
},
100102
},
@@ -125,7 +127,8 @@ func (factory *hermesNotificationEmailFactory) WebhookSendFailed(user *entities.
125127
if err != nil {
126128
return nil, stacktrace.Propagate(err, "cannot generate text email")
127129
}
128-
text = formatWebhookSendFailedTextPayload(text, formattedPayload)
130+
// Hermes/html2text collapses dictionary whitespace, so restore the payload after plain-text generation.
131+
text = strings.Replace(text, webhookSendFailedEventPayloadPlaceholder, formattedPayload, 1)
129132

130133
return &Email{
131134
ToEmail: user.Email,
@@ -135,26 +138,6 @@ func (factory *hermesNotificationEmailFactory) WebhookSendFailed(user *entities.
135138
}, nil
136139
}
137140

138-
func formatWebhookSendFailedTextPayload(text string, formattedPayload string) string {
139-
const (
140-
eventPayloadPrefix = "* Event Payload: "
141-
nextSectionPrefix = "\n\nUsually this error happens"
142-
)
143-
144-
start := strings.Index(text, eventPayloadPrefix)
145-
if start == -1 {
146-
return text
147-
}
148-
149-
end := strings.Index(text[start:], nextSectionPrefix)
150-
if end == -1 {
151-
return text
152-
}
153-
154-
end += start
155-
return text[:start] + eventPayloadPrefix + formattedPayload + text[end:]
156-
}
157-
158141
func (factory *hermesNotificationEmailFactory) MessageExpired(user *entities.User, payload *events.MessageSendExpiredPayload) (*Email, error) {
159142
email := hermes.Email{
160143
Body: hermes.Body{

0 commit comments

Comments
 (0)