models

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2018 License: AGPL-3.0 Imports: 15 Imported by: 10

Documentation

Index

Constants

View Source
const StatusPending = MsgStatus("P")
View Source
const StatusQueued = MsgStatus("Q")

Variables

View Source
var (
	ExitInterrupted = null.NewString("I", true)
	ExitCompleted   = null.NewString("C", true)
	ExitExpired     = null.NewString("E", true)
)

Functions

func ApplyEvent

func ApplyEvent(ctx context.Context, tx *sqlx.Tx, org *OrgAssets, session *Session, run *FlowRun, e flows.Event) error

func ApplyMsgCreatedEvent

func ApplyMsgCreatedEvent(ctx context.Context, tx *sqlx.Tx, org *OrgAssets, session *Session, run *FlowRun, event *events.MsgCreatedEvent) error

func LoadContact

func LoadContact(o *OrgAssets, id ContactID) (*flows.Contact, error)

LoadContact loads a contact for the passed in contact id and org assets

func MarkCampaignEventFired

func MarkCampaignEventFired(ctx context.Context, db *sqlx.DB, fireID int, fired time.Time) error

func MarkMessagesQueued added in v0.0.2

func MarkMessagesQueued(ctx context.Context, db *sqlx.DB, msgs []*Msg) error

Types

type ChannelID

type ChannelID int

type ConnectionID

type ConnectionID null.Int

type ContactID

type ContactID int

type ContactURNID

type ContactURNID int

type ExitType

type ExitType null.String

type FlowDefinition

type FlowDefinition struct {
	Definition string `db:"definition"`
	ID         FlowID `db:"id"`
}

type FlowID

type FlowID int64

type FlowRun

type FlowRun struct {
	ID         FlowID        `db:"id"`
	UUID       flows.RunUUID `db:"uuid"`
	IsActive   bool          `db:"is_active"`
	CreatedOn  time.Time     `db:"created_on"`
	ModifiedOn time.Time     `db:"modified_on"`
	ExitedOn   *time.Time    `db:"exited_on"`
	ExitType   null.String   `db:"exit_type"`
	ExpiresOn  *time.Time    `db:"expires_on"`
	TimeoutOn  *time.Time    `db:"timeout_on"`
	Responded  bool          `db:"responded"`

	// TODO: should this be a complex object that can read / write iself to the DB as JSON?
	Results string `db:"results"`

	// TODO: should this be a complex object that can read / write iself to the DB as JSON?
	Path string `db:"path"`

	// TODO: should this be a complex object that can read / write iself to the DB as JSON?
	Events          string         `db:"events"`
	CurrentNodeUUID flows.NodeUUID `db:"current_node_uuid"`
	ContactID       int            `db:"contact_id"`
	FlowID          FlowID         `db:"flow_id"`
	OrgID           OrgID          `db:"org_id"`
	ParentID        null.Int       `db:"parent_id"`
	SessionID       SessionID      `db:"session_id"`
	StartID         null.Int       `db:"start_id"`
}

func CreateRun

func CreateRun(ctx context.Context, tx *sqlx.Tx, org *OrgAssets, session *Session, r flows.FlowRun) (*FlowRun, error)

type Msg

type Msg struct {
	ID           MsgID             `db:"id"              json:"id"`
	UUID         flows.MsgUUID     `db:"uuid"            json:"uuid"`
	Text         string            `db:"text"            json:"text"`
	HighPriority bool              `db:"high_priority"   json:"high_priority"`
	CreatedOn    time.Time         `db:"created_on"      json:"created_on"`
	ModifiedOn   time.Time         `db:"modified_on"     json:"modified_on"`
	SentOn       time.Time         `db:"sent_on"         json:"sent_on"`
	QueuedOn     time.Time         `db:"queued_on"       json:"queued_on"`
	Direction    MsgDirection      `db:"direction"       json:"direction"`
	Status       MsgStatus         `db:"status"          json:"status"`
	Visibility   MsgVisibility     `db:"visibility"      json:"visibility"`
	MsgType      MsgType           `db:"msg_type"`
	MsgCount     int               `db:"msg_count"       json:"tps_cost"`
	ErrorCount   int               `db:"error_count"     json:"error_count"`
	NextAttempt  time.Time         `db:"next_attempt"    json:"next_attempt"`
	ExternalID   null.String       `db:"external_id"     json:"external_id"`
	Attachments  []string          `db:"attachments"     json:"attachments"`
	Metadata     null.String       `db:"metadata"        json:"metadata"`
	ChannelID    ChannelID         `db:"channel_id"      json:"channel_id"`
	ChannelUUID  flows.ChannelUUID `                     json:"channel_uuid"`
	ConnectionID ConnectionID      `db:"connection_id"`
	ContactID    ContactID         `db:"contact_id"      json:"contact_id"`
	ContactURNID ContactURNID      `db:"contact_urn_id"  json:"contact_urn_id"`
	URN          urns.URN          `                     json:"urn"`
	OrgID        OrgID             `db:"org_id"          json:"org_id"`
	TopUpID      TopUpID           `db:"topup_id"`
}

