flows

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2017 License: AGPL-3.0 Imports: 6 Imported by: 44

Documentation

Index

Constants

View Source
const (
	TelScheme      = "tel"
	FacebookScheme = "facebook"
	TwitterScheme  = "twitter"
	ViberScheme    = "viber"
	TelegramScheme = "telegram"
	EmailScheme    = "email"
)

List of schemes we support for URNs

Variables

View Source
var NoRoute = Route{}

Functions

func ValidateGroup

func ValidateGroup(sl validator.StructLevel)

ValidateGroup is our global validator for our group struct

Types

type Action

type Action interface {
	Execute(FlowRun, Step) error
	Validate() error
	utils.Typed
}

type ActionUUID

type ActionUUID UUID

func (ActionUUID) String

func (u ActionUUID) String() string

type Channel

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

Channel represents a channel in the system. Channels have a UUID, name, type and configuration

func ReadChannel

func ReadChannel(data json.RawMessage) (*Channel, error)

ReadChannel decodes a channel from the passed in JSON

func (*Channel) Default

func (c *Channel) Default() interface{}

Default returns the default value for a channel, which is itself

func (*Channel) MarshalJSON

func (c *Channel) MarshalJSON() ([]byte, error)

MarshalJSON is our custom marshalling of a channel

func (*Channel) Name

func (c *Channel) Name() string

Name returns the name of this channel

func (*Channel) Resolve

func (c *Channel) Resolve(key string) interface{}

Resolve satisfies our resolver interface

func (*Channel) String

func (c *Channel) String() string

String returns the default string value for a channel, which is its name

func (*Channel) Type

func (c *Channel) Type() ChannelType

Type returns the type of this channel

func (*Channel) UUID

func (c *Channel) UUID() ChannelUUID

UUID returns the UUID of this channel

func (*Channel) UnmarshalJSON

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

UnmarshalJSON is our custom unmarshalling of a channel

type ChannelType

type ChannelType string

ChannelType represents the type of a Channel

func (ChannelType) String

func (ct ChannelType) String() string

type ChannelUUID

type ChannelUUID UUID

func (ChannelUUID) String

func (u ChannelUUID) String() string

type Contact

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

Contact represents a single contact

func ReadContact

func ReadContact(data json.RawMessage) (*Contact, error)

ReadContact decodes a contact from the passed in JSON

func (*Contact) AddGroup

func (c *Contact) AddGroup(uuid GroupUUID, name string)

func (*Contact) Default

func (c *Contact) Default() interface{}

Default returns our default value in the context

func (*Contact) Fields

func (c *Contact) Fields() *Fields

func (*Contact) Groups

func (c *Contact) Groups() GroupList

func (*Contact) Language

func (c *Contact) Language() utils.Language

func (*Contact) MarshalJSON

func (c *Contact) MarshalJSON() ([]byte, error)

func (*Contact) Name

func (c *Contact) Name() string

func (*Contact) RemoveGroup

func (c *Contact) RemoveGroup(uuid GroupUUID) bool

func (*Contact) Resolve

func (c *Contact) Resolve(key string) interface{}

func (*Contact) SetLanguage

func (c *Contact) SetLanguage(lang utils.Language)

func (*Contact) SetName

func (c *Contact) SetName(name string)

func (*Contact) SetTimezone

func (c *Contact) SetTimezone(tz *time.Location)

func (*Contact) String

func (c *Contact) String() string

String returns our string value in the context

func (*Contact) Timezone

func (c *Contact) Timezone() *time.Location

func (*Contact) URNs

func (c *Contact) URNs() URNList

func (*Contact) UUID

func (c *Contact) UUID() ContactUUID

func (*Contact) UnmarshalJSON

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

type ContactReference

type ContactReference struct {
	UUID ContactUUID `json:"uuid"    validate:"required,uuid4"`
	Name string      `json:"name"`
}

type ContactUUID

type ContactUUID UUID

func (ContactUUID) String

func (u ContactUUID) String() string

type Context

type Context interface {
	utils.VariableResolver
	Contact() *Contact
	Run() FlowRun
}

type Event

type Event interface {
	CreatedOn() *time.Time
	SetCreatedOn(time.Time)

	Step() StepUUID
	SetStep(StepUUID)

	utils.Typed
}

