BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr
Compatible AI email template
lotk39b6d7de6b04
diff --git a/core/api/email_template/v1/email_template.go b/core/api/email_template/v1/email_template.goindex 92e480af..58cbccaa 100644--- a/core/api/email_template/v1/email_template.go+++ b/core/api/email_template/v1/email_template.go@@ -14,6 +14,7 @@ type EmailTemplate struct {Render string `json:"drag_data" description:"Render Data" orm:"render"`CreateTime int `json:"create_time" description:"Create Time" orm:"create_time"`UpdateTime int `json:"update_time" description:"Update Time" orm:"update_time"`+ Chat_id string `json:"chat_id" description:"Exclusive AI Email" orm:"chat_id"`}// CreateTemplateReq Create template request@@ -21,9 +22,10 @@ type CreateTemplateReq struct {g.Meta `path:"/email_template/create" method:"post" tags:"EmailTemplate" summary:"Create email template"`Authorization string `json:"authorization" dc:"Authorization" in:"header"`TempName string `json:"temp_name" v:"required" dc:"Template Name"`- AddType int `json:"add_type" v:"required|in:0,1" dc:"Add Type(0:HTML 1:Drag )"`+ AddType int `json:"add_type" v:"required|in:0,1,2" dc:"Add Type(0:HTML 1:Drag 2:AI)"`Content string `json:"html_content" dc:"HTML Content(Required when add_type=0,1)"`Render string `json:"drag_data" dc:"Drag and Drop Render Data(Required when add_type=1)"`+ Chat_id string `json:"chat_id" dc:"Exclusive AI Email"`}type CreateTemplateRes struct {@@ -65,7 +67,7 @@ type ListTemplatesReq struct {Page int `json:"page" v:"required|min:1" dc:"Page Number"`PageSize int `json:"page_size" v:"required|min:1" dc:"Page Size"`Keyword string `json:"keyword" dc:"Search Keyword(Template Name)"`- AddType int `json:"add_type" dc:"Add Type Filter(0:Upload 1:Drag and Drop -1:All)" default:"-1"`+ AddType int `json:"add_type" dc:"Add Type Filter(0:Upload 1:Drag and Drop 2:AI -1:All)" default:"-1"`}type ListTemplatesRes struct {@@ -81,6 +83,7 @@ type CopyTemplateReq struct {g.Meta `path:"/email_template/copy" method:"post" tags:"EmailTemplate" summary:"Copy email template"`Authorization string `json:"authorization" dc:"Authorization" in:"header"`Id int `json:"id" v:"required" dc:"Template ID"`+ Chat_id string `json:"chat_id" dc:"Exclusive AI Email"`}type CopyTemplateRes struct {diff --git a/core/internal/controller/email_template/email_template_v1_copy_template.go b/core/internal/controller/email_template/email_template_v1_copy_template.goindex bcbf6ccf..08059d86 100644--- a/core/internal/controller/email_template/email_template_v1_copy_template.go+++ b/core/internal/controller/email_template/email_template_v1_copy_template.go@@ -27,7 +27,7 @@ func (c *ControllerV1) CopyTemplate(ctx context.Context, req *v1.CopyTemplateReq}newName := template.TempName + "_bak"- _, err = email_template.CreateTemplate(ctx, newName, template.AddType, template.Content, template.Render)+ _, err = email_template.CreateTemplate(ctx, newName, template.AddType, template.Content, template.Render, req.Chat_id)if err != nil {res.Code = 500res.SetError(gerror.New(public.LangCtx(ctx, "Failed to create new template {}", err.Error())))diff --git a/core/internal/controller/email_template/email_template_v1_create_template.go b/core/internal/controller/email_template/email_template_v1_create_template.goindex ccbe5641..2a3f6cc7 100644--- a/core/internal/controller/email_template/email_template_v1_create_template.go+++ b/core/internal/controller/email_template/email_template_v1_create_template.go@@ -27,7 +27,7 @@ func (c *ControllerV1) CreateTemplate(ctx context.Context, req *v1.CreateTemplat}var content, render string- if req.AddType == 0 { // upload+ if req.AddType == 0 || req.AddType == 2 { // uploadif req.Content == "" {res.Code = 400res.SetError(gerror.New(public.LangCtx(ctx, "File data is required for upload type")))@@ -47,7 +47,7 @@ func (c *ControllerV1) CreateTemplate(ctx context.Context, req *v1.CreateTemplat}// Create template- id, err := email_template.CreateTemplate(ctx, req.TempName, req.AddType, content, render)+ id, err := email_template.CreateTemplate(ctx, req.TempName, req.AddType, content, render, req.Chat_id)if err != nil {res.Code = 500res.SetError(gerror.New(public.LangCtx(ctx, "Failed to create template")))diff --git a/core/internal/service/database_initialization/batch_mail.go b/core/internal/service/database_initialization/batch_mail.goindex c98ba6a7..01018fbb 100644--- a/core/internal/service/database_initialization/batch_mail.go+++ b/core/internal/service/database_initialization/batch_mail.go@@ -49,7 +49,8 @@ func init() {`CREATE TABLE IF NOT EXISTS email_templates (id SERIAL PRIMARY KEY,temp_name VARCHAR(255),- add_type SMALLINT NOT NULL DEFAULT 0,+ chat_id VARCHAR(255), -- ai chat id+ add_type SMALLINT NOT NULL DEFAULT 0, -- // 0 html 1 drag 2 AIcontent TEXT NOT NULL DEFAULT '',render TEXT NOT NULL DEFAULT '',create_time INTEGER NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),@@ -197,6 +198,9 @@ func init() {_ = AddColumnIfNotExists("bm_contact_groups", "welcome_subject", "TEXT", "''", false)_ = AddColumnIfNotExists("bm_contact_groups", "send_welcome_email", "SMALLINT", "0", true)+ //email_templates+ _ = AddColumnIfNotExists("email_templates", "chat_id", "VARCHAR(255)", "''", false)+// unsubscribe_records_ = DropForeignKeyIfExists("unsubscribe_records", "group_id")_ = DropForeignKeyIfExists("unsubscribe_records", "template_id")diff --git a/core/internal/service/email_template/email_template.go b/core/internal/service/email_template/email_template.goindex 0d234db4..a85ac449 100644--- a/core/internal/service/email_template/email_template.go+++ b/core/internal/service/email_template/email_template.go@@ -17,7 +17,7 @@ func CheckTemplateNameExists(ctx context.Context, name string) (bool, error) {}// CreateTemplate-func CreateTemplate(ctx context.Context, name string, addType int, content, render string) (int, error) {+func CreateTemplate(ctx context.Context, name string, addType int, content, render, chat_id string) (int, error) {now := time.Now().Unix()result, err := g.DB().Model("email_templates").Ctx(ctx).@@ -28,6 +28,7 @@ func CreateTemplate(ctx context.Context, name string, addType int, content, rend"render": render,"create_time": now,"update_time": now,+ "chat_id": chat_id,})if err != nil {return 0, err