Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use exact template names for email.send webhook types #2037

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 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,9 +19,3 @@ type PasscodeData struct {
TTL int `json:"ttl"`
ValidUntil int64 `json:"valid_until"` // UnixTimestamp
}

type EmailType string

var (
EmailTypePasscode EmailType = "passcode"
)
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ func (a ReSendPasscode) Execute(c flowpilot.ExecutionContext) error {
}
}

passcodeTemplate := c.Stash().Get(shared.StashPathPasscodeTemplate).String()

sendParams := services.SendPasscodeParams{
Template: c.Stash().Get(shared.StashPathPasscodeTemplate).String(),
Template: passcodeTemplate,
EmailAddress: c.Stash().Get(shared.StashPathEmail).String(),
Language: deps.HttpContext.Request().Header.Get("X-Language"),
}
Expand All @@ -71,7 +73,7 @@ func (a ReSendPasscode) Execute(c flowpilot.ExecutionContext) error {
DeliveredByHanko: deps.Cfg.EmailDelivery.Enabled,
AcceptLanguage: sendParams.Language,
Language: sendParams.Language,
Type: webhook.EmailTypePasscode,
Type: passcodeTemplate,
Data: webhook.PasscodeData{
ServiceName: deps.Cfg.Service.Name,
OtpCode: passcodeResult.Code,
Expand Down
6 changes: 4 additions & 2 deletions backend/flow_api/flow/credential_usage/hook_send_passcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ func (h SendPasscode) Execute(c flowpilot.HookExecutionContext) error {

isDifferentEmailAddress := c.Stash().Get(shared.StashPathEmail).String() != c.Stash().Get(shared.StashPathPasscodeEmail).String()

passcodeTemplate := c.Stash().Get(shared.StashPathPasscodeTemplate).String()

if !passcodeIsValid || isDifferentEmailAddress {
sendParams := services.SendPasscodeParams{
Template: c.Stash().Get(shared.StashPathPasscodeTemplate).String(),
Template: passcodeTemplate,
EmailAddress: c.Stash().Get(shared.StashPathEmail).String(),
Language: deps.HttpContext.Request().Header.Get("X-Language"),
}
Expand All @@ -92,7 +94,7 @@ func (h SendPasscode) Execute(c flowpilot.HookExecutionContext) error {
DeliveredByHanko: deps.Cfg.EmailDelivery.Enabled,
AcceptLanguage: sendParams.Language,
Language: sendParams.Language,
Type: webhook.EmailTypePasscode,
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
Loading