diff --git a/sparkpost/examples/send_ics/main.go b/sparkpost/examples/send_ics/main.go index d31f0f1..d288f91 100644 --- a/sparkpost/examples/send_ics/main.go +++ b/sparkpost/examples/send_ics/main.go @@ -21,6 +21,8 @@ import ( "github.com/grokify/oauth2more/sparkpost" ) +const DefaultExampleEmail = "john@example.com" + type appConfig struct { SparkPostApiKey string `env:"SPARKPOST_API_KEY"` SparkPostEmailSender string `env:"SPARKPOST_EMAIL_SENDER"` @@ -31,6 +33,10 @@ func sendTestEmail(cfg appConfig, client sp.Client) { day := 811 // Change this to set the day. This currently uses single digit month + 2 digit day seq := 0 // Sequence index. Start with 0 and increment. This demo doesn't support changing the day when changing sequence. + if len(strings.TrimSpace(cfg.SparkPostEmailRecipientDemo)) == 0 { + cfg.SparkPostEmailRecipientDemo = DefaultExampleEmail + } + format := `BEGIN:VCALENDAR VERSION:2.0 PRODID:-//MY COMPANY//Calendar//EN @@ -72,6 +78,7 @@ END:VCALENDAR` attendee, uid2, day, day, dtNow, seq) fmt.Println(data) + panic("z") attach := sp.Attachment{ MIMEType: hum.ContentTypeTextCalendarUtf8Request, B64Data: base64.StdEncoding.EncodeToString([]byte(data))} @@ -97,6 +104,56 @@ END:VCALENDAR` Str("email-id", id) } +func buildExampleIcs(recipientSmtpAddr string, dtStart, dtEnd time.Time, seq uint) string { + if len(strings.TrimSpace(recipientSmtpAddr)) == 0 { + recipientSmtpAddr = DefaultExampleEmail + } + // seq = Sequence index. Start with 0 and increment. This demo doesn't support changing the day when changing sequence. + + day := 811 // Change this to set the day. This currently uses single digit month + 2 digit day + + format := `BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//MY COMPANY//Calendar//EN +CALSCALE:GREGORIAN +METHOD:%v +BEGIN:VEVENT +%vUID:shift-%v-emp-128@mycompany.com +DTSTART:20180%vT010000 +DTEND:20180%vT020000 +DTSTAMP:%v +SEQUENCE:%v +SUMMARY:Morning shift +LOCATION:Morning Location +DESCRIPTION:Morning shift +END:VEVENT +BEGIN:VEVENT +%vUID:shift-%v-emp-128@mycompany.com +DTSTART:20180%vT130000 +DTEND:20180%vT140000 +DTSTAMP:%v +SEQUENCE:%v +SUMMARY:Night shift +LOCATION:Night Location +DESCRIPTION:Night +END:VEVENT +END:VCALENDAR` + + //attenddee needed for both events + attendee := fmt.Sprintf( + "ATTENDEE;ROLE=REQ-PARTICIPANT;CN=%s:MAILTO:%s\n", + recipientSmtpAddr, recipientSmtpAddr) + + uid1 := day + 1000 + uid2 := uid1 + 1 + dtNow := time.Now().Format(tu.ISO8601CompactNoTZ) + icsData := fmt.Sprintf( + format, "REQUEST", + attendee, uid1, day, day, dtNow, seq, + attendee, uid2, day, day, dtNow, seq) + return icsData +} + func main() { envFiles := []string{os.Getenv("ENV_PATH"), "./.env"} if err := config.LoadDotEnvSkipEmpty(envFiles...); err != nil {