message

package
v0.0.0-...-d68d608 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAWSSESClient

func NewAWSSESClient(accessKeyID, secretAccessKey, region, senderID string) (*awsSESClient, error)

NewAWSSESClient creates a new AWS SES client, that is used to send emails.

func NewAWSSNSClient

func NewAWSSNSClient(accessKeyID, secretAccessKey, region, senderID string) (*awsSNSClient, error)

NewAWSSNSClient creates a new awsSNSClient, that is used to send SMS messages.

func NewTwilioClient

func NewTwilioClient(accountSid, authToken, senderID string) (*twilioClient, error)

Types

type Message

type Message struct {
	Type              MessageType
	ToPhoneNumber     string
	ToEmail           string
	Body              string
	Title             string
	TemplateVariables map[TemplateVariable]string
}

func (Message) IsValidForEmail

func (m Message) IsValidForEmail() error

func (Message) String

func (m Message) String() string

func (Message) SupportedChannels

func (m Message) SupportedChannels() []MessageChannel

func (Message) ValidateFor

func (m Message) ValidateFor(messengerType MessengerType) error

ValidateFor validates if the message object is valid for the given messengerType.

type MessageChannel

type MessageChannel string
const (
	MessageChannelEmail MessageChannel = "EMAIL"
	MessageChannelSMS   MessageChannel = "SMS"
)

type MessageDispatcher

type MessageDispatcher struct {
	// contains filtered or unexported fields
}

func NewMessageDispatcher

func NewMessageDispatcher() *MessageDispatcher

func (*MessageDispatcher) GetClient

func (d *MessageDispatcher) GetClient(channel MessageChannel) (MessengerClient, error)

func (*MessageDispatcher) RegisterClient

func (d *MessageDispatcher) RegisterClient(ctx context.Context, channel MessageChannel, client MessengerClient)

func (*MessageDispatcher) SendMessage

func (d *MessageDispatcher) SendMessage(ctx context.Context, message Message, channelPriority []MessageChannel) (MessengerType, error)

type MessageDispatcherInterface

type MessageDispatcherInterface interface {
	RegisterClient(ctx context.Context, channel MessageChannel, client MessengerClient)
	SendMessage(ctx context.Context, message Message, channelPriority []MessageChannel) (MessengerType, error)
	GetClient(channel MessageChannel) (MessengerClient, error)
}

type MessageType

type MessageType string
const (
	MessageTypeUserForgotPassword MessageType = "user_forgot_password"
	MessageTypeUserMFA            MessageType = "user_mfa"
	MessageTypeUserInvitation     MessageType = "user_invitation"
	MessageTypeReceiverInvitation MessageType = "receiver_invitation"
	MessageTypeReceiverOTP        MessageType = "receiver_otp"
)

func (MessageType) IsTrustedHTMLBody

func (t MessageType) IsTrustedHTMLBody() bool

IsTrustedHTMLBody reports whether this type's body is trusted, fully-formed HTML (staff emails). Everything else — receiver messages and unknown types — is escaped before embedding in an email.

type MessengerClient

type MessengerClient interface {
	SendMessage(ctx context.Context, message Message) error
	MessengerType() MessengerType
}

func GetClient

func GetClient(opts MessengerOptions) (MessengerClient, error)

func NewDryRunClient

func NewDryRunClient() (MessengerClient, error)

func NewTwilioSendGridClient

func NewTwilioSendGridClient(apiKey string, senderAddress string) (MessengerClient, error)

NewTwilioSendGridClient creates a new SendGrid client that is used to send emails

func NewTwilioWhatsAppClient

func NewTwilioWhatsAppClient(accountSid, authToken, fromNumber string, templates map[MessageType]string) (MessengerClient, error)

NewTwilioWhatsAppClient creates a new Twilio WhatsApp client that is used to send WhatsApp messages.

type MessengerClientMock

type MessengerClientMock struct {
	mock.Mock
}

MessengerClientMock is an autogenerated mock type for the MessengerClient type

func NewMessengerClientMock

func NewMessengerClientMock(t interface {
	mock.TestingT
	Cleanup(func())
}) *MessengerClientMock

NewMessengerClientMock creates a new instance of MessengerClientMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MessengerClientMock) MessengerType

func (_m *MessengerClientMock) MessengerType() MessengerType

MessengerType provides a mock function with given fields:

func (*MessengerClientMock) SendMessage