type Exit

type Exit interface {
	UUID() ExitUUID
	DestinationNodeUUID() NodeUUID
	Name() string
}

type ExitUUID

type ExitUUID UUID

func (ExitUUID) String

func (u ExitUUID) String() string

type Field

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

Field represents a contact field and value for a contact

func (*Field) Default

func (f *Field) Default() interface{}

Default returns the default value for a Field, which is the field itself

func (*Field) MarshalJSON

func (f *Field) MarshalJSON() ([]byte, error)

MarshalJSON is our custom unmarshalling for Field

func (*Field) Resolve

func (f *Field) Resolve(key string) interface{}

Resolve resolves one of the fields on a Field

func (*Field) String

func (f *Field) String() string

String returns the string value for a field, which is our value

func (*Field) UnmarshalJSON

func (f *Field) UnmarshalJSON(data []byte) error

UnmarshalJSON is our custom unmarshalling for Field

type FieldUUID

type FieldUUID UUID

func (FieldUUID) String

func (u FieldUUID) String() string

type Fields

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

Fields represents a set of fields keyed by snakified field names

func NewFields

func NewFields() *Fields

NewFields returns a new empty field

func (*Fields) Default

func (f *Fields) Default() interface{}

Default returns the default value for Fields, which is ourselves

func (*Fields) MarshalJSON

func (f *Fields) MarshalJSON() ([]byte, error)

MarshalJSON is our custom marshalling of a Fields object, we build a map with the full names and then marshal that with snakified keys

func (*Fields) Resolve

func (f *Fields) Resolve(key string) interface{}

Resolve resolves the field for the passed in key which will be snakified

func (*Fields) Save

func (f *Fields) Save(uuid FieldUUID, name string, value string)

Save saves a new field to our map

func (*Fields) String

func (f *Fields) String() string

String returns the string representation of these Fields, which is our JSON representation

func (*Fields) UnmarshalJSON

func (f *Fields) UnmarshalJSON(data []byte) error

UnmarshalJSON is our custom unmarshalling of a Fields object, we validate our keys against snaked names

type Flow

type Flow interface {
	Name() string
	Language() utils.Language
	UUID() FlowUUID
	Translations() FlowTranslations

	Nodes() []Node
	GetNode(uuid NodeUUID) Node

	Validate() error

	CreateRun(env FlowEnvironment, contact *Contact, parent FlowRun) FlowRun
}

type FlowEnvironment

type FlowEnvironment interface {
	GetFlow(FlowUUID) (Flow, error)
	GetRun(RunUUID) (FlowRun, error)
	GetContact(ContactUUID) (*Contact, error)
	utils.Environment
}

type FlowRun

type FlowRun interface {
	UUID() RunUUID
	FlowUUID() FlowUUID
	Flow() Flow

	Hydrate(FlowEnvironment) error

	ContactUUID() ContactUUID
	Contact() *Contact

	ChannelUUID() ChannelUUID
	Channel() *Channel
	SetChannel(*Channel)

	Context() Context
	Results() *Results
	Environment() FlowEnvironment

	SetExtra(json.RawMessage)
	Extra() utils.JSONFragment

	Session() Session
	SetSession(Session)
	ResetSession()

	Status() RunStatus
	Exit(RunStatus)
	IsComplete() bool

	Wait() Wait
	SetWait(Wait)

	Input() Input
	SetInput(Input)

	AddEvent(Step, Event)
	AddError(Step, error)

	CreateStep(Node) Step
	Path() []Step

	SetLanguage(utils.Language)
	SetFlowTranslations(FlowTranslations)
	GetText(uuid UUID, key string, backdown string) string
	GetTranslations(uuid UUID, key string, backdown []string) []string

	Webhook() *utils.RequestResponse
	SetWebhook(*utils.RequestResponse)

	Child() FlowRunReference
	Parent() FlowRunReference

	CreatedOn() time.Time
	ModifiedOn() time.Time
	ExpiresOn() *time.Time
	TimesOutOn() *time.Time
	ExitedOn() *time.Time
}

FlowRun represents a single run on a flow by a single contact

type FlowRunReference

