Documentation
¶
Index ¶
- Constants
- Variables
- func Migrate(db *gorm.DB) error
- type Config
- type DataMessageContent
- type EnqueueOptions
- type ErrValidation
- type FxResult
- type HashingTask
- type HashingTaskConfig
- type HashingTaskParams
- type Message
- type MessageIn
- type MessageOut
- type MessageRecipient
- type MessageState
- type MessageStateIn
- type MessageStateOut
- type MessageType
- type MessagesOrder
- type MessagesSelectFilter
- type MessagesSelectOptions
- type ProcessingState
- type Service
- func (s *Service) Clean(ctx context.Context) error
- func (s *Service) Enqueue(device models.Device, message MessageIn, opts EnqueueOptions) (MessageStateOut, error)
- func (s *Service) ExportInbox(device models.Device, since, until time.Time) error
- func (s *Service) GetState(user models.User, ID string) (MessageStateOut, error)
- func (s *Service) RunBackgroundTasks(ctx context.Context, wg *sync.WaitGroup)
- func (s *Service) SelectPending(deviceID string, order MessagesOrder) ([]MessageOut, error)
- func (s *Service) SelectStates(user models.User, filter MessagesSelectFilter, options MessagesSelectOptions) ([]MessageStateOut, int64, error)
- func (s *Service) UpdateState(deviceID string, message MessageStateIn) error
- type ServiceParams
- type TextMessageContent
Constants ¶
View Source
const ( ProcessingStatePending ProcessingState = "Pending" ProcessingStateProcessed ProcessingState = "Processed" ProcessingStateSent ProcessingState = "Sent" ProcessingStateDelivered ProcessingState = "Delivered" ProcessingStateFailed ProcessingState = "Failed" MessageTypeText MessageType = "Text" MessageTypeData MessageType = "Data" )
View Source
const (
ErrorTTLExpired = "TTL expired"
)
Variables ¶
View Source
var ErrMessageAlreadyExists = errors.New("duplicate id")
View Source
var ErrMessageNotFound = gorm.ErrRecordNotFound
View Source
var ErrMultipleMessagesFound = errors.New("multiple messages found")
View Source
var Module = fx.Module( "messages", fx.Decorate(func(log *zap.Logger) *zap.Logger { return log.Named("messages") }), fx.Provide(func(p ServiceParams) FxResult { svc := NewService(p) return FxResult{ Service: svc, AsCleaner: svc, } }), fx.Provide(newRepository), fx.Provide(NewHashingTask, fx.Private), )
Functions ¶
Types ¶
type DataMessageContent ¶ added in v1.24.0
type EnqueueOptions ¶
type EnqueueOptions struct {
SkipPhoneValidation bool
}
type ErrValidation ¶
type ErrValidation string
func (ErrValidation) Error ¶
func (e ErrValidation) Error() string
type HashingTask ¶
type HashingTask struct {
Messages *repository
Config HashingTaskConfig
Logger *zap.Logger
// contains filtered or unexported fields
}
func NewHashingTask ¶
func NewHashingTask(params HashingTaskParams) *HashingTask
func (*HashingTask) Enqueue ¶ added in v1.20.0
func (t *HashingTask) Enqueue(id uint64)
Enqueue adds a message ID to the processing queue to be hashed in the next batch
func (*HashingTask) Run ¶
func (t *HashingTask) Run(ctx context.Context)
type HashingTaskConfig ¶
type HashingTaskParams ¶
type HashingTaskParams struct {
fx.In
Messages *repository
Config HashingTaskConfig
Logger *zap.Logger
}
type Message ¶ added in v1.24.0
type Message struct {
ID uint64 `gorm:"primaryKey;type:BIGINT UNSIGNED;autoIncrement"`
DeviceID string `gorm:"not null;type:char(21);uniqueIndex:unq_messages_id_device,priority:2;index:idx_messages_device_state"`
ExtID string `gorm:"not null;type:varchar(36);uniqueIndex:unq_messages_id_device,priority:1"`
Type MessageType `gorm:"not null;type:enum('Text','Data');default:Text"`
Content string `gorm:"not null;type:text"`
State ProcessingState `gorm:"not null;type:enum('Pending','Sent','Processed','Delivered','Failed');default:Pending;index:idx_messages_device_state"`
ValidUntil *time.Time `gorm:"type:datetime"`
SimNumber *uint8 `gorm:"type:tinyint(1) unsigned"`
WithDeliveryReport bool `gorm:"not null;type:tinyint(1) unsigned"`
Priority int8 `gorm:"not null;type:tinyint;default:0"`
IsHashed bool `gorm:"not null;type:tinyint(1) unsigned;default:0"`
IsEncrypted bool `gorm:"not null;type:tinyint(1) unsigned;default:0"`
Device models.Device `gorm:"foreignKey:DeviceID;constraint:OnDelete:CASCADE"`
Recipients []MessageRecipient `gorm:"foreignKey:MessageID;constraint:OnDelete:CASCADE"`
States []MessageState `gorm:"foreignKey:MessageID;constraint:OnDelete:CASCADE"`
models.SoftDeletableModel
}
func (*Message) GetDataContent ¶ added in v1.24.0
func (m *Message) GetDataContent() (*DataMessageContent, error)
func (*Message) GetTextContent ¶ added in v1.24.0
func (m *Message) GetTextContent() (*TextMessageContent, error)
func (*Message) SetDataContent ¶ added in v1.24.0
func (m *Message) SetDataContent(content DataMessageContent) error
func (*Message) SetTextContent ¶ added in v1.24.0
func (m *Message) SetTextContent(content TextMessageContent) error
type MessageIn ¶ added in v1.20.0
type MessageIn struct {
ID string
TextContent *TextMessageContent
DataContent *DataMessageContent
PhoneNumbers []string
IsEncrypted bool
SimNumber *uint8
WithDeliveryReport *bool
TTL *uint64
ValidUntil *time.Time
Priority smsgateway.MessagePriority
}
type MessageOut ¶ added in v1.20.0
type MessageRecipient ¶ added in v1.24.0
type MessageRecipient struct {
ID uint64 `gorm:"primaryKey;type:BIGINT UNSIGNED;autoIncrement"`
MessageID uint64 `gorm:"uniqueIndex:unq_message_recipients_message_id_phone_number,priority:1;type:BIGINT UNSIGNED"`
PhoneNumber string `gorm:"uniqueIndex:unq_message_recipients_message_id_phone_number,priority:2;type:varchar(128)"`
State ProcessingState `gorm:"not null;type:enum('Pending','Sent','Processed','Delivered','Failed');default:Pending"`
Error *string `gorm:"type:varchar(256)"`
}
type MessageState ¶ added in v1.24.0
type MessageState struct {
ID uint64 `gorm:"primaryKey;type:BIGINT UNSIGNED;autoIncrement"`
MessageID uint64 `gorm:"not null;type:BIGINT UNSIGNED;uniqueIndex:unq_message_states_message_id_state,priority:1"`
State ProcessingState `` /* 135-byte string literal not displayed */
UpdatedAt time.Time `gorm:"<-:create;not null;autoupdatetime:false"`
}
type MessageStateIn ¶ added in v1.25.0
type MessageStateIn struct {
// Message ID
ID string
// State
State ProcessingState
// Recipients states
Recipients []smsgateway.RecipientState
// History of states
States map[string]time.Time
}
type MessageStateOut ¶ added in v1.25.0
type MessageStateOut struct {
// Device ID
DeviceID string
// Hashed
IsHashed bool
// Encrypted
IsEncrypted bool
MessageStateIn
}
type MessageType ¶ added in v1.24.0
type MessageType string
type MessagesOrder ¶ added in v1.28.0
type MessagesOrder string
MessagesOrder defines supported ordering for message selection. Valid values: "lifo" (default), "fifo".
const ( // MessagesOrderLIFO orders messages newest-first within the same priority (default). MessagesOrderLIFO MessagesOrder = "lifo" // MessagesOrderFIFO orders messages oldest-first within the same priority. MessagesOrderFIFO MessagesOrder = "fifo" )
type MessagesSelectFilter ¶
type MessagesSelectOptions ¶
type ProcessingState ¶ added in v1.24.0
type ProcessingState string
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(params ServiceParams) *Service
func (*Service) Enqueue ¶ added in v1.20.0
func (s *Service) Enqueue(device models.Device, message MessageIn, opts EnqueueOptions) (MessageStateOut, error)
func (*Service) ExportInbox ¶ added in v1.17.0
func (*Service) RunBackgroundTasks ¶
func (*Service) SelectPending ¶
func (s *Service) SelectPending(deviceID string, order MessagesOrder) ([]MessageOut, error)
func (*Service) SelectStates ¶ added in v1.27.0
func (s *Service) SelectStates(user models.User, filter MessagesSelectFilter, options MessagesSelectOptions) ([]MessageStateOut, int64, error)
func (*Service) UpdateState ¶
func (s *Service) UpdateState(deviceID string, message MessageStateIn) error
type ServiceParams ¶
type TextMessageContent ¶ added in v1.24.0
type TextMessageContent struct {
Text string `json:"text"`
}
Click to show internal directories.
Click to hide internal directories.