func (_m *MessengerClientMock) SendMessage(ctx context.Context, message Message) error

SendMessage provides a mock function with given fields: ctx, message

type MessengerOptions

type MessengerOptions struct {
	MessengerType MessengerType
	Environment   string

	// Twilio
	TwilioAccountSID string
	TwilioAuthToken  string

	// Twilio SMS
	TwilioServiceSID string

	// Twilio WhatsApp
	TwilioWhatsAppFromNumber string
	// Twilio WhatsApp Templates
	TwilioWhatsAppReceiverInvitationTemplateSID string
	TwilioWhatsAppReceiverOTPTemplateSID        string

	// Twilio Email (SendGrid)
	TwilioSendGridAPIKey        string
	TwilioSendGridSenderAddress string

	// AWS
	AWSAccessKeyID     string
	AWSSecretAccessKey string
	AWSRegion          string
	// AWS SNS (SMS messages)
	AWSSNSSenderID string
	// AWS SES (EMAIL messages)
	AWSSESSenderID string
}

type MessengerType

type MessengerType string
const (
	// MessengerTypeTwilioSMS is used to send SMS messages using Twilio.
	MessengerTypeTwilioSMS MessengerType = "TWILIO_SMS"
	// MessengerTypeTwilioWhatsApp is used to send WhatsApp messages using Twilio.
	MessengerTypeTwilioWhatsApp MessengerType = "TWILIO_WHATSAPP"
	// MessengerTypeTwilioEmail is used to send emails using Twilio SendGrid.
	MessengerTypeTwilioEmail MessengerType = "TWILIO_EMAIL"
	// MessengerTypeAWSSMS is used to send SMS messages using AWS SNS.
	MessengerTypeAWSSMS MessengerType = "AWS_SMS"
	// MessengerTypeAWSEmail is used to send emails using AWS SES.
	MessengerTypeAWSEmail MessengerType = "AWS_EMAIL"
	// MessengerTypeDryRun is used for development environment
	MessengerTypeDryRun MessengerType = "DRY_RUN"
)

ATTENTION: when adding a new type, make ure to update the MessengerType methods!

func ParseMessengerType

func ParseMessengerType(messengerTypeStr string) (MessengerType, error)

func (MessengerType) All

func (mt MessengerType) All() []MessengerType

func (MessengerType) IsEmail

func (mt MessengerType) IsEmail() bool

func (MessengerType) IsSMS

func (mt MessengerType) IsSMS() bool

func (MessengerType) ValidEmailTypes

func (mt MessengerType) ValidEmailTypes() []MessengerType

func (MessengerType) ValidSMSTypes

func (mt MessengerType) ValidSMSTypes() []MessengerType

type MockMessageDispatcher

type MockMessageDispatcher struct {
	mock.Mock
}

MockMessageDispatcher is an autogenerated mock type for the MessageDispatcherInterface type

func NewMockMessageDispatcher

func NewMockMessageDispatcher(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockMessageDispatcher

NewMockMessageDispatcher creates a new instance of MockMessageDispatcher. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockMessageDispatcher) GetClient

func (_m *MockMessageDispatcher) GetClient(channel MessageChannel) (MessengerClient, error)

GetClient provides a mock function with given fields: channel

func (*MockMessageDispatcher) RegisterClient

func (_m *MockMessageDispatcher) RegisterClient(ctx context.Context, channel MessageChannel, client MessengerClient)

RegisterClient provides a mock function with given fields: ctx, channel, client

func (*MockMessageDispatcher) SendMessage

func (_m *MockMessageDispatcher) SendMessage(ctx context.Context, message Message, channelPriority []MessageChannel) (MessengerType, error)

SendMessage provides a mock function with given fields: ctx, message, channelPriority

type TemplateVariable

type TemplateVariable string
const (
	TemplateVarOrgName                  TemplateVariable = "org_name"
	TemplateVarReceiverOTP              TemplateVariable = "receiver_otp"
	TemplateVarReceiverRegistrationLink TemplateVariable = "registration_link"
	TemplateVarResetPasswordLink        TemplateVariable = "reset_password_link"
	TemplateVarMFACode                  TemplateVariable = "mfa_code"
	TemplateVarFirstName                TemplateVariable = "first_name"
	TemplateVarRole                     TemplateVariable = "role"
	TemplateVarForgotPasswordLink       TemplateVariable = "forgot_password_link"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址