func CreateOutgoingMsg

func CreateOutgoingMsg(ctx context.Context, tx *sqlx.Tx, org *OrgAssets, contactID ContactID, m *flows.MsgOut) (*Msg, error)

type MsgDirection

type MsgDirection string

type MsgID

type MsgID int64

type MsgStatus

type MsgStatus string

type MsgType

type MsgType string

type MsgVisibility

type MsgVisibility string

type OrgAssets

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

OrgAssets is the set of assets for an organization. These are loaded lazily from the database as asked for. OrgAssets are thread safe and can be shared across goroutines. OrgAssets implement the flows.SessionAssets interface.

func NewOrgAssets

func NewOrgAssets(ctx context.Context, db *sqlx.DB, orgID OrgID) *OrgAssets

func (*OrgAssets) GetActiveTopup

func (o *OrgAssets) GetActiveTopup() (TopUpID, error)

TODO: does this need to be optimized further?

func (*OrgAssets) GetChannel

func (o *OrgAssets) GetChannel(uuid flows.ChannelUUID) (flows.Channel, error)

func (*OrgAssets) GetChannelID

func (o *OrgAssets) GetChannelID(uuid flows.ChannelUUID) (ChannelID, error)

func (*OrgAssets) GetChannelSet

func (o *OrgAssets) GetChannelSet() (*flows.ChannelSet, error)

func (*OrgAssets) GetField

func (o *OrgAssets) GetField(key string) (*flows.Field, error)

func (*OrgAssets) GetFieldSet

func (o *OrgAssets) GetFieldSet() (*flows.FieldSet, error)

func (*OrgAssets) GetFlow

func (o *OrgAssets) GetFlow(uuid flows.FlowUUID) (flows.Flow, error)

func (*OrgAssets) GetFlowID

func (o *OrgAssets) GetFlowID(uuid flows.FlowUUID) (FlowID, error)

func (*OrgAssets) GetGroup

func (o *OrgAssets) GetGroup(uuid flows.GroupUUID) (*flows.Group, error)

func (*OrgAssets) GetGroupSet

func (o *OrgAssets) GetGroupSet() (*flows.GroupSet, error)

func (*OrgAssets) GetLabel

func (o *OrgAssets) GetLabel(uuid flows.LabelUUID) (*flows.Label, error)

func (*OrgAssets) GetLabelSet

func (o *OrgAssets) GetLabelSet() (*flows.LabelSet, error)

func (*OrgAssets) GetLocationHierarchySet

func (o *OrgAssets) GetLocationHierarchySet() (*flows.LocationHierarchySet, error)

func (*OrgAssets) GetOrgID

func (o *OrgAssets) GetOrgID() OrgID

func (*OrgAssets) GetResthookSet

func (o *OrgAssets) GetResthookSet() (*flows.ResthookSet, error)

func (*OrgAssets) HasLocations

func (o *OrgAssets) HasLocations() bool

type OrgID

type OrgID int

type Session

type Session struct {
	ID        SessionID     `db:"id"`
	Status    SessionStatus `db:"status"`
	Responded bool          `db:"responded"`
	Output    string        `db:"output"`
	ContactID ContactID     `db:"contact_id"`
	OrgID     OrgID         `db:"org_id"`
	CreatedOn time.Time
	// contains filtered or unexported fields
}

func CreateSession

func CreateSession(ctx context.Context, tx *sqlx.Tx, org *OrgAssets, s flows.Session) (*Session, error)

CreateSession writes the passed in session to our database, writes any runs that need to be created as well as appying any events created in the session

func (*Session) AddFlowIDMapping

func (s *Session) AddFlowIDMapping(uuid flows.FlowUUID, id FlowID)

func (*Session) AddOutboxMsg

func (s *Session) AddOutboxMsg(m *Msg)

func (*Session) GetFlowID

func (s *Session) GetFlowID(uuid flows.FlowUUID) (FlowID, bool)

func (*Session) GetOutbox

func (s *Session) GetOutbox() []*Msg

type SessionID

type SessionID float64

type SessionStatus

type SessionStatus string

type Step

type Step struct {
	UUID      flows.StepUUID `json:"uuid"`
	NodeUUID  flows.NodeUUID `json:"node_uuid"`
	ArrivedOn time.Time      `json:"arrived_on"`
	ExitUUID  flows.ExitUUID `json:"exit_uuid,omitempty"`
}

type TopUpID

type TopUpID null.Int

Jump to

Keyboard shortcuts

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