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(backend): allow ics invitation #78

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
37 changes: 32 additions & 5 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ func App() *cli.App {
Usage: "Path to HTML body file",
Required: true,
},
&cli.StringFlag{
Name: "ics-body",
Value: "",
Usage: "Path to ICS body file",
Required: true,
},
&cli.StringFlag{
Name: "recipients",
Value: "",
Expand All @@ -316,8 +322,8 @@ func App() *cli.App {
Required: false,
},
},
Usage: "blast-email [subject] [template-plaintext] [template-html-body] [csv-file list destination of emails]",
ArgsUsage: "[subject] [template-plaintext] [template-html-body] [path-csv-file]",
Usage: "blast-email [subject] [template-plaintext] [template-html-body] [attachment-ics-body] [csv-file list destination of emails]",
ArgsUsage: "[subject] [template-plaintext] [template-html-body] [attachment-ics-body] [path-csv-file]",
Action: func(cCtx *cli.Context) error {
config, err := GetConfig(cCtx.String("config-file-path"))
if err != nil {
Expand Down Expand Up @@ -349,6 +355,7 @@ func App() *cli.App {
htmlBody := cCtx.String("html-body")
mailCsv := cCtx.String("recipients")
singleRecipient := cCtx.String("single-recipient")
icsBody := cCtx.String("ics-body")

if subject == "" {
log.Fatal().Msg("Subject is required")
Expand Down Expand Up @@ -377,14 +384,14 @@ func App() *cli.App {
if err != nil {
log.Fatal().Err(err).Msg("failed to read html template")
}

htmlTemplate, err := handlebars.Parse(string(htmlContent))
if err != nil {
log.Fatal().Err(err).Msg("failed to parse html template")
}

var userList []User

if mailCsv != "" {
emailList, err := os.ReadFile(mailCsv)
if err != nil {
Expand All @@ -400,6 +407,14 @@ func App() *cli.App {
Email: singleRecipient,
})
}

var icsContent []byte
if icsBody != "" {
icsContent, err = os.ReadFile(icsBody)
if err != nil {
log.Fatal().Err(err).Msg("failed to read ics attachment")
}
}

mailSender := NewMailSender(&MailConfiguration{
SmtpHostname: config.Mailer.Hostname,
Expand All @@ -408,13 +423,25 @@ func App() *cli.App {
SmtpPassword: config.Mailer.Password,
})

attachments := []Attachment{}
if (icsContent != nil){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run go fmt ./... first, to make sure your code align with Go's formatting standards.

attachments := append(attachments, Attachment{
Fixed Show fixed Hide fixed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The attachments variable is being override here.

ContentDisposition: ContentDispositionAttachment,
Name: "invite.ics",
Description: "Invitation",
ContentType: "application/ics",
Payload: icsBody,
})
}

for _, user := range userList {
mail := &Mail{
RecipientName: user.Name,
RecipientEmail: user.Email,
Subject: subject,
PlainTextBody: string(plaintextContent),
HtmlBody: string(htmlContent),
Attachments
}

// Parse email template information
Expand Down
26 changes: 26 additions & 0 deletions emails/payment_success.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//conf.teknologiumum.com//Teknologi Umum
CALSCALE:GREGORIAN
BEGIN:VTIMEZONE
TZID:Asia/Jakarta
LAST-MODIFIED:20230407T050750Z
TZURL:https://www.tzurl.org/zoneinfo-outlook/Asia/Jakarta
X-LIC-LOCATION:Asia/Jakarta
BEGIN:STANDARD
TZNAME:WIB
TZOFFSETFROM:+0700
TZOFFSETTO:+0700
DTSTART:19700101T000000
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTSTAMP:20231015T085408Z
UID:[email protected]
DTSTART;TZID=Asia/Jakarta:20231021T130000
DTEND;TZID=Asia/Jakarta:20231021T190000
SUMMARY:TeknumConf 2023
URL:https://conf.teknologiumum.com/
LOCATION:Kode Creative Hub\, Depok Town Square Depok\, Indonesia
END:VEVENT
END:VCALENDAR