model

package
v0.0.0-...-df4207d Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StagePlatform       = "platform"
	StageQueue          = "queue"
	StageQueueResponse  = "queue.response"
	StageCarrier        = "carrier"
	StageCarrierReceipt = "carrier.receipt"
)
View Source
const NotFoundProvider = "_not_found_"

Variables

This section is empty.

Functions

func Now

func Now() time.Time

Now return the current time.Time with microsecond precision.

Types

type JSON

type JSON json.RawMessage

JSON is a json.RawMessage, which is a []byte underneath. Value() validates the json format in the source, and returns an error if the json is not valid. Scan does no validation. JSON additionally implements `Unmarshal`, which unmarshals the json within to an interface{}

See https://github.com/jmoiron/sqlx/blob/master/types/types.go

func MarshalJSON

func MarshalJSON(v interface{}) JSON

MarshalJSON returns the JSON encoding of v.

func (JSON) MarshalJSON

func (j JSON) MarshalJSON() ([]byte, error)

MarshalJSON returns the *j as the JSON encoding of j.

func (*JSON) Scan

func (j *JSON) Scan(src interface{}) error

Scan stores the src in *j. No validation is done.

func (JSON) String

func (j JSON) String() string

String supports pretty printing for JSON types.

func (*JSON) Unmarshal

func (j *JSON) Unmarshal(v interface{}) error

Unmarshal unmarshal's the json in j to v, as in json.Unmarshal.

func (*JSON) UnmarshalJSON

func (j *JSON) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *j to a copy of data

func (JSON) Value

func (j JSON) Value() (driver.Value, error)

Value returns j as a value. This does a validating unmarshal into another RawMessage. If j is invalid json, it returns an error.

type Message

type Message struct {
	ID                string     `json:"id"`                 // Message ID
	To                string     `json:"to" db:"toNumber"`   // The destination phone number (E.164 format)
	From              string     `json:"from" db:"fromName"` // Sender ID (phone number or alphanumeric)
	Body              string     `json:"body"`               // The text of the message
	Async             bool       `json:"async"`              // Enable a background sending mode that is optimized for bulk sending
	Route             *string    `json:"route"`
	Provider          *string    `json:"provider"`
	ProviderMessageID *string    `json:"provider_message_id" db:"providerMessageId"`
	Steps             JSON       `json:"steps"`
	Status            StatusCode `json:"status"`
	CreatedTime       time.Time  `json:"created_time" db:"createdTime"`
	UpdatedTime       *time.Time `json:"updated_time" db:"updatedTime"`
}

func NewMessage

func NewMessage(to, from, body string, async bool) *Message

func (*Message) AddStep

func (m *Message) AddStep(step MessageStep)

func (*Message) GetSteps

func (m *Message) GetSteps() []MessageStep

func (*Message) HandleStep

func (m *Message) HandleStep(wrap MessageStepWrap)

func (*Message) SetSteps

func (m *Message) SetSteps(steps []MessageStep)

type MessageJob

type MessageJob struct {
	Message
	Result chan Message
}

func NewMessageJob

func NewMessageJob(to, from, body string, async bool) *MessageJob

type MessageReceipt

type MessageReceipt struct {
	MessageStep
	ProviderMessageID string
	Provider          string
}

func NewMessageReceipt

func NewMessageReceipt(providerMessageID, provider string, status StatusCode, receipt interface{}) *MessageReceipt

type MessageResponse

type MessageResponse struct {
	MessageStep
	ProviderMessageID *string
}

func NewMessageResponse

func NewMessageResponse(status StatusCode, response interface{}, providerMessageID *string) *MessageResponse

type MessageStep

type MessageStep struct {
	Stage       string      `json:"stage"`
	Data        interface{} `json:"data"`
	Status      StatusCode  `json:"status"`
	CreatedTime time.Time   `json:"created_time" db:"createdTime"`
}

func NewMessageStepSending

func NewMessageStepSending() *MessageStep

func (MessageStep) GetStep

func (ms MessageStep) GetStep() MessageStep

type MessageStepWrap

type MessageStepWrap interface {
	GetStep() MessageStep
}

type Provider

type Provider interface {
	Name() string
	Send(message Message) *MessageResponse
	Callback(register func(webhook *Webhook), receipts chan<- MessageReceipt)
}

type ProviderError

type ProviderError struct {
	Error string `json:"error"`
}

type Route

type Route struct {
	ID       int64  `json:"-"`
	Name     string `json:"name"`
	Pattern  string `json:"pattern"`
	Provider string `json:"provider"`
	From     string `json:"from" db:"fromName"`
	IsActive bool   `json:"is_active" db:"isActive"`
	// contains filtered or unexported fields
}

func NewRoute

func NewRoute(name, pattern string, provider Provider, isActive bool) *Route

NewRoute creates a new instance of the Route.

func (*Route) GetProvider

func (r *Route) GetProvider() Provider

func (*Route) Match

func (r *Route) Match(recipient string) bool

Match matches the route against the recipient phone number.

func (*Route) SetFrom

func (r *Route) SetFrom(from string) *Route

func (*Route) SetPattern

func (r *Route) SetPattern(pattern string) *Route

func (*Route) SetProvider

func (r *Route) SetProvider(provider Provider) *Route

type Stats

type Stats struct {
	Time         int64  `json:"time"`
	GoVersion    string `json:"go_version"`
	GoMaxProcs   int    `json:"go_max_procs"`
	NumCPU       int    `json:"num_cpu"`
	NumGoroutine int    `json:"num_goroutine"`
	MemSys       uint64 `json:"mem_sys"`
}

func NewStats

func NewStats() *Stats

type StatusCode

type StatusCode int
const (
	StatusInit        StatusCode = iota // Default status, This should not be exported to client
	StatusAccepted                      // Received your API request to send a message
	StatusQueued                        // The message is queued to be sent out
	StatusSending                       // The message is in the process of dispatching to the upstream carrier
	StatusFailed                        // The message could not be sent to the upstream carrier
	StatusSent                          // The message was successfully accepted by the upstream carrie
	StatusUnknown                       // Received an undocumented status code from the upstream carrier
	StatusUndelivered                   // Received that the message was not delivered from the upstream carrier
	StatusDelivered                     // Received confirmation of message delivery from the upstream carrier
)

Status

func (StatusCode) MarshalJSON

func (c StatusCode) MarshalJSON() ([]byte, error)

func (*StatusCode) Scan

func (c *StatusCode) Scan(src interface{}) error

func (StatusCode) String

func (c StatusCode) String() string

func (*StatusCode) UnmarshalJSON

func (c *StatusCode) UnmarshalJSON(data []byte) error

func (StatusCode) Value

func (c StatusCode) Value() (driver.Value, error)

type Webhook

type Webhook struct {
	Path   string
	Func   func(http.ResponseWriter, *http.Request)
	Method string
}

Webhook represents a webhook endpoint.

Jump to

Keyboard shortcuts

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