type FlowRunReference interface {
	UUID() RunUUID
	FlowUUID() FlowUUID
	ContactUUID() ContactUUID
	ChannelUUID() ChannelUUID

	Results() *Results
	Status() RunStatus

	CreatedOn() time.Time
	ModifiedOn() time.Time
	ExpiresOn() *time.Time
	TimesOutOn() *time.Time
	ExitedOn() *time.Time
}

FlowRunReference represents a flow run reference within a flow

type FlowTranslations

type FlowTranslations interface {
	GetTranslations(utils.Language) Translations
}

FlowTranslations provide a way to get the Translations for a flow for a specific language

type FlowUUID

type FlowUUID UUID

func (FlowUUID) String

func (u FlowUUID) String() string

type Group

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

Group represents a grouping of contacts. From an engine perspective the only piece that matter is the UUID of the group and its name

func NewGroup

func NewGroup(uuid GroupUUID, name string) *Group

NewGroup returns a new group object with the passed in uuid and name

func (*Group) Default

func (g *Group) Default() interface{}

Default returns the default value for this group

func (*Group) MarshalJSON

func (g *Group) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Group into json

func (*Group) Name

func (g *Group) Name() string

Name returns the name of the group

func (*Group) Resolve

func (g *Group) Resolve(key string) interface{}

Resolve resolves the passed in key to a value

func (*Group) String

func (g *Group) String() string

String satisfies the stringer interface returning the name of the group

func (*Group) UUID

func (g *Group) UUID() GroupUUID

UUID returns the UUID of the group

func (*Group) UnmarshalJSON

func (g *Group) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the group from the passed in json

type GroupList

type GroupList []*Group

GroupList defines a list of groups

func (GroupList) Default

func (l GroupList) Default() interface{}

Default returns the default value for this group, which is our entire list

func (GroupList) FindGroup

func (l GroupList) FindGroup(uuid GroupUUID) *Group

FindGroup returns the group with the passed in UUID or nil if not found

func (GroupList) Resolve

func (l GroupList) Resolve(key string) interface{}

Resolve looks up the passed in key for the group list, we attempt to find the group with the uuid of the passed in key, which can be used for testing whether a contact is part of a group

func (GroupList) String

func (l GroupList) String() string

String stringifies the group list, joining our names with a comma

type GroupUUID

type GroupUUID UUID

func (GroupUUID) String

func (u GroupUUID) String() string

type Input

type Input interface {
	Event
	utils.VariableResolver
}

type Label

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

Label represents a msg label

func NewLabel

func NewLabel(uuid LabelUUID, name string) *Label

NewLabel creates a new label given the passed in uuid and name

func (*Label) MarshalJSON

func (l *Label) MarshalJSON() ([]byte, error)

func (*Label) Name

func (l *Label) Name() string

Name returns the name of this label

func (*Label) UUID

func (l *Label) UUID() LabelUUID

UUID returns the UUID of this label

func (*Label) UnmarshalJSON

func (l *Label) UnmarshalJSON(data []byte) error

type LabelUUID

type LabelUUID UUID

func (LabelUUID) String

func (u LabelUUID) String() string

type MsgDirection

type MsgDirection string

MsgDirection is the direction of a Msg (either in or out)

const (
	// MsgOut represents an outgoing message
	MsgOut MsgDirection = "O"

	// MsgIn represents an incoming message
	MsgIn MsgDirection = "I"
)

type Node

type Node interface {
	UUID() NodeUUID

	Router() Router
	Actions() []Action
	Exits() []Exit
	Wait() Wait
}

type NodeUUID

type NodeUUID UUID

func (NodeUUID) String

func (u NodeUUID) String() string

type Result

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

Result represents a result value in our flow run. Results have a name for which they are the result for, the value itself of the result, optional category and the date and node the result was collected on

func (*Result) Default

func (r *Result) Default() interface{}

Default returns the default value for a result, which is our value

func (*Result) MarshalJSON

func (r *Result) MarshalJSON() ([]byte, error)

MarshalJSON is our custom marshalling of a Result object

func (*Result) Resolve

func (r *Result) Resolve(key string) interface{}

Resolve resolves the passed in key to a value. Result values have a name, value, category, node and created_on

func (*Result) String

func (r *Result) String() string

String returns the string representation of a result, which is our value

func (*Result) UnmarshalJSON

