Documentation
¶
Index ¶
- Constants
- Variables
- func Migrate(db *gorm.DB) error
- func Module() fx.Option
- type Config
- type DataMessageContent
- type EnqueueOptions
- type Message
- type MessageIn
- type MessageOut
- type MessageRecipient
- type MessageState
- type MessageStateIn
- type MessageStateOut
- type MessageType
- type Order
- type ProcessingState
- type Repository
- func (r *Repository) Cleanup(ctx context.Context, until time.Time) (int64, error)
- func (r *Repository) Get(filter SelectFilter, options SelectOptions) (Message, error)
- func (r *Repository) HashProcessed(ctx context.Context, ids []uint64) (int64, error)
- func (r *Repository) Insert(message *Message) error
- func (r *Repository) Select(filter SelectFilter, options SelectOptions) ([]Message, int64, error)
- func (r *Repository) SelectPending(deviceID string, order Order) ([]Message, error)
- func (r *Repository) UpdateState(message *Message) error
- type SelectFilter
- func (f *SelectFilter) WithDateRange(start, end time.Time) *SelectFilter
- func (f *SelectFilter) WithDeviceID(deviceID string) *SelectFilter
- func (f *SelectFilter) WithExtID(extID string) *SelectFilter
- func (f *SelectFilter) WithState(state ProcessingState) *SelectFilter
- func (f *SelectFilter) WithUserID(userID string) *SelectFilter
- type SelectOptions
- func (o *SelectOptions) IncludeDevice() *SelectOptions
- func (o *SelectOptions) IncludeRecipients() *SelectOptions
- func (o *SelectOptions) IncludeStates() *SelectOptions
- func (o *SelectOptions) WithLimit(limit int) *SelectOptions
- func (o *SelectOptions) WithOffset(offset int) *SelectOptions
- func (o *SelectOptions) WithOrderBy(order Order) *SelectOptions
- type Service
- 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(userID string, id string) (*MessageStateOut, error)
- func (s *Service) RunBackgroundTasks(ctx context.Context, wg *sync.WaitGroup)
- func (s *Service) SelectPending(deviceID string, order Order) ([]MessageOut, error)
- func (s *Service) SelectStates(userID string, filter SelectFilter, options SelectOptions) ([]MessageStateOut, int64, error)
- func (s *Service) UpdateState(device *models.Device, message MessageStateIn) error
- type TextMessageContent
- type ValidationError
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" )
Variables ¶
View Source
var ErrMessageAlreadyExists = errors.New("duplicate id")
View Source
var ErrMessageNotFound = errors.New("message not found")
View Source
var ErrMultipleMessagesFound = errors.New("multiple messages found")
View Source
var (
ErrNoContent = errors.New("no text or data content")
)
Functions ¶
Types ¶
type DataMessageContent ¶ added in v1.24.0
type EnqueueOptions ¶
type EnqueueOptions struct {
SkipPhoneValidation bool
}
type Message ¶ added in v1.24.0
type Message struct {
models.SoftDeletableModel
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"`
}
func NewMessage ¶ added in v1.34.3
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 {
ID string `json:"id"` // Message ID
State ProcessingState `json:"state"` // State
Recipients []smsgateway.RecipientState `json:"recipients"` // Recipients states
States map[string]time.Time `json:"states"` // History of states
}
type MessageStateOut ¶ added in v1.25.0
type MessageStateOut struct {
MessageStateIn
DeviceID string `json:"device_id"` // Device ID
IsHashed bool `json:"is_hashed"` // Hashed
IsEncrypted bool `json:"is_encrypted"` // Encrypted
}
type MessageType ¶ added in v1.24.0
type MessageType string
type Order ¶ added in v1.34.3
type Order string
Order defines supported ordering for message selection. Valid values: "lifo" (default), "fifo".
type ProcessingState ¶ added in v1.24.0
type ProcessingState string
type Repository ¶ added in v1.34.0
type Repository struct {
// contains filtered or unexported fields
}
func NewRepository ¶ added in v1.34.0
func NewRepository(db *gorm.DB) *Repository
func (*Repository) Get ¶ added in v1.34.0
func (r *Repository) Get(filter SelectFilter, options SelectOptions) (Message, error)
func (*Repository) HashProcessed ¶ added in v1.34.0
func (*Repository) Insert ¶ added in v1.34.0
func (r *Repository) Insert(message *Message) error
func (*Repository) Select ¶ added in v1.34.0
func (r *Repository) Select(filter SelectFilter, options SelectOptions) ([]Message, int64, error)
func (*Repository) SelectPending ¶ added in v1.34.0
func (r *Repository) SelectPending(deviceID string, order Order) ([]Message, error)
func (*Repository) UpdateState ¶ added in v1.34.0
func (r *Repository) UpdateState(message *Message) error
type SelectFilter ¶ added in v1.34.3
type SelectFilter struct {
ExtID string
UserID string
DeviceID string
StartDate time.Time
EndDate time.Time
State ProcessingState
}
func (*SelectFilter) WithDateRange ¶ added in v1.34.3
func (f *SelectFilter) WithDateRange(start, end time.Time) *SelectFilter
func (*SelectFilter) WithDeviceID ¶ added in v1.34.3
func (f *SelectFilter) WithDeviceID(deviceID string) *SelectFilter
func (*SelectFilter) WithExtID ¶ added in v1.34.3
func (f *SelectFilter) WithExtID(extID string) *SelectFilter
func (*SelectFilter) WithState ¶ added in v1.34.3
func (f *SelectFilter) WithState(state ProcessingState) *SelectFilter
func (*SelectFilter) WithUserID ¶ added in v1.34.3
func (f *SelectFilter) WithUserID(userID string) *SelectFilter
type SelectOptions ¶ added in v1.34.3
type SelectOptions struct {
WithRecipients bool
WithDevice bool
WithStates bool
// OrderBy sets the retrieval order for pending messages.
// Empty (zero) value defaults to "lifo".
OrderBy Order
Limit int
Offset int
}
func (*SelectOptions) IncludeDevice ¶ added in v1.34.3
func (o *SelectOptions) IncludeDevice() *SelectOptions
func (*SelectOptions) IncludeRecipients ¶ added in v1.34.3
func (o *SelectOptions) IncludeRecipients() *SelectOptions
func (*SelectOptions) IncludeStates ¶ added in v1.34.3
func (o *SelectOptions) IncludeStates() *SelectOptions
func (*SelectOptions) WithLimit ¶ added in v1.34.3
func (o *SelectOptions) WithLimit(limit int) *SelectOptions
func (*SelectOptions) WithOffset ¶ added in v1.34.3
func (o *SelectOptions) WithOffset(offset int) *SelectOptions
func (*SelectOptions) WithOrderBy ¶ added in v1.34.3
func (o *SelectOptions) WithOrderBy(order Order) *SelectOptions
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
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) GetState ¶
func (s *Service) GetState(userID string, id string) (*MessageStateOut, error)
func (*Service) RunBackgroundTasks ¶
func (*Service) SelectPending ¶
func (s *Service) SelectPending(deviceID string, order Order) ([]MessageOut, error)
func (*Service) SelectStates ¶ added in v1.27.0
func (s *Service) SelectStates( userID string, filter SelectFilter, options SelectOptions, ) ([]MessageStateOut, int64, error)
func (*Service) UpdateState ¶
func (s *Service) UpdateState(device *models.Device, message MessageStateIn) error
type TextMessageContent ¶ added in v1.24.0
type TextMessageContent struct {
Text string `json:"text"`
}
type ValidationError ¶ added in v1.34.3
type ValidationError string
func (ValidationError) Error ¶ added in v1.34.3
func (e ValidationError) Error() string
Click to show internal directories.
Click to hide internal directories.