Monorepo for Tangled tangled.org
756
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview/email: create contact and then add to segment

This is API call is idempotent. If the contact doesn't previously exist
on Resend, adding to Segment will fail.

Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>

+8 -2
+8 -2
appview/email/email.go
··· 33 33 return nil 34 34 } 35 35 36 - // AddNewsletterContact adds an email address to the Resend newsletter segment. 36 + // AddNewsletterContact creates a global contact in Resend and adds them to the newsletter segment. 37 37 func AddNewsletterContact(apiKey, segmentID, emailAddr string) error { 38 38 client := resend.NewClient(apiKey) 39 - _, err := client.Contacts.Segments.Add(&resend.AddContactSegmentRequest{ 39 + _, err := client.Contacts.Create(&resend.CreateContactRequest{ 40 + Email: emailAddr, 41 + }) 42 + if err != nil { 43 + return fmt.Errorf("error creating contact: %w", err) 44 + } 45 + _, err = client.Contacts.Segments.Add(&resend.AddContactSegmentRequest{ 40 46 SegmentId: segmentID, 41 47 Email: emailAddr, 42 48 })