func (r *Result) UnmarshalJSON(data []byte) error

UnmarshalJSON is our custom unmarshalling of a Result object

type Results

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

Results is our wrapper around a map of snakified result names to result objects

func NewResults

func NewResults() *Results

NewResults returns a new empty Results object

func (*Results) Default

func (r *Results) Default() interface{}

Default returns the default value for our Results, which is the entire map

func (*Results) MarshalJSON

func (r *Results) MarshalJSON() ([]byte, error)

MarshalJSON is our custom marshalling of a Results object, we build a map with the full names and then marshal that with snakified keys

func (*Results) Resolve

func (r *Results) Resolve(key string) interface{}

Resolve resolves the passed in key, which is snakified before lookup

func (*Results) Save

func (r *Results) Save(node NodeUUID, name string, value string, category string, categoryLocalized string, createdOn time.Time)

Save saves a new result in our map. The key is saved in a snakified format

func (*Results) String

func (r *Results) String() string

String returns the string representation of our Results, which is a key/value pairing of our fields

func (*Results) UnmarshalJSON

func (r *Results) UnmarshalJSON(data []byte) error

UnmarshalJSON is our custom unmarshalling of a Results object, we build our map only with with snakified keys

type Route

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

func NewRoute

func NewRoute(exit ExitUUID, match string) Route

func (Route) Exit

func (r Route) Exit() ExitUUID

func (Route) Match

func (r Route) Match() string

type Router

type Router interface {
	PickRoute(FlowRun, []Exit, Step) (Route, error)
	Validate([]Exit) error
	ResultName() string
	utils.Typed
}

type RunStatus

type RunStatus string

RunStatus represents the current status of the flow run

const (
	// StatusActive represents an active flow run that is awaiting input
	StatusActive RunStatus = "A"

	// StatusCompleted represents a flow run that has run to completion
	StatusCompleted RunStatus = "C"

	// StatusErrored represents a flow run that encountered an error
	StatusErrored RunStatus = "E"

	// StatusExpired represents a flow run that expired due to inactivity
	StatusExpired RunStatus = "X"

	// StatusInterrupted represents a flow run that was interrupted by another flow
	StatusInterrupted RunStatus = "I"
)

func (RunStatus) String

func (r RunStatus) String() string

type RunUUID

type RunUUID UUID

func (RunUUID) String

func (u RunUUID) String() string

type Session

type Session interface {
	Runs() []FlowRun
	AddRun(FlowRun)

	ActiveRun() FlowRun

	Events() []Event
	AddEvent(Event)
	ClearEvents()
}

Session represents the session of a flow run which may contain many runs

type Step

type Step interface {
	utils.VariableResolver

	UUID() StepUUID
	NodeUUID() NodeUUID
	ExitUUID() ExitUUID

	ArrivedOn() time.Time
	LeftOn() *time.Time

	Leave(ExitUUID)

	Events() []Event
}

type StepUUID

type StepUUID UUID

func (StepUUID) String

func (u StepUUID) String() string

type Translations

type Translations interface {
	GetText(uuid UUID, key string, backdown string) string
	GetTranslations(uuid UUID, key string, backdown []string) []string
}

Translations provide a way to get the translation for a specific language for a uuid/key pair

type URN

type URN string

func (URN) Default

func (u URN) Default() interface{}

func (URN) Path

func (u URN) Path() URNPath

func (URN) Resolve

func (u URN) Resolve(key string) interface{}

func (URN) Scheme

func (u URN) Scheme() URNScheme

func (URN) String

func (u URN) String() string

type URNList

type URNList []URN

func (URNList) Default

func (l URNList) Default() interface{}

func (URNList) Resolve

func (l URNList) Resolve(key string) interface{}

func (URNList) String

func (l URNList) String() string

type URNPath

type URNPath string

func (URNPath) String

func (u URNPath) String() string

type URNScheme

type URNScheme string

func GetScheme

func GetScheme(scheme string) URNScheme

func (URNScheme) String

func (u URNScheme) String() string

type UUID

type UUID string

type Wait

type Wait interface {
	Begin(FlowRun, Step) error
	GetEndEvent(FlowRun, Step) (Event, error)
	End(FlowRun, Step, Event) error
	utils.Typed
	utils.VariableResolver
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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