mirror of
https://github.com/hanzoai/notify.git
synced 2026-10-30 15:04:32 +00:00
Add service/twilioemail: a transactional email provider that POSTs to Twilio's native Email API (POST https://comms.twilio.com/v1/Emails) with HTTP Basic auth using the SAME Twilio account credentials (account-sid + auth-token) the SMS provider uses. Implements the notify.Notifier surface (Send) plus AddReceivers/BodyFormat, mirroring service/sendgrid so the tenant chain wraps it with the same adapter shape. Wire into internal/tenant: - new provider id "twilio_email" (knownProvider, buildProvider, buildTwilioEmail reading brand/<slug>/twilio/{account-sid,auth-token, from-email,from-name}) - Twilio email is now the head of the hanzo (DefaultBrand) transactional and OTP email chains; SES remains the fallback. Marketing stays on sendgrid->ses (needs RFC 8058 List-Unsubscribe via RawSender). - legacy single-provider path (tenant.go) gets a matching twilio_email branch + required-field list (account-sid, auth-token, from-email). Tests: httptest-based unit tests assert the POST URL, HTTP Basic header (account-sid:auth-token), and JSON body (from/to/subject/html|text); plus plain-text, non-2xx error, and no-receiver no-op cases. Existing chain contract tests updated for the new default chains + known provider. go build ./... and go test ./... pass.
37 lines
991 B
Go
37 lines
991 B
Go
/*
|
|
Package twilioemail provides email notification integration for Twilio's
|
|
native Email API (POST https://comms.twilio.com/v1/Emails).
|
|
|
|
It is the email counterpart to service/twilio (SMS): both authenticate
|
|
with the SAME Twilio account credentials (account SID + auth token) via
|
|
HTTP Basic. Use this instead of service/sendgrid when a brand sends email
|
|
through its Twilio account rather than a separate SendGrid key.
|
|
|
|
Usage:
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
|
|
"github.com/hanzoai/notify"
|
|
"github.com/hanzoai/notify/service/twilioemail"
|
|
)
|
|
|
|
func main() {
|
|
emailSvc := twilioemail.New("account_sid", "auth_token", "[email protected]", "Hanzo")
|
|
emailSvc.AddReceivers("[email protected]")
|
|
|
|
notifier := notify.New()
|
|
notifier.UseServices(emailSvc)
|
|
|
|
if err := notifier.Send(context.Background(), "subject", "<b>message</b>"); err != nil {
|
|
log.Fatalf("notifier.Send() failed: %s", err.Error())
|
|
}
|
|
|
|
log.Println("notification sent")
|
|
}
|
|
*/
|
|
package twilioemail
|