messaging

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IMSIMDNDispositionPositiveDelivery = "positive-delivery"
	IMSIMDNDispositionNegativeDelivery = "negative-delivery"
	IMSIMDNDispositionDisplay          = "display"
	IMSIMDNDispositionProcessing       = "processing"
)
View Source
const (
	SMSNationalLanguageTurkish    = 1
	SMSNationalLanguageSpanish    = 2
	SMSNationalLanguagePortuguese = 3
	SMSNationalLanguageBengali    = 4
	SMSNationalLanguageGujarati   = 5
	SMSNationalLanguageHindi      = 6
	SMSNationalLanguageKannada    = 7
	SMSNationalLanguageMalayalam  = 8
	SMSNationalLanguageOriya      = 9
	SMSNationalLanguagePunjabi    = 10
	SMSNationalLanguageTamil      = 11
	SMSNationalLanguageTelugu     = 12
	SMSNationalLanguageUrdu       = 13
)
View Source
const IMS3GPPSMSContentType = "application/vnd.3gpp.sms"
View Source
const IMSCPIMContentType = "message/cpim"
View Source
const IMSUSSDContentDisposition = "Info-Package"
View Source
const IMSUSSDContentType = "application/vnd.3gpp.ussd+xml"
View Source
const IMSUSSDInfoPackage = "g.3gpp.ussd"
View Source
const SMSRPCauseTemporaryFailure byte = 41

Variables

View Source
var ErrDeliveryNotFound = errors.New("delivery not found")
View Source
var ErrSMSTransportUnavailable = errors.New("sms transport unavailable")
View Source
var ErrUSSDTransportUnavailable = errors.New("ussd transport unavailable")

Functions

func BuildIMSCPIMIMDNMessageHeaders

func BuildIMSCPIMIMDNMessageHeaders(from, to, messageID string, notifications []string) map[string][]string

func BuildIMSCPIMMessage

func BuildIMSCPIMMessage(from, to, contentType string, body []byte) ([]byte, error)

func BuildIMSCPIMMessageWithHeaders

func BuildIMSCPIMMessageWithHeaders(messageHeaders, contentHeaders map[string][]string, body []byte) ([]byte, error)

func BuildIMSUSSDXML

func BuildIMSUSSDXML(payload IMSUSSDPayload) ([]byte, error)

func BuildSMSRPAck

func BuildSMSRPAck(rpMR byte) []byte

func BuildSMSRPAckWithTPDU

func BuildSMSRPAckWithTPDU(rpMR byte, tpdu []byte) ([]byte, error)

func BuildSMSRPData

func BuildSMSRPData(rpMR byte, smsc string, tpdu []byte) ([]byte, error)

func BuildSMSRPError

func BuildSMSRPError(rpMR byte, cause byte) []byte

func BuildSMSRPErrorWithDiagnostics

func BuildSMSRPErrorWithDiagnostics(rpMR byte, cause byte, diagnostics []byte, tpdu []byte) ([]byte, error)

func BuildSMSStatusReportTPDU

func BuildSMSStatusReportTPDU(report SMSStatusReport) ([]byte, error)

func BuildSMSSubmitTPDU

func BuildSMSSubmitTPDU(to string, part SMSPart, mr byte) ([]byte, error)

func IMSMessagingSMSSubmitIdempotencyKey

func IMSMessagingSMSSubmitIdempotencyKey(req SMSSendRequest) string

func IMSMessagingUSSDSessionKey

func IMSMessagingUSSDSessionKey(req USSDRequest) string

func IMSRegistrationRecoveryNeededStatus

func IMSRegistrationRecoveryNeededStatus(code int) bool

func IMSRegistrationRecoveryRetryAfter

func IMSRegistrationRecoveryRetryAfter(err error) time.Duration

func IsIMSRegistrationRecoveryError

func IsIMSRegistrationRecoveryError(err error) bool

func NormalizeIMSIMDNDispositionNotifications

func NormalizeIMSIMDNDispositionNotifications(values ...string) []string

func ParseSMSRPData

func ParseSMSRPData(body []byte) (rpMR byte, tpdu []byte, err error)

func ParseSMSRPErrorCause

func ParseSMSRPErrorCause(body []byte) (byte, error)

func RPCauseText

func RPCauseText(code int) string

func SMSStatusReportText

func SMSStatusReportText(status byte) string

func WithSuppressSendTGSuccess

func WithSuppressSendTGSuccess(ctx context.Context) context.Context

Types

type DeliveryPartMatch

type DeliveryPartMatch struct {
	MessageID string
	PartNo    int
	State     string
}

type DeliveryPartStatus

