Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

1.4 KB
Raw Blame
package emailtypes

import (
	"bytes"
	"context"
	"html/template"

	"github.com/SigNoz/signoz/pkg/errors"
	"github.com/SigNoz/signoz/pkg/valuer"
)

var (
	// Templates is a list of all the templates that are supported by the emailing service.
	// This list should be updated whenever a new template is added.
	Templates = []TemplateName{TemplateNameInvitationEmail, TemplateNameResetPassword}
)

var (
	TemplateNameInvitationEmail = TemplateName{valuer.NewString("invitation")}
	TemplateNameResetPassword   = TemplateName{valuer.NewString("reset_password")}
	TemplateNameAPIKeyEvent     = TemplateName{valuer.NewString("api_key_event")}
)

type TemplateName struct{ valuer.String }

func NewTemplateName(name string) (TemplateName, error) {
	switch name {
	case TemplateNameInvitationEmail.StringValue():
		return TemplateNameInvitationEmail, nil
	case TemplateNameResetPassword.StringValue():
		return TemplateNameResetPassword, nil
	case TemplateNameAPIKeyEvent.StringValue():
		return TemplateNameAPIKeyEvent, nil
	default:
		return TemplateName{}, errors.Newf(errors.TypeInvalidInput, errors.CodeInvalidInput, "invalid template name: %s", name)
	}
}

func NewContent(template *template.Template, data map[string]any) ([]byte, error) {
	buf := bytes.NewBuffer(nil)
	err := template.Execute(buf, data)
	if err != nil {
		return nil, err
	}

	return buf.Bytes(), nil
}

type TemplateStore interface {
	Get(context.Context, TemplateName) (*template.Template, error)
}