Skip to content

Commit

Permalink
feat: use exact template names for email.send webhook types
Browse files Browse the repository at this point in the history
  • Loading branch information
lfleischmann committed Jan 30, 2025
1 parent 9a411e7 commit b181235
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 39 deletions.
44 changes: 8 additions & 36 deletions backend/dto/webhook/email.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package webhook

type EmailSend struct {
Subject string `json:"subject"` // subject
BodyPlain string `json:"body_plain"` // used for string templates
Body string `json:"body,omitempty"` // used for HTML templates
ToEmailAddress string `json:"to_email_address"`
DeliveredByHanko bool `json:"delivered_by_hanko"`
AcceptLanguage string `json:"accept_language"` // Deprecated. Accept-Language header from HTTP request
Language string `json:"language"` // X-Language header from HTTP request
Type EmailType `json:"type"` // type of the email, currently only "passcode", but other could be added later
Subject string `json:"subject"` // subject
BodyPlain string `json:"body_plain"` // used for string templates
Body string `json:"body,omitempty"` // used for HTML templates
ToEmailAddress string `json:"to_email_address"`
DeliveredByHanko bool `json:"delivered_by_hanko"`
AcceptLanguage string `json:"accept_language"` // Deprecated. Accept-Language header from HTTP request
Language string `json:"language"` // X-Language header from HTTP request
Type string `json:"type"` // type of the email

Data interface{} `json:"data"`
}
Expand All @@ -19,31 +19,3 @@ type PasscodeData struct {
TTL int `json:"ttl"`
ValidUntil int64 `json:"valid_until"` // UnixTimestamp
}

type EmailType string

func EmailTypeFromStashedTemplateName(stashedTemplateName string) EmailType {
switch stashedTemplateName {
case "login":
return EmailTypePasscode
case "email_login_attempted":
return EmailTypeLoginAttempt
case "email_verification":
return EmailTypeEmailVerification
case "email_registration_attempted":
return EmailTypeRegistrationAttempt
case "recovery":
return EmailTypeRecovery
default:
return EmailTypeUnknown
}
}

var (
EmailTypePasscode EmailType = "passcode"
EmailTypeLoginAttempt EmailType = "login_attempt"
EmailTypeRegistrationAttempt EmailType = "registration_attempt"
EmailTypeEmailVerification EmailType = "email_verification"
EmailTypeRecovery EmailType = "recovery"
EmailTypeUnknown EmailType = "unknown"
)
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (a ReSendPasscode) Execute(c flowpilot.ExecutionContext) error {
DeliveredByHanko: deps.Cfg.EmailDelivery.Enabled,
AcceptLanguage: sendParams.Language,
Language: sendParams.Language,
Type: webhook.EmailTypeFromStashedTemplateName(passcodeTemplate),
Type: passcodeTemplate,
Data: webhook.PasscodeData{
ServiceName: deps.Cfg.Service.Name,
OtpCode: passcodeResult.Code,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (h SendPasscode) Execute(c flowpilot.HookExecutionContext) error {
DeliveredByHanko: deps.Cfg.EmailDelivery.Enabled,
AcceptLanguage: sendParams.Language,
Language: sendParams.Language,
Type: webhook.EmailTypeFromStashedTemplateName(passcodeTemplate),
Type: passcodeTemplate,
Data: webhook.PasscodeData{
ServiceName: deps.Cfg.Service.Name,
OtpCode: passcodeResult.Code,
Expand Down
2 changes: 1 addition & 1 deletion backend/handler/passcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (h *PasscodeHandler) Init(c echo.Context) error {
DeliveredByHanko: true,
AcceptLanguage: lang,
Language: lang,
Type: webhook.EmailTypePasscode,
Type: "passcode",
Data: webhook.PasscodeData{
ServiceName: h.cfg.Service.Name,
OtpCode: passcode,
Expand Down

0 comments on commit b181235

Please sign in to comment.