-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
madeindra
wants to merge
3
commits into
teknologi-umum:master
Choose a base branch
from
madeindra:feat/invitation-attachment
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: "", | ||
|
@@ -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 { | ||
|
@@ -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") | ||
|
@@ -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 { | ||
|
@@ -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, | ||
|
@@ -408,13 +423,25 @@ func App() *cli.App { | |
SmtpPassword: config.Mailer.Password, | ||
}) | ||
|
||
attachments := []Attachment{} | ||
if (icsContent != nil){ | ||
attachments := append(attachments, Attachment{ | ||
|
||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.