type DeliveryPartStatus struct {
	PartNo      int
	CallID      string
	InReplyTo   string
	RPMR        int
	State       string
	SIPCode     int
	RPCause     int
	RPCauseText string
	ErrorText   string
	SentAt      time.Time
	ReportAt    *time.Time
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

type DeliveryStatus

type DeliveryStatus struct {
	MessageID  string
	IMSI       string
	DeviceID   string
	Peer       string
	Content    string
	PartsTotal int
	Acks       int
	State      string
	LastError  string
	CreatedAt  time.Time
	UpdatedAt  time.Time
	Parts      []DeliveryPartStatus
}

type DeliveryStore

type DeliveryStore interface {
	CreateSMSDelivery(messageID, imsi, deviceID, peer, content string, partsTotal int, at time.Time) error
	UpsertSMSDeliveryPart(messageID string, partNo int, callID string, rpMR int, state string, sentAt time.Time) error
	MarkSMSDeliveryPartReport(inReplyTo, callID, deviceID string, rpMR int, state string, sipCode int, rpCause int, errText string, at time.Time) (DeliveryPartMatch, error)
	RecomputeSMSDelivery(messageID string, at time.Time) error
	UpdateSMSDeliveryState(messageID, state, lastError string, acks int, at time.Time) error
	GetSMSDeliveryStatus(messageID string) (*DeliveryStatus, error)
}

type IMSCPIMIMDNDispositionRequest

type IMSCPIMIMDNDispositionRequest struct {
	MessageID        string
	Notifications    []string
	PositiveDelivery bool
	NegativeDelivery bool
	Display          bool
	Processing       bool
	Required         bool
}

func IMSCPIMIMDNDispositionRequestFromHeaders

func IMSCPIMIMDNDispositionRequestFromHeaders(headers map[string][]string) IMSCPIMIMDNDispositionRequest

func ParseIMSCPIMIMDNDispositionRequest

func ParseIMSCPIMIMDNDispositionRequest(cpim IMSCPIMMessage) IMSCPIMIMDNDispositionRequest

func (IMSCPIMIMDNDispositionRequest) Requested

func (r IMSCPIMIMDNDispositionRequest) Requested() bool

type IMSCPIMMessage

type IMSCPIMMessage struct {
	Headers           map[string][]string
	ContentHeaders    map[string][]string
	ContentType       string
	ContentTypeParams map[string]string
	Body              []byte
}

func ParseIMSCPIMMessage

func ParseIMSCPIMMessage(body []byte) (IMSCPIMMessage, error)

type IMSMessageRequest

type IMSMessageRequest struct {
	FromURI     string
	ToURI       string
	CallID      string
	CSeq        int
	ContentType string
	Body        []byte
	Headers     map[string][]string
}

type IMSMessageResult

type IMSMessageResult struct {
	StatusCode         int
	Reason             string
	RPDU               SMSRPDU
	Incoming           *IncomingSMS
	DeliveryReport     *SMSDeliveryReport
	ReplyContentType   string
	ReplyBody          []byte
	UnsupportedContent bool
}

type IMSMessagingRecoveryCandidate

type IMSMessagingRecoveryCandidate struct {
	Kind              IMSMessagingRecoveryCandidateKind
	StatusCode        int
	URI               string
	RetryAfter        time.Duration
	RetryAfterPresent bool
	Weight            float64
}

IMSMessagingRecoveryCandidate is a sorted, local recovery option derived from SIP messaging failure metadata.

func IMSMessagingRecoveryCandidatesForSIPResponse

func IMSMessagingRecoveryCandidatesForSIPResponse(resp voiceclient.SIPResponse) []IMSMessagingRecoveryCandidate

IMSMessagingRecoveryCandidatesForSIPResponse extracts target and backoff hints from a SIP response. Candidates are returned from most to least useful for messaging recovery: direct target candidates first, higher q/weight first, and standalone Retry-After backoff only when no direct target is present.

type IMSMessagingRecoveryCandidateKind

type IMSMessagingRecoveryCandidateKind string
const (
	IMSMessagingRecoveryCandidateRetryAfter         IMSMessagingRecoveryCandidateKind = "retry-after"
	IMSMessagingRecoveryCandidateRedirectContact    IMSMessagingRecoveryCandidateKind = "redirect-contact"
	IMSMessagingRecoveryCandidateAlternativeService IMSMessagingRecoveryCandidateKind = "alternative-service"
)

type IMSMessagingRetryAction

type IMSMessagingRetryAction string
const (
	IMSMessagingRetryActionNone                  IMSMessagingRetryAction = "none"
	IMSMessagingRetryActionRetry                 IMSMessagingRetryAction = "retry"
	IMSMessagingRetryActionRetryAfter            IMSMessagingRetryAction = "retry-after"
	IMSMessagingRetryActionRefreshAuthentication IMSMessagingRetryAction = "refresh-authentication"
	IMSMessagingRetryActionRecoverRegistration   IMSMessagingRetryAction = "recover-registration"
	IMSMessagingRetryActionFailoverTarget        IMSMessagingRetryAction = "failover-target"
)

type IMSMessagingRetryClass

type IMSMessagingRetryClass string
const (
	IMSMessagingRetryClassAccepted         IMSMessagingRetryClass = "accepted"
	IMSMessagingRetryClassSuccess          IMSMessagingRetryClass = "success"
	IMSMessagingRetryClassRedirect         IMSMessagingRetryClass = "redirect"
	IMSMessagingRetryClassAuthentication   IMSMessagingRetryClass = "authentication"
	IMSMessagingRetryClassClientFailure    IMSMessagingRetryClass = "client-failure"
	IMSMessagingRetryClassThrottled        IMSMessagingRetryClass = "throttled"
	IMSMessagingRetryClassServerFailure    IMSMessagingRetryClass = "server-failure"
	IMSMessagingRetryClassSIPTimeout       IMSMessagingRetryClass = "sip-timeout"
	IMSMessagingRetryClassTransportFailure IMSMessagingRetryClass = "transport-failure"
	IMSMessagingRetryClassUnknown          IMSMessagingRetryClass = "unknown"
)

type IMSMessagingRetryDueStore

type IMSMessagingRetryDueStore interface {
	ListDueIMSMessagingRetries(now time.Time, limit int) ([]IMSMessagingRetryEnvelope, error)
}

type IMSMessagingRetryEnvelope

type IMSMessagingRetryEnvelope struct {
	Version        int                         `json:"version"`
	Key            string                      `json:"key"`
	Operation      IMSMessagingRetryOperation  `json:"operation"`
	Method         string                      `json:"method,omitempty"`
	State          IMSMessagingRetryQueueState `json:"state"`
	Attempt        int                         `json:"attempt"`
	NextAttempt    int                         `json:"next_attempt,omitempty"`
	IdempotencyKey string                      `json:"idempotency_key,omitempty"`
	SessionKey     string                      `json:"session_key,omitempty"`
	DueAt          time.Time                   `json:"due_at,omitempty"`
	CreatedAt      time.Time                   `json:"created_at,omitempty"`
	UpdatedAt      time.Time                   `json:"updated_at,omitempty"`
	TerminalAt     time.Time                   `json:"terminal_at,omitempty"`
	LastError      string                      `json:"last_error,omitempty"`
	Plan           IMSMessagingRetryPlan       `json:"plan"`
	Payload        IMSMessagingRetryPayload    `json:"payload,omitempty"`
}

func NewIMSUSSDSessionRetryEnvelope

func NewIMSUSSDSessionRetryEnvelope(req USSDRequest, result USSDResult, err error, opts IMSMessagingRetryOptions) IMSMessagingRetryEnvelope

func SelectDueIMSMessagingRetryEnvelopes

func SelectDueIMSMessagingRetryEnvelopes(envelopes []IMSMessagingRetryEnvelope, now time.Time, limit int) []IMSMessagingRetryEnvelope

func (IMSMessagingRetryEnvelope) Due

func (IMSMessagingRetryEnvelope) Pending

func (e IMSMessagingRetryEnvelope) Pending() bool

func (IMSMessagingRetryEnvelope) ReplayReady

func (e IMSMessagingRetryEnvelope) ReplayReady(now time.Time) bool

func (IMSMessagingRetryEnvelope) SMSSubmitRequest

func (e IMSMessagingRetryEnvelope) SMSSubmitRequest() (SMSSendRequest, bool)

func (IMSMessagingRetryEnvelope) Terminal

func (e IMSMessagingRetryEnvelope) Terminal() bool

func (IMSMessagingRetryEnvelope) USSDRequest

func (e IMSMessagingRetryEnvelope) USSDRequest() (USSDRequest, bool)

type IMSMessagingRetryInput

type IMSMessagingRetryInput struct {
	Operation      IMSMessagingRetryOperation
	Method         string
	Response       voiceclient.SIPResponse
	Err            error
	Attempt        int
	Policy         IMSMessagingRetryPolicy
	Now            time.Time
	IdempotencyKey string
	SessionKey     string
}

type IMSMessagingRetryOperation

type IMSMessagingRetryOperation string
const (
	IMSMessagingRetryOperationSMSSubmit   IMSMessagingRetryOperation = "sms-submit"
	IMSMessagingRetryOperationUSSDSession IMSMessagingRetryOperation = "ussd-session"
)

type IMSMessagingRetryOptions

type IMSMessagingRetryOptions struct {
	Method         string
	Attempt        int
	Policy         IMSMessagingRetryPolicy
	Now            time.Time
	IdempotencyKey string
	SessionKey     string
}

type IMSMessagingRetryPayload

type IMSMessagingRetryPayload struct {
	SMSSubmit *SMSSendRequest `json:"sms_submit,omitempty"`
	USSD      *USSDRequest    `json:"ussd,omitempty"`
}

type IMSMessagingRetryPlan

type IMSMessagingRetryPlan struct {
	Operation                         IMSMessagingRetryOperation `json:"operation"`
	Method                            string                     `json:"method,omitempty"`
	StatusCode                        int                        `json:"status_code,omitempty"`
	Class                             IMSMessagingRetryClass     `json:"class"`
	Action                            IMSMessagingRetryAction    `json:"action"`
	Retry                             bool                       `json:"retry"`
	Terminal                          bool                       `json:"terminal"`
	Durable                           bool                       `json:"durable"`
	Attempt                           int                        `json:"attempt"`
	NextAttempt                       int                        `json:"next_attempt,omitempty"`
	MaxAttempts                       int                        `json:"max_attempts"`
	Delay                             time.Duration              `json:"delay,omitempty"`
	RetryAfter                        time.Duration              `json:"retry_after,omitempty"`
	RetryAfterPresent                 bool                       `json:"retry_after_present,omitempty"`
	NextAttemptAt                     time.Time                  `json:"next_attempt_at,omitempty"`
	RetryKey                          string                     `json:"retry_key,omitempty"`
	IdempotencyKey                    string                     `json:"idempotency_key,omitempty"`
	SessionKey                        string                     `json:"session_key,omitempty"`
	TargetURI                         string                     `json:"target_uri,omitempty"`
	TargetFailover                    bool                       `json:"target_failover,omitempty"`
	RegistrationRecoveryNeeded        bool                       `json:"registration_recovery_needed,omitempty"`
	AuthenticationRefresh             bool                       `json:"authentication_refresh,omitempty"`
	AuthenticationChallengeHeader     string                     `json:"authentication_challenge_header,omitempty"`
	AuthenticationChallenge           string                     `json:"authentication_challenge,omitempty"`
	AuthenticationAuthorizationHeader string                     `json:"authentication_authorization_header,omitempty"`
	TransportFailure                  bool                       `json:"transport_failure,omitempty"`
	TimedOut                          bool                       `json:"timed_out,omitempty"`
	FinalResponseTimeout              bool                       `json:"final_response_timeout,omitempty"`
	DuplicateRisk                     bool                       `json:"duplicate_risk,omitempty"`
	Reason                            string                     `json:"reason,omitempty"`
}

IMSMessagingRetryPlan is intentionally durable: it contains no function pointers or transient transport state, so callers can JSON-encode and replay the decision from a local queue.

func PlanIMSMessagingRetry

func PlanIMSMessagingRetry(input IMSMessagingRetryInput) IMSMessagingRetryPlan

func PlanIMSUSSDSessionRetry

func PlanIMSUSSDSessionRetry(req USSDRequest, result USSDResult, err error, opts IMSMessagingRetryOptions) IMSMessagingRetryPlan

type IMSMessagingRetryPolicy

type IMSMessagingRetryPolicy struct {
	MaxAttempts int           `json:"max_attempts,omitempty"`
	BaseDelay   time.Duration `json:"base_delay,omitempty"`
	MaxDelay    time.Duration `json:"max_delay,omitempty"`
}

func DefaultIMSMessagingRetryPolicy

func DefaultIMSMessagingRetryPolicy() IMSMessagingRetryPolicy

type IMSMessagingRetryQueue

type IMSMessagingRetryQueue struct {
	Envelopes []IMSMessagingRetryEnvelope `json:"envelopes,omitempty"`
}

func (*IMSMessagingRetryQueue) Delete

func (q *IMSMessagingRetryQueue) Delete(operation IMSMessagingRetryOperation, key string)

func (IMSMessagingRetryQueue) Due

func (*IMSMessagingRetryQueue) Upsert

type IMSMessagingRetryQueueState

type IMSMessagingRetryQueueState string
const (
	IMSMessagingRetryQueueStatePending  IMSMessagingRetryQueueState = "pending"
	IMSMessagingRetryQueueStateTerminal IMSMessagingRetryQueueState = "terminal"
)

type IMSMessagingRetryReplayResult

type IMSMessagingRetryReplayResult struct {
	Envelope      IMSMessagingRetryEnvelope
	NextEnvelope  IMSMessagingRetryEnvelope
	Replayed      bool
	Upserted      bool
	Deleted       bool
	DuplicateRisk bool
	SMSResult     SMSSendResult
	USSDResult    USSDResult
	Err           error
}

type IMSMessagingRetryStore

type IMSMessagingRetryStore interface {
	UpsertIMSMessagingRetry(IMSMessagingRetryEnvelope) error
	DeleteIMSMessagingRetry(operation IMSMessagingRetryOperation, key string) error
}

type IMSMessagingSIPRecoveryDecision

type IMSMessagingSIPRecoveryDecision struct {
	Method                            string
	StatusCode                        int
	RetryAfter                        time.Duration
	RetryAfterPresent                 bool
	Recoverable                       bool
	TargetFailover                    bool
	RegistrationRecoveryNeeded        bool
	AuthenticationRefresh             bool
	AuthenticationChallengeHeader     string
	AuthenticationChallenge           string
	AuthenticationAuthorizationHeader string
	RedirectURI                       string
	Candidates                        []IMSMessagingRecoveryCandidate
	FailureText                       string
}

IMSMessagingSIPRecoveryDecision describes the messaging-layer recovery action for a SIP response to SMS MESSAGE or USSD dialog requests.

func ClassifyIMSMessagingSIPResponseRecovery

func ClassifyIMSMessagingSIPResponseRecovery(method string, resp voiceclient.SIPResponse) IMSMessagingSIPRecoveryDecision

ClassifyIMSMessagingSIPResponseRecovery maps the generic SIP response recovery plan into SMS/USSD messaging decisions while preserving the legacy registration recovery statuses used by older runtime hosts.

type IMSRegistrationRecoveryError

type IMSRegistrationRecoveryError struct {
	Err        error
	StatusCode int
	RetryAfter time.Duration
}

func (IMSRegistrationRecoveryError) Error

func (IMSRegistrationRecoveryError) Unwrap

type IMSSMSTransport

type IMSSMSTransport struct {
	Transport            voiceclient.SIPRequestTransport
	Profile              voiceclient.IMSProfile
	Registration         voiceclient.RegistrationBinding
	Domain               string
	LocalURI             string
	ContactURI           string
	RemoteTargetURI      string
	UserAgent            string
	ContentType          string
	SMSC                 string
	UseCPIM              bool
	IMDNNotifications    []string
	DisableStatusReports bool
}

func (IMSSMSTransport) SendSMSPart

func (t IMSSMSTransport) SendSMSPart(ctx context.Context, req SMSSendRequest) (SMSSendResult, error)

type IMSUSSDDialogRequest

type IMSUSSDDialogRequest struct {
	URI         string
	FromURI     string
	ToURI       string
	CallID      string
	CSeq        int
	ContentType string
	InfoPackage string
	Body        []byte
	Headers     map[string][]string
}

type IMSUSSDDialogResult

type IMSUSSDDialogResult struct {
	Handled     bool
	StatusCode  int
	Reason      string
	ContentType string
	Body        []byte
	Headers     map[string]string
	USSD        USSDResult
}

type IMSUSSDDialogTransport

type IMSUSSDDialogTransport interface {
	HandleIMSInfo(context.Context, IMSUSSDDialogRequest) (IMSUSSDDialogResult, error)
	HandleIMSBye(context.Context, IMSUSSDDialogRequest) (IMSUSSDDialogResult, error)
}

type IMSUSSDOperation

type IMSUSSDOperation string
const (
	IMSUSSDOperationRequest  IMSUSSDOperation = "request"
	IMSUSSDOperationResponse IMSUSSDOperation = "response"
	IMSUSSDOperationNotify   IMSUSSDOperation = "notify"
	IMSUSSDOperationRelease  IMSUSSDOperation = "release"
)

type IMSUSSDPayload

type IMSUSSDPayload struct {
	Language            string
	Text                string
	Operation           IMSUSSDOperation
	ErrorCode           int
	HasError            bool
	AlertingPattern     int
	HasAlertingPattern  bool
	RawOperationElement string
}

func DecodeIMSUSSDDocument

func DecodeIMSUSSDDocument(contentType string, body []byte) (IMSUSSDPayload, bool, error)

func ParseIMSUSSDXML

func ParseIMSUSSDXML(body []byte) (IMSUSSDPayload, error)

type IMSUSSDTransport

type IMSUSSDTransport struct {
	Transport       voiceclient.SIPRequestTransport
	Profile         voiceclient.IMSProfile
	Registration    voiceclient.RegistrationBinding
	Domain          string
	LocalURI        string
	ContactURI      string
	RemoteTargetURI string
	UserAgent       string
	LocalTag        string
	Language        string
	SessionExpires  int
	// contains filtered or unexported fields
}

func (*IMSUSSDTransport) CancelUSSD

func (t *IMSUSSDTransport) CancelUSSD(ctx context.Context, req USSDRequest) error

func (*IMSUSSDTransport) ContinueUSSD

func (t *IMSUSSDTransport) ContinueUSSD(ctx context.Context, req USSDRequest) (USSDResult, error)

func (*IMSUSSDTransport) ExecuteUSSD

func (t *IMSUSSDTransport) ExecuteUSSD(ctx context.Context, req USSDRequest) (USSDResult, error)

func (*IMSUSSDTransport) HandleIMSBye

func (*IMSUSSDTransport) HandleIMSInfo

type IncomingSMS

type IncomingSMS struct {
	Sender                 string
	Recipient              string
	Content                string
	Timestamp              time.Time
	ProtocolID             byte
	DataCodingScheme       byte
	DataCoding             SMSDataCodingInfo
	UserDataHeader         bool
	UserDataHeaderInfo     SMSUserDataHeaderInfo
	MoreMessagesToSend     bool
	StatusReportIndication bool
	ReplyPath              bool
}

type SMSConcatInfo

type SMSConcatInfo struct {
	IsConcat bool
	Ref      int
	RefBits  int
	Total    int
	Seq      int
}

type SMSDataCodingInfo

type SMSDataCodingInfo struct {
	Raw                   byte
	Alphabet              string
	Compressed            bool
	AutoDelete            bool
	HasMessageClass       bool
	MessageClass          int
	MessageWaiting        bool
	MessageWaitingActive  bool
	MessageWaitingDiscard bool
	MessageWaitingType    string
	Reserved              bool
}

func ParseSMSDataCodingScheme

func ParseSMSDataCodingScheme(dcs byte) SMSDataCodingInfo

type SMSDeliver

type SMSDeliver struct {
	Sender                 string
	Recipient              string
	Text                   string
	Timestamp              time.Time
	Concat                 SMSConcatInfo
	FirstOctet             byte
	ProtocolID             byte
	DataCodingScheme       byte
	DataCoding             SMSDataCodingInfo
	UserDataLength         int
	UserDataHeader         bool
	UserDataHeaderInfo     SMSUserDataHeaderInfo
	MoreMessagesToSend     bool
	StatusReportIndication bool
	ReplyPath              bool
	RawTPDU                []byte
}

func ParseSMSDeliverTPDU

func ParseSMSDeliverTPDU(tpdu []byte) (SMSDeliver, error)

type SMSDeliveryReport

type SMSDeliveryReport struct {
	InReplyTo             string
	CallID                string
	RPMR                  int
	State                 string
	SIPCode               int
	RPCause               int
	ErrorText             string
	ReportAt              time.Time
	Recipient             string
	SentAt                time.Time
	FirstOctet            byte
	MoreMessagesToSend    bool
	StatusReportQualifier bool
	UserDataHeader        bool
	UserDataHeaderInfo    SMSUserDataHeaderInfo
	ParameterIndicator    byte
	ProtocolID            byte
	DataCodingScheme      byte
	DataCoding            SMSDataCodingInfo
	UserData              string
}

type SMSPart

type SMSPart struct {
	PartNo                int
	TotalParts            int
	Text                  string
	Encoding              string
	UDH                   []byte
	ValidityPeriod        time.Duration
	ValidityDeadline      time.Time
	ProtocolID            byte
	DataCodingScheme      byte
	UseProtocolID         bool
	UseDataCodingScheme   bool
	ReplyPath             bool
	RejectDuplicates      bool
	ConcatRef             int
	ConcatRefBits         int
	ApplicationDestPort   int
	ApplicationSourcePort int
	ApplicationPortBits   int
	SingleShiftLang       int
	LockingShiftLang      int
	RequestStatusReport   bool
}

func SegmentSMS

func SegmentSMS(text, encoding string) []SMSPart

func SegmentSMSWithOptions

func SegmentSMSWithOptions(text string, opts SendOptions) []SMSPart

type SMSRPCauseClass

type SMSRPCauseClass string
const (
	SMSRPCauseClassUnknown          SMSRPCauseClass = ""
	SMSRPCauseClassAddressing       SMSRPCauseClass = "addressing"
	SMSRPCauseClassBarring          SMSRPCauseClass = "barring"
	SMSRPCauseClassSubscriber       SMSRPCauseClass = "subscriber"
	SMSRPCauseClassTemporaryNetwork SMSRPCauseClass = "temporary-network"
	SMSRPCauseClassFacility         SMSRPCauseClass = "facility"
	SMSRPCauseClassProtocol         SMSRPCauseClass = "protocol"
	SMSRPCauseClassInterworking     SMSRPCauseClass = "interworking"
)

type SMSRPCauseDisposition

type SMSRPCauseDisposition struct {
	Cause                   int
	Class                   SMSRPCauseClass
	Text                    string
	Temporary               bool
	Permanent               bool
	Retryable               bool
	Terminal                bool
	RegistrationRecoverable bool
	SubscriberActionNeeded  bool
	ProtocolError           bool
}

SMSRPCauseDisposition describes retry and finality metadata for RP-ERROR causes.

func ClassifySMSRPCause

func ClassifySMSRPCause(cause int) SMSRPCauseDisposition

type SMSRPDU

type SMSRPDU struct {
	Kind             SMSRPDUKind
	RawType          byte
	MR               byte
	Cause            int
	CauseDiagnostics []byte
	Originator       string
	Destination      string
	TPDU             []byte
}

func ParseSMSRPDU

func ParseSMSRPDU(body []byte) (SMSRPDU, error)

type SMSRPDUKind

type SMSRPDUKind string
const (
	SMSRPDUKindUnknown SMSRPDUKind = "UNKNOWN"
	SMSRPDUKindData    SMSRPDUKind = "RP-DATA"
	SMSRPDUKindAck     SMSRPDUKind = "RP-ACK"
	SMSRPDUKindError   SMSRPDUKind = "RP-ERROR"
)

type SMSSMSCControlParameters

type SMSSMSCControlParameters struct {
	Raw                                      byte
	StatusReportTransactionCompleted         bool
	StatusReportPermanentError               bool
	StatusReportTemporaryErrorNoMoreAttempts bool
	StatusReportTemporaryErrorMoreAttempts   bool
	CancelSRRForRemainingConcatParts         bool
	IncludeOriginalUDHInStatusReport         bool
	ReservedBits                             byte
}

type SMSSendRequest

type SMSSendRequest struct {
	DeviceID  string
	IMSI      string
	Peer      string
	MessageID string
	Part      SMSPart
}

type SMSSendResult

type SMSSendResult struct {
	CallID                     string
	RPMR                       int
	State                      string
	SIPCode                    int
	ErrorText                  string
	RegistrationRecoveryNeeded bool
	RetryAfter                 time.Duration
}

type SMSSpecialMessageIndication

type SMSSpecialMessageIndication struct {
	Raw          byte
	StoreMessage bool
	ProfileID    int
	BasicType    int
	ExtendedType int
	MessageType  string
	Count        int
	Active       bool
	ReservedType bool
}

type SMSStatusReport

type SMSStatusReport struct {
	Reference             byte
	Recipient             string
	Timestamp             time.Time
	DoneAt                time.Time
	Status                byte
	State                 string
	FirstOctet            byte
	MoreMessagesToSend    bool
	StatusReportQualifier bool
	UserDataHeader        bool
	ParameterIndicator    byte
	HasParameterIndicator bool
	ProtocolID            byte
	HasProtocolID         bool
	DataCodingScheme      byte
	HasDataCodingScheme   bool
	DataCoding            SMSDataCodingInfo
	UserDataLength        int
	UserDataHeaderInfo    SMSUserDataHeaderInfo
	UserData              string
	HasUserData           bool
	RawTPDU               []byte
}

func ParseSMSStatusReportTPDU

func ParseSMSStatusReportTPDU(tpdu []byte) (SMSStatusReport, error)

type SMSStatusReportClass

type SMSStatusReportClass string

SMSStatusReportClass groups TP-ST values into the delivery classes defined for SMS-STATUS-REPORT.

const (
	SMSStatusReportClassCompleted         SMSStatusReportClass = "completed"
	SMSStatusReportClassTemporaryRetrying SMSStatusReportClass = "temporary-retrying"
	SMSStatusReportClassPermanentFailure  SMSStatusReportClass = "permanent-failure"
	SMSStatusReportClassTemporaryFailure  SMSStatusReportClass = "temporary-failure"
	SMSStatusReportClassReserved          SMSStatusReportClass = "reserved"
)

type SMSStatusReportDisposition

type SMSStatusReportDisposition struct {
	Status                byte
	Class                 SMSStatusReportClass
	State                 string
	Text                  string
	Delivered             bool
	Failed                bool
	Temporary             bool
	Permanent             bool
	ServiceCenterRetrying bool
	Terminal              bool
	Retryable             bool
	Reserved              bool
}

SMSStatusReportDisposition describes carrier retry and finality metadata for an SMS-STATUS-REPORT TP-ST value.

func ClassifySMSStatusReport

func ClassifySMSStatusReport(status byte) SMSStatusReportDisposition

type SMSTransport

type SMSTransport interface {
	SendSMSPart(context.Context, SMSSendRequest) (SMSSendResult, error)
}

type SMSUDHElement

type SMSUDHElement struct {
	Identifier byte
	Data       []byte
}

type SMSUDHSourceIndicator

type SMSUDHSourceIndicator struct {
	Value       int
	Description string
}

type SMSUserDataHeaderInfo

type SMSUserDataHeaderInfo struct {
	Raw                       []byte
	Elements                  []SMSUDHElement
	Concat                    SMSConcatInfo
	HasPorts                  bool
	DestinationPort           int
	SourcePort                int
	PortBits                  int
	SpecialMessageIndications []SMSSpecialMessageIndication
	HasSMSCControl            bool
	SMSCControl               SMSSMSCControlParameters
	SourceIndicators          []SMSUDHSourceIndicator
	HasRFC822EmailHeader      bool
	RFC822EmailHeaderLength   int
	HasSingleShift            bool
	SingleShiftLang           int
	HasLockingShift           bool
	LockingShiftLang          int
}

type SendOptions

type SendOptions struct {
	Encoding              string
	ValidityPeriod        time.Duration
	ValidityDeadline      time.Time
	ProtocolID            byte
	DataCodingScheme      byte
	UseProtocolID         bool
	UseDataCodingScheme   bool
	ReplyPath             bool
	RejectDuplicates      bool
	ConcatRef             int
	ConcatRefBits         int
	ApplicationDestPort   int
	ApplicationSourcePort int
	ApplicationPortBits   int
	SingleShiftLang       int
	LockingShiftLang      int
}

type SendOutcome

type SendOutcome struct {
	MessageID     string `json:"message_id,omitempty"`
	Parts         int    `json:"parts,omitempty"`
	PartsTotal    int    `json:"parts_total,omitempty"`
	State         string `json:"state,omitempty"`
	DeliveryState string `json:"delivery_state,omitempty"`
}

type Service

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

func NewService

func NewService(deviceID, imsi string, store DeliveryStore, dispatch eventhost.Dispatcher) *Service

func (*Service) CancelUSSD

func (s *Service) CancelUSSD(ctx context.Context, sessionID string) error

func (*Service) ContinueUSSD

func (s *Service) ContinueUSSD(ctx context.Context, sessionID, input string) (*USSDResult, error)

func (*Service) GetSMSDeliveryStatus

func (s *Service) GetSMSDeliveryStatus(messageID string) (*DeliveryStatus, error)

func (*Service) HandleIMSMessage

func (s *Service) HandleIMSMessage(ctx context.Context, msg IMSMessageRequest) (IMSMessageResult, error)

func (*Service) HandleIMSUSSDBye

func (s *Service) HandleIMSUSSDBye(ctx context.Context, req IMSUSSDDialogRequest) (IMSUSSDDialogResult, error)

func (*Service) HandleIMSUSSDInfo

func (s *Service) HandleIMSUSSDInfo(ctx context.Context, req IMSUSSDDialogRequest) (IMSUSSDDialogResult, error)

func (*Service) HandleIncomingSMS

func (s *Service) HandleIncomingSMS(ctx context.Context, msg IncomingSMS) error

func (*Service) HandleSMSDeliveryReport

func (s *Service) HandleSMSDeliveryReport(ctx context.Context, report SMSDeliveryReport) (DeliveryPartMatch, error)

func (*Service) ReplayDueIMSMessagingRetries

func (s *Service) ReplayDueIMSMessagingRetries(ctx context.Context, envelopes []IMSMessagingRetryEnvelope, now time.Time, limit int) ([]IMSMessagingRetryReplayResult, error)

func (*Service) ReplayDueIMSMessagingRetriesFromStore

func (s *Service) ReplayDueIMSMessagingRetriesFromStore(ctx context.Context, now time.Time, limit int) ([]IMSMessagingRetryReplayResult, error)

func (*Service) ReplayIMSMessagingRetry

func (s *Service) ReplayIMSMessagingRetry(ctx context.Context, envelope IMSMessagingRetryEnvelope, now time.Time) (IMSMessagingRetryReplayResult, error)

func (*Service) SendSMSWithOptions

func (s *Service) SendSMSWithOptions(ctx context.Context, to, text string, opts SendOptions) (SendOutcome, error)

func (*Service) SendUSSD

func (s *Service) SendUSSD(ctx context.Context, command string) (*USSDResult, error)

func (*Service) SetSMSTransport

func (s *Service) SetSMSTransport(t SMSTransport)

func (*Service) SetUSSDTransport

func (s *Service) SetUSSDTransport(t USSDTransport)

type USSDRequest

type USSDRequest struct {
	DeviceID  string
	IMSI      string
	SessionID string
	Command   string
	Input     string
}

type USSDResult

type USSDResult struct {
	SessionID                  string        `json:"session_id,omitempty"`
	Text                       string        `json:"text,omitempty"`
	RawText                    string        `json:"raw_text,omitempty"`
	Status                     int           `json:"status,omitempty"`
	DCS                        int           `json:"dcs,omitempty"`
	Done                       bool          `json:"done"`
	RegistrationRecoveryNeeded bool          `json:"registration_recovery_needed,omitempty"`
	RetryAfter                 time.Duration `json:"retry_after,omitempty"`
}

type USSDTransport

type USSDTransport interface {
	ExecuteUSSD(context.Context, USSDRequest) (USSDResult, error)
	ContinueUSSD(context.Context, USSDRequest) (USSDResult, error)
	CancelUSSD(context.Context, USSDRequest) error
}

Jump to

Keyboard shortcuts

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