flows

package
v0.52.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2019 License: AGPL-3.0 Imports: 20 Imported by: 44

Documentation

Index

Constants

View Source
const (
	LocationLevelState    = utils.LocationLevel(1)
	LocationLevelDistrict = utils.LocationLevel(2)
	LocationLevelWard     = utils.LocationLevel(3)
)

location levels which can be field types

View Source
const NilMsgID = MsgID(0)

NilMsgID is our constant for nil message ids

Variables

View Source
var RunContextTopLevels = []string{
	"child",
	"contact",
	"fields",
	"input",
	"legacy_extra",
	"parent",
	"results",
	"run",
	"trigger",
	"urns",
	"webhook",
}

RunContextTopLevels are the allowed top-level variables for expression evaluations

Functions

func Context

func Context(env envs.Environment, contextable Contextable) *types.XObject

Context generates a lazy object for use in expressions

func ContextFunc added in v0.33.8

func ContextFunc(env envs.Environment, fn func(envs.Environment) map[string]types.XValue) *types.XObject

ContextFunc generates a lazy object for use in expressions

func ValidateURN added in v0.4.0

func ValidateURN(fl validator.FieldLevel) bool

ValidateURN validates whether the field value is a valid URN

func ValidateURNScheme added in v0.4.0

func ValidateURNScheme(fl validator.FieldLevel) bool

ValidateURNScheme validates whether the field value is a valid URN scheme

Types

type Action

type Action interface {
	utils.Typed
	Localizable

	UUID() ActionUUID
	Execute(FlowRun, Step, ModifierCallback, EventCallback) error
	Validate() error
	AllowedFlowTypes() []FlowType
}

Action is an action within a flow node

type ActionUUID

type ActionUUID uuids.UUID

ActionUUID is the UUID of an action

type ActivatedWait added in v0.33.0

type ActivatedWait interface {
	utils.Typed

	TimeoutSeconds() *int
}

type AirtimeService added in v0.48.0

type AirtimeService interface {
	// Transfer transfers airtime to the given URN
	Transfer(session Session, sender urns.URN, recipient urns.URN, amounts map[string]decimal.Decimal, logEvent EventCallback) (*AirtimeTransfer, error)
}

AirtimeService provides airtime functionality to the engine

type AirtimeTransfer added in v0.48.0

type AirtimeTransfer struct {
	Sender    urns.URN
	Recipient urns.URN
	Currency  string
	Amount    decimal.Decimal
}

AirtimeTransfer is the result of an attempted airtime transfer

type AirtimeTransferStatus added in v0.48.0

type AirtimeTransferStatus string

AirtimeTransferStatus is a status of a airtime transfer

const (
	AirtimeTransferStatusSuccess AirtimeTransferStatus = "success"
	AirtimeTransferStatusFailed  AirtimeTransferStatus = "failed"
)

possible values for airtime transfer statuses

type BaseMsg added in v0.6.0

type BaseMsg struct {
	UUID_        MsgUUID                  `json:"uuid"`
	ID_          MsgID                    `json:"id,omitempty"`
	URN_         urns.URN                 `json:"urn,omitempty" validate:"omitempty,urn"`
	Channel_     *assets.ChannelReference `json:"channel,omitempty"`
	Text_        string                   `json:"text"`
	Attachments_ []utils.Attachment       `json:"attachments,omitempty"`
}

BaseMsg represents a incoming or outgoing message with the session contact

func (*BaseMsg) Attachments added in v0.6.0

func (m *BaseMsg) Attachments() []utils.Attachment

Attachments returns the attachments of this message

func (*BaseMsg) Channel added in v0.6.0

func (m *BaseMsg) Channel() *assets.ChannelReference

Channel returns the channel of this message

func (*BaseMsg) ID added in v0.15.0

func (m *BaseMsg) ID() MsgID

ID returns the internal ID of this message

func (*BaseMsg) SetID added in v0.24.0

func (m *BaseMsg) SetID(id MsgID)

SetID sets the internal ID of this message

func (*BaseMsg) SetURN added in v0.41.17

func (m *BaseMsg) SetURN(urn urns.URN)

SetURN returns the URN of this message

func (*BaseMsg) Text added in v0.6.0

func (m *BaseMsg) Text() string

Text returns the text of this message

func (*BaseMsg) URN added in v0.6.0

func (m *BaseMsg) URN() urns.URN

URN returns the URN of this message

func (*BaseMsg) UUID added in v0.6.0

func (m *BaseMsg) UUID() MsgUUID

UUID returns the UUID of this message

type CallStatus added in v0.51.0

type CallStatus string

CallStatus represents the status of a call to an external service

const (
	// CallStatusSuccess represents that the webhook was successful
	CallStatusSuccess CallStatus = "success"

	// CallStatusConnectionError represents that the webhook had a connection error
	CallStatusConnectionError CallStatus = "connection_error"

	// CallStatusResponseError represents that the webhook response had a non 2xx status code
	CallStatusResponseError CallStatus = "response_error"

	// CallStatusSubscriberGone represents a special state of resthook responses which indicate the caller must remove that subscriber
	CallStatusSubscriberGone CallStatus = "subscriber_gone"
)

type CategoryUUID added in v0.30.2

type CategoryUUID uuids.UUID

CategoryUUID is the UUID of a node category

type Channel

type Channel struct {
	assets.Channel
}

Channel represents a means for sending and receiving input during a flow run

func NewChannel added in v0.6.0

func NewChannel(asset assets.Channel) *Channel

func (*Channel) Asset added in v0.15.0

func (c *Channel) Asset() assets.Channel

Asset returns the underlying asset

func (*Channel) Context added in v0.33.8

func (c *Channel) Context(env envs.Environment) map[string]types.XValue

Context returns the properties available in expressions

__default__:text -> the name
uuid:text -> the UUID of the channel
name:text -> the name of the channel
address:text -> the address of the channel

@context channel

func (*Channel) HasParent added in v0.15.0

func (c *Channel) HasParent() bool

func (*Channel) HasRole added in v0.6.0

func (c *Channel) HasRole(role assets.ChannelRole) bool

HasRole returns whether this channel has the given role

func (*Channel) Reference added in v0.5.0

func (c *Channel) Reference() *assets.ChannelReference

Reference returns a reference to this channel

func (*Channel) String

func (c *Channel) String() string

func (*Channel) SupportsScheme added in v0.6.0

func (c *Channel) SupportsScheme(scheme string) bool

SupportsScheme returns whether this channel supports the given URN scheme

type ChannelAssets added in v0.15.0

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

ChannelAssets provides access to all channel assets

func NewChannelAssets added in v0.15.0

func NewChannelAssets(channels []assets.Channel) *ChannelAssets

NewChannelAssets creates a new set of channel assets

func (*ChannelAssets) Get added in v0.15.0

func (s *ChannelAssets) Get(uuid assets.ChannelUUID) *Channel

Get returns the channel with the given UUID

func (*ChannelAssets) GetForURN added in v0.15.0

func (s *ChannelAssets) GetForURN(urn *ContactURN, role assets.ChannelRole) *Channel

GetForURN returns the best channel for the given URN

type Classification added in v0.51.0

type Classification struct {
	Intents  []ExtractedIntent            `json:"intents,omitempty"`
	Entities map[string][]ExtractedEntity `json:"entities,omitempty"`
}

Classification is the result of an NLU classification

type ClassificationService added in v0.51.0

type ClassificationService interface {
	Classify(session Session, input string, logEvent EventCallback) (*Classification, error)
}

ClassificationService provides NLU functionality to the engine

type Classifier added in v0.51.0

type Classifier struct {
	assets.Classifier
}

Classifier represents an NLU classifier.

func NewClassifier added in v0.51.0

func NewClassifier(asset assets.Classifier) *Classifier

NewClassifier returns a new classifier object from the given classifier asset

func (*Classifier) Asset added in v0.51.0

func (c *Classifier) Asset() assets.Classifier

Asset returns the underlying asset

func (*Classifier) Reference added in v0.51.0

func (c *Classifier) Reference() *assets.ClassifierReference

Reference returns a reference to this classifier

type ClassifierAssets added in v0.51.0

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

ClassifierAssets provides access to all classifier assets

func NewClassifierAssets added in v0.51.0

func NewClassifierAssets(classifiers []assets.Classifier) *ClassifierAssets

NewClassifierAssets creates a new set of classifier assets

func (*ClassifierAssets) Get added in v0.51.0

Get returns the classifier with the given UUID

type Connection added in v0.25.0

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

Connection represents a connection to a specific channel using a specific URN

func NewConnection added in v0.25.0

func NewConnection(channel *assets.ChannelReference, urn urns.URN) *Connection

NewConnection creates a new connection

func (*Connection) Channel added in v0.25.0

func (c *Connection) Channel() *assets.ChannelReference

func (*Connection) MarshalJSON added in v0.25.2

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

MarshalJSON marshals this connection into JSON

func (*Connection) URN added in v0.25.0

func (c *Connection) URN() urns.URN

func (*Connection) UnmarshalJSON added in v0.25.2

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

type Contact

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

Contact represents a person who is interacting with the flow

func NewContact added in v0.5.1

func NewContact(
	sa SessionAssets,
	uuid ContactUUID,
	id ContactID,
	name string,
	language envs.Language,
	timezone *time.Location,
	createdOn time.Time,
	urns []urns.URN,
	groups []assets.Group,
	fields map[string]*Value) (*Contact, error)

NewContact creates a new contact with the passed in attributes

func NewEmptyContact added in v0.14.7

func NewEmptyContact(sa SessionAssets, name string, language envs.Language, timezone *time.Location) *Contact

NewEmptyContact creates a new empy contact with the passed in name, language and location

func ReadContact

func ReadContact(sa SessionAssets, data json.RawMessage, missing assets.MissingCallback) (*Contact, error)

ReadContact decodes a contact from the passed in JSON

func (*Contact) AddURN added in v0.4.0

func (c *Contact) AddURN(urn *ContactURN) bool

AddURN adds a new URN to this contact

func (*Contact) Clone added in v0.4.0

func (c *Contact) Clone() *Contact

Clone creates a copy of this contact

func (*Contact) Context added in v0.33.8

func (c *Contact) Context(env envs.Environment) map[string]types.XValue

Context returns the properties available in expressions

__default__:text -> the name or URN
uuid:text -> the UUID of the contact
id:text -> the numeric ID of the contact
first_name:text -> the first name of the contact
name:text -> the name of the contact
language:text -> the language of the contact as 3-letter ISO code
created_on:datetime -> the creation date of the contact
urns:[]text -> the URNs belonging to the contact
urn:text -> the preferred URN of the contact
groups:[]group -> the groups the contact belongs to
fields:fields -> the custom field values of the contact
channel:channel -> the preferred channel of the contact

@context contact

func (*Contact) CreatedOn added in v0.10.15

func (c *Contact) CreatedOn() time.Time

CreatedOn returns the created on time of this contact

func (*Contact) Equal added in v0.20.0

func (c *Contact) Equal(other *Contact) bool

Equal returns true if this instance is equal to the given instance

func (*Contact) Fields

func (c *Contact) Fields() FieldValues

Fields returns this contact's field values

func (*Contact) Format added in v0.10.18

func (c *Contact) Format(env envs.Environment) string

Format returns a friendly string version of this contact depending on what fields are set

func (*Contact) Groups

func (c *Contact) Groups() *GroupList

Groups returns the groups that this contact belongs to

func (*Contact) HasURN added in v0.6.1

func (c *Contact) HasURN(urn urns.URN) bool

HasURN checks whether the contact has the given URN

func (*Contact) ID added in v0.10.5

func (c *Contact) ID() ContactID

ID returns the numeric ID of this contact

func (*Contact) Language

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

Language gets the language for this contact

func (*Contact) MarshalJSON

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

MarshalJSON marshals this contact into JSON

func (*Contact) Name

func (c *Contact) Name() string

Name returns the name of this contact

func (*Contact) PreferredChannel added in v0.11.0

func (c *Contact) PreferredChannel() *Channel

PreferredChannel gets the preferred channel for this contact, i.e. the channel we would use for sending

func (*Contact) PreferredURN added in v0.27.5

func (c *Contact) PreferredURN() *ContactURN

PreferredURN gets the preferred URN for this contact, i.e. the URN we would use for sending

func (*Contact) QueryProperty added in v0.45.1

func (c *Contact) QueryProperty(env envs.Environment, key string, propType contactql.PropertyType) []interface{}

QueryProperty resolves a contact query search key for this contact

func (*Contact) ReevaluateDynamicGroups added in v0.9.6

func (c *Contact) ReevaluateDynamicGroups(env envs.Environment, allGroups *GroupAssets, allFields *FieldAssets) ([]*Group, []*Group, []error)

ReevaluateDynamicGroups reevaluates membership of all dynamic groups for this contact

func (*Contact) Reference added in v0.4.0

func (c *Contact) Reference() *ContactReference

Reference returns a reference to this contact

func (*Contact) ResolveDestinations added in v0.27.5

func (c *Contact) ResolveDestinations(all bool) []Destination

ResolveDestinations resolves possible URN/channel destinations

func (*Contact) SetCreatedOn added in v0.10.15

func (c *Contact) SetCreatedOn(createdOn time.Time)

SetCreatedOn sets the created on time of this contact

func (*Contact) SetLanguage

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

SetLanguage sets the language for this contact

func (*Contact) SetName

func (c *Contact) SetName(name string)

SetName sets the name of this contact

func (*Contact) SetTimezone

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

SetTimezone sets the timezone of this contact

func (*Contact) Timezone

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

Timezone returns the timezone of this contact

func (*Contact) URNs

func (c *Contact) URNs() URNList

URNs returns the URNs of this contact

func (*Contact) UUID

func (c *Contact) UUID() ContactUUID

UUID returns the UUID of this contact

func (*Contact) UpdatePreferredChannel added in v0.6.0

func (c *Contact) UpdatePreferredChannel(channel *Channel) bool

UpdatePreferredChannel updates the preferred channel and returns whether any change was made

type ContactID added in v0.15.0

type ContactID int64

ContactID is the ID of a contact

type ContactReference

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

ContactReference is used to reference a contact

func NewContactReference added in v0.4.0

func NewContactReference(uuid ContactUUID, name string) *ContactReference

NewContactReference creates a new contact reference with the given UUID and name

func (*ContactReference) Identity added in v0.29.0

func (r *ContactReference) Identity() string

Identity returns the unique identity of the asset

func (*ContactReference) String added in v0.29.0

func (r *ContactReference) String() string

func (*ContactReference) Type added in v0.29.0

func (r *ContactReference) Type() string

Type returns the name of the asset type

func (*ContactReference) Variable added in v0.29.0

func (r *ContactReference) Variable() bool

Variable returns whether this a variable (vs concrete) reference

type ContactURN added in v0.6.0

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

ContactURN represents a destination for an outgoing message or a source of an incoming message. It is string composed of 3 components: scheme, path, and display (optional). For example:

  • _tel:+16303524567_
  • _twitterid:54784326227#nyaruka_
  • _telegram:34642632786#bobby_

func NewContactURN added in v0.6.0

func NewContactURN(urn urns.URN, channel *Channel) *ContactURN

NewContactURN creates a new contact URN with associated channel

func ParseRawURN added in v0.23.0

func ParseRawURN(ca *ChannelAssets, rawURN urns.URN, missing assets.MissingCallback) (*ContactURN, error)

ParseRawURN converts a raw URN to a ContactURN by extracting it's channel reference

func (*ContactURN) Channel added in v0.6.0

func (u *ContactURN) Channel() *Channel

Channel gets the channel associated with this URN

func (*ContactURN) Equal added in v0.23.0

func (u *ContactURN) Equal(other *ContactURN) bool

Equal determines if this URN is equal to another

func (*ContactURN) SetChannel added in v0.6.0

func (u *ContactURN) SetChannel(channel *Channel)

SetChannel sets the channel associated with this URN

func (*ContactURN) String added in v0.6.0

func (u *ContactURN) String() string

func (*ContactURN) ToXValue added in v0.32.0

func (u *ContactURN) ToXValue(env envs.Environment) types.XValue

ToXValue returns a representation of this object for use in expressions

func (*ContactURN) URN added in v0.23.0

func (u *ContactURN) URN() urns.URN

URN gets the underlying URN

type ContactUUID

type ContactUUID uuids.UUID

ContactUUID is the UUID of a contact

type Contextable added in v0.33.8

type Contextable interface {
	Context(env envs.Environment) map[string]types.XValue
}

Contextable is an object that can accessed in expressions as a object with properties

type Dependencies added in v0.40.0

type Dependencies struct {
	Channels  []*assets.ChannelReference  `json:"channels,omitempty"`
	Contacts  []*ContactReference         `json:"contacts,omitempty"`
	Fields    []*assets.FieldReference    `json:"fields,omitempty"`
	Flows     []*assets.FlowReference     `json:"flows,omitempty"`
	Groups    []*assets.GroupReference    `json:"groups,omitempty"`
	Labels    []*assets.LabelReference    `json:"labels,omitempty"`
	Templates []*assets.TemplateReference `json:"templates,omitempty"`
}

func NewDependencies added in v0.40.0

func NewDependencies(refs []assets.Reference) *Dependencies

func (*Dependencies) Check added in v0.40.0

func (d *Dependencies) Check(sa SessionAssets, missing assets.MissingCallback) error

Check checks the asset dependencies and notifies the caller of missing assets via the callback

type Destination added in v0.27.5

type Destination struct {
	Channel *Channel
	URN     *ContactURN
}

Destination is a sendable channel and URN pair

type Engine added in v0.27.4

type Engine interface {
	NewSession(SessionAssets, Trigger) (Session, Sprint, error)
	ReadSession(SessionAssets, json.RawMessage, assets.MissingCallback) (Session, error)

	HTTPClient() *http.Client
	Services() Services
	MaxStepsPerSprint() int
}

type Event

type Event interface {
	utils.Typed

	CreatedOn() time.Time
	StepUUID() StepUUID
	SetStepUUID(StepUUID)
}

Event describes a state change

type EventCallback added in v0.26.0

type EventCallback func(Event)

EventCallback is a callback invoked when an event has been generated

type Exit

type Exit interface {
	UUID() ExitUUID
	DestinationUUID() NodeUUID
}

type ExitUUID

type ExitUUID uuids.UUID

ExitUUID is the UUID of a node exit

type ExtractedEntity added in v0.51.0

type ExtractedEntity struct {
	Value      string          `json:"value"`
	Confidence decimal.Decimal `json:"confidence"`
}

ExtractedEntity models an entity match

type ExtractedIntent added in v0.51.0

type ExtractedIntent struct {
	Name       string          `json:"name"`
	Confidence decimal.Decimal `json:"confidence"`
}

ExtractedIntent models an intent match

type Field

type Field struct {
	assets.Field
}

Field represents a contact field

func NewField added in v0.4.0

func NewField(asset assets.Field) *Field

NewField creates a new field from the given asset

func (*Field) Asset added in v0.15.0

func (f *Field) Asset() assets.Field

Asset returns the underlying asset

func (*Field) Reference added in v0.24.0

func (f *Field) Reference() *assets.FieldReference

Reference returns a reference to this field

type FieldAssets added in v0.15.0

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

FieldAssets provides access to all field assets

func NewFieldAssets added in v0.15.0

func NewFieldAssets(fields []assets.Field) *FieldAssets

NewFieldAssets creates a new set of field assets

func (*FieldAssets) All added in v0.15.0

func (s *FieldAssets) All() []*Field

All returns all the fields in this set

func (*FieldAssets) FirstOfType added in v0.15.0

func (s *FieldAssets) FirstOfType(valueType assets.FieldType) *Field

FirstOfType returns the first field in this set with the given value type

func (*FieldAssets) Get added in v0.15.0

func (s *FieldAssets) Get(key string) *Field

Get returns the contact field with the given key

type FieldValue added in v0.4.0

type FieldValue struct {
	*Value
	// contains filtered or unexported fields
}

FieldValue represents a field and a set of values for that field

func NewFieldValue added in v0.4.0

func NewFieldValue(field *Field, value *Value) *FieldValue

NewFieldValue creates a new field value

func (*FieldValue) QueryValue added in v0.32.0

func (v *FieldValue) QueryValue() interface{}

QueryValue returns the value for use in contact queries

func (*FieldValue) ToXValue added in v0.32.0

func (v *FieldValue) ToXValue(env envs.Environment) types.XValue

ToXValue returns a representation of this object for use in expressions

type FieldValues added in v0.4.0

type FieldValues map[string]*FieldValue

FieldValues is the set of all field values for a contact

func NewFieldValues added in v0.15.2

func NewFieldValues(a SessionAssets, values map[string]*Value, missing assets.MissingCallback) (FieldValues, error)

NewFieldValues creates a new field value map

func (FieldValues) Clear added in v0.19.2

func (f FieldValues) Clear(field *Field)

Clear clears the value set for the given field

func (FieldValues) Context added in v0.30.4

func (f FieldValues) Context(env envs.Environment) map[string]types.XValue

Context returns the properties available in expressions

func (FieldValues) Get added in v0.19.2

func (f FieldValues) Get(field *Field) *Value

Get gets the value set for the given field

func (FieldValues) Parse added in v0.24.0

func (f FieldValues) Parse(env envs.Environment, fields *FieldAssets, field *Field, rawValue string) *Value

Parse parses a raw string field value into the different possible types

func (FieldValues) Set added in v0.19.2

func (f FieldValues) Set(field *Field, value *Value)

Set sets the value for the given field (can be null to clear it)

type Flow

type Flow interface {
	Contextable

	// spec properties
	UUID() assets.FlowUUID
	Name() string
	Revision() int
	Language() envs.Language
	Type() FlowType
	ExpireAfterMinutes() int
	Localization() Localization
	UI() json.RawMessage
	Nodes() []Node
	GetNode(uuid NodeUUID) Node
	Reference() *assets.FlowReference
	Generic() map[string]interface{}
	Clone(map[uuids.UUID]uuids.UUID) Flow

	Inspect() *FlowInfo
	Validate(SessionAssets, func(assets.Reference)) error
	ValidateRecursive(SessionAssets, func(assets.Reference)) error

	ExtractTemplates() []string
	ExtractDependencies() []assets.Reference
	ExtractResults() []*ResultInfo

	MarshalWithInfo() ([]byte, error)
}

Flow describes the ordered logic of actions and routers

type FlowAssets added in v0.15.0

type FlowAssets interface {
	Get(assets.FlowUUID) (Flow, error)
}

type FlowInfo added in v0.40.0

type FlowInfo struct {
	Dependencies *Dependencies `json:"dependencies"`
	Results      []*ResultInfo `json:"results"`
	WaitingExits []ExitUUID    `json:"waiting_exits"`
}

type FlowRun

type FlowRun interface {
	Contextable
	RunSummary
	FlowReference() *assets.FlowReference

	Environment() RunEnvironment
	Session() Session
	SaveResult(*Result)
	SetStatus(RunStatus)

	CreateStep(Node) Step
	Path() []Step
	PathLocation() (Step, Node, error)

	LogEvent(Step, Event)
	LogError(Step, error)
	Events() []Event

	EvaluateTemplateValue(template string) (types.XValue, error)
	EvaluateTemplate(template string) (string, error)

	GetText(uuids.UUID, string, string) string
	GetTextArray(uuids.UUID, string, []string) []string
	GetTranslatedTextArray(uuids.UUID, string, []string, []envs.Language) []string

	Snapshot() RunSummary
	Parent() RunSummary
	ParentInSession() FlowRun
	Ancestors() []FlowRun

	CreatedOn() time.Time
	ModifiedOn() time.Time
	ExpiresOn() *time.Time
	ResetExpiration(*time.Time)
	ExitedOn() *time.Time
	Exit(RunStatus)
}

FlowRun is a single contact's journey through a flow. It records the path they have taken, and the results that have been collected.

type FlowType added in v0.14.0

type FlowType string

FlowType represents the different types of flows

const (
	// FlowTypeMessaging is a flow that is run over a messaging channel
	FlowTypeMessaging FlowType = "messaging"

	// FlowTypeMessagingOffline is a flow which is run over an offline messaging client like Surveyor
	FlowTypeMessagingOffline FlowType = "messaging_offline"

	// FlowTypeVoice is a flow which is run over IVR
	FlowTypeVoice FlowType = "voice"
)

type Group

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

Group represents a grouping of contacts. It can be static (contacts are added and removed manually through [actions](#action:add_contact_groups)) or dynamic (contacts are added automatically by a query).

func NewGroup

func NewGroup(asset assets.Group) *Group

NewGroup returns a new group object from the given group asset

func (*Group) Asset added in v0.15.0

func (g *Group) Asset() assets.Group

Asset returns the underlying asset

func (*Group) CheckDynamicMembership added in v0.4.0

func (g *Group) CheckDynamicMembership(env envs.Environment, contact *Contact, fields *FieldAssets) (bool, error)

CheckDynamicMembership returns whether the given contact belongs in this dynamic group

func (*Group) IsDynamic added in v0.4.0

func (g *Group) IsDynamic() bool

IsDynamic returns whether this group is dynamic

func (*Group) Reference added in v0.4.0

func (g *Group) Reference() *assets.GroupReference

Reference returns a reference to this group

func (*Group) ToXValue added in v0.32.0

func (g *Group) ToXValue(env envs.Environment) types.XValue

ToXValue returns a representation of this object for use in expressions

uuid:text -> the UUID of the group
name:text -> the name of the group

@context group

type GroupAssets added in v0.15.0

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

GroupAssets provides access to all group assets

func NewGroupAssets added in v0.15.0

func NewGroupAssets(groups []assets.Group) *GroupAssets

NewGroupAssets creates a new set of group assets

func (*GroupAssets) All added in v0.15.0

func (s *GroupAssets) All() []*Group

All returns all the groups

func (*GroupAssets) FindByName added in v0.15.0

func (s *GroupAssets) FindByName(name string) *Group

FindByName looks for a group with the given name (case-insensitive)

func (*GroupAssets) Get added in v0.15.0

func (s *GroupAssets) Get(uuid assets.GroupUUID) *Group

Get returns the group with the given UUID

type GroupList

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

GroupList defines a contact's list of groups

func NewGroupList added in v0.4.0

func NewGroupList(groups []*Group) *GroupList

NewGroupList creates a new group list

func NewGroupListFromAssets added in v0.15.2

func NewGroupListFromAssets(a SessionAssets, groupAssets []assets.Group) (*GroupList, error)

NewGroupListFromAssets creates a new group list

func (*GroupList) Add added in v0.4.0

func (l *GroupList) Add(group *Group) bool

Add adds the given group to this group list

func (*GroupList) All added in v0.4.0

func (l *GroupList) All() []*Group

All returns all groups in this group list

func (*GroupList) Count added in v0.4.0

func (l *GroupList) Count() int

Count returns the number of groups in this group list

func (*GroupList) FindByUUID added in v0.4.0

func (l *GroupList) FindByUUID(uuid assets.GroupUUID) *Group

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

func (*GroupList) Remove added in v0.4.0

func (l *GroupList) Remove(group *Group) bool

Remove removes the given group from this group list

func (GroupList) ToXValue added in v0.32.0

func (l GroupList) ToXValue(env envs.Environment) types.XValue

ToXValue returns a representation of this object for use in expressions

type Hint added in v0.24.0

type Hint interface {
	utils.Typed
}

type Input

type Input interface {
	utils.Typed
	Contextable

	UUID() InputUUID
	CreatedOn() time.Time
	Channel() *Channel
}

Input describes input from the contact and currently we only support one type of input: `msg`

type InputUUID added in v0.4.0

type InputUUID uuids.UUID

InputUUID is the UUID of an input

type Label

type Label struct {
	assets.Label
}

Label represents a message label

func NewLabel

func NewLabel(asset assets.Label) *Label

NewLabel creates a new label from the given asset

func (*Label) Asset added in v0.15.0

func (l *Label) Asset() assets.Label

Asset returns the underlying asset

func (*Label) Reference added in v0.4.0

func (l *Label) Reference() *assets.LabelReference

Reference returns a reference to this label

type LabelAssets added in v0.15.0

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

LabelAssets provides access to all label assets

func NewLabelAssets added in v0.15.0

func NewLabelAssets(labels []assets.Label) *LabelAssets

NewLabelAssets creates a new set of label assets

func (*LabelAssets) All added in v0.15.0

func (s *LabelAssets) All() []*Label

All returns all the labels

func (*LabelAssets) FindByName added in v0.15.0

func (s *LabelAssets) FindByName(name string) *Label

FindByName looks for a label with the given name (case-insensitive)

func (*LabelAssets) Get added in v0.15.0

func (s *LabelAssets) Get(uuid assets.LabelUUID) *Label

Get returns the label with the given UUID

type LegacyExtraContributor added in v0.21.3

type LegacyExtraContributor interface {
	LegacyExtra() Results
}

LegacyExtraContributor is something which contributes results for constructing @legacy_extra

type Localizable added in v0.29.0

type Localizable interface {
	LocalizationUUID() uuids.UUID
}

Localizable is anything in the flow definition which can be localized and therefore needs a UUID

type Localization added in v0.6.2

type Localization interface {
	AddItemTranslation(envs.Language, uuids.UUID, string, []string)
	GetTranslations(envs.Language) Translations
	Languages() []envs.Language
}

Localization provide a way to get the translations for a specific language

type LocationAssets added in v0.15.0

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

LocationAssets provides access to location assets

func NewLocationAssets added in v0.15.0

func NewLocationAssets(hierarchies []assets.LocationHierarchy) *LocationAssets

NewLocationAssets creates a new set of location assets

func (*LocationAssets) Hierarchies added in v0.15.0

func (s *LocationAssets) Hierarchies() []assets.LocationHierarchy

Hierarchies returns all hierarchies

type Modifier added in v0.24.0

type Modifier interface {
	utils.Typed

	Apply(envs.Environment, SessionAssets, *Contact, EventCallback)
}

Modifier is something which can modify a contact

type ModifierCallback added in v0.26.0

type ModifierCallback func(Modifier)

ModifierCallback is a callback invoked when a modifier has been generated

type MsgID added in v0.15.0

type MsgID int64

MsgID is the ID of a message

type MsgIn

type MsgIn struct {
	BaseMsg

	ExternalID_ string `json:"external_id,omitempty"`
}

MsgIn represents a incoming message from the session contact

func NewMsgIn added in v0.6.0

func NewMsgIn(uuid MsgUUID, urn urns.URN, channel *assets.ChannelReference, text string, attachments []utils.Attachment) *MsgIn

NewMsgIn creates a new incoming message

func (*MsgIn) ExternalID added in v0.24.0

func (m *MsgIn) ExternalID() string

ExternalID returns the optional external ID of this incoming message

func (*MsgIn) SetExternalID added in v0.24.0

func (m *MsgIn) SetExternalID(id string)

SetExternalID sets the external ID of this message

type MsgOut

type MsgOut struct {
	BaseMsg

	QuickReplies_ []string       `json:"quick_replies,omitempty"`
	Templating_   *MsgTemplating `json:"templating,omitempty"`
}

MsgOut represents a outgoing message to the session contact

func NewMsgOut added in v0.6.0

func NewMsgOut(urn urns.URN, channel *assets.ChannelReference, text string, attachments []utils.Attachment, quickReplies []string, templating *MsgTemplating) *MsgOut

NewMsgOut creates a new outgoing message

func (*MsgOut) QuickReplies added in v0.6.0

func (m *MsgOut) QuickReplies() []string

QuickReplies returns the quick replies of this outgoing message

func (*MsgOut) Templating added in v0.32.0

func (m *MsgOut) Templating() *MsgTemplating

Templating returns the templating to use to send this message (if any)

type MsgTemplating added in v0.32.0

type MsgTemplating struct {
	Template_  *assets.TemplateReference `json:"template"`
	Language_  envs.Language             `json:"language"`
	Variables_ []string                  `json:"variables,omitempty"`
}

MsgTemplating represents any substituted message template that should be applied when sending this message

func NewMsgTemplating added in v0.32.0

func NewMsgTemplating(template *assets.TemplateReference, language envs.Language, variables []string) *MsgTemplating

NewMsgTemplating creates and returns a new msg template

func (MsgTemplating) Language added in v0.32.0

func (t MsgTemplating) Language() envs.Language

Language returns the language that should be used for the template

func (MsgTemplating) Template added in v0.32.0

func (t MsgTemplating) Template() *assets.TemplateReference

Template returns the template this msg template is for

func (MsgTemplating) Variables added in v0.32.0

func (t MsgTemplating) Variables() []string

Variables returns the variables that should be substituted in the template

type MsgUUID added in v0.6.0

type MsgUUID uuids.UUID

MsgUUID is the UUID of a message

type Node

type Node interface {
	UUID() NodeUUID
	Actions() []Action
	Router() Router
	Exits() []Exit

	Validate(Flow, map[uuids.UUID]bool) error

	EnumerateTemplates(Localization, func(string))
	EnumerateDependencies(Localization, func(assets.Reference))
	EnumerateResults(Node, func(*ResultInfo))
}

Node is a single node in a flow

type NodeUUID

type NodeUUID uuids.UUID

NodeUUID is a UUID of a flow node

type Resthook added in v0.10.20

type Resthook struct {
	assets.Resthook
}

Resthook represents a named event and a set of subscribers

func NewResthook added in v0.10.20

func NewResthook(asset assets.Resthook) *Resthook

NewResthook returns a new resthook object

func (*Resthook) Asset added in v0.15.0

func (r *Resthook) Asset() assets.Resthook

Asset returns the underlying asset

type ResthookAssets added in v0.15.0

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

ResthookAssets provides access to all resthook assets

func NewResthookAssets added in v0.15.0

func NewResthookAssets(resthooks []assets.Resthook) *ResthookAssets

NewResthookAssets creates a new set of resthook assets

func (*ResthookAssets) FindBySlug added in v0.15.0

func (s *ResthookAssets) FindBySlug(slug string) *Resthook

FindBySlug finds the group with the given UUID

type Result

type Result struct {
	Name              string          `json:"name" validate:"required"`
	Value             string          `json:"value"`
	Category          string          `json:"category,omitempty"`
	CategoryLocalized string          `json:"category_localized,omitempty"`
	NodeUUID          NodeUUID        `json:"node_uuid"`
	Input             string          `json:"input,omitempty"`
	Extra             json.RawMessage `json:"extra,omitempty"`
	CreatedOn         time.Time       `json:"created_on" validate:"required"`
}

Result describes a value captured during a run's execution. It might have been implicitly created by a router, or explicitly created by a [set_run_result](#action:set_run_result) action.

func NewResult added in v0.21.1

func NewResult(name string, value string, category string, categoryLocalized string, nodeUUID NodeUUID, input string, extra json.RawMessage, createdOn time.Time) *Result

NewResult creates a new result

func (*Result) Context added in v0.33.8

func (r *Result) Context(env envs.Environment) map[string]types.XValue

Context returns the properties available in expressions

__default__:text -> the value
name:text -> the name of the result
value:text -> the value of the result
category:text -> the category of the result
category_localized:text -> the localized category of the result
input:text -> the input of the result
extra:any -> the extra data of the result such as a webhook response
node_uuid:text -> the UUID of the node in the flow that generated the result
created_on:datetime -> the creation date of the result

@context result

type ResultInfo added in v0.40.0

type ResultInfo struct {
	Key        string     `json:"key"`
	Name       string     `json:"name"`
	Categories []string   `json:"categories"`
	NodeUUIDs  []NodeUUID `json:"node_uuids"`
}

ResultInfo is possible result that a flow might generate

func MergeResultInfos added in v0.40.0

func MergeResultInfos(specs []*ResultInfo) []*ResultInfo

MergeResultInfos merges result specs based on key

func NewResultInfo added in v0.40.0

func NewResultInfo(name string, categories []string, node Node) *ResultInfo

NewResultInfo creates a new result spec

func (*ResultInfo) String added in v0.40.0

func (r *ResultInfo) String() string

type Results

type Results map[string]*Result

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

func NewResults

func NewResults() Results

NewResults creates a new empty set of results

func (Results) Clone added in v0.4.0

func (r Results) Clone() Results

Clone returns a clone of this results set

func (Results) Context added in v0.33.8

func (r Results) Context(env envs.Environment) map[string]types.XValue

Context returns the properties available in expressions

func (Results) Get added in v0.9.10

func (r Results) Get(key string) *Result

Get returns the result with the given key

func (Results) Save

func (r Results) Save(result *Result)

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

type Resume added in v0.20.0

type Resume interface {
	utils.Typed

	Apply(FlowRun, EventCallback) error

	Environment() envs.Environment
	Contact() *Contact
	ResumedOn() time.Time
}

Resume represents something which can resume a session with the flow engine

type Router

type Router interface {
	utils.Typed

	Wait() Wait
	ResultName() string

	Validate([]Exit) error
	AllowTimeout() bool
	Route(FlowRun, Step, EventCallback) (ExitUUID, error)
	RouteTimeout(FlowRun, Step, EventCallback) (ExitUUID, error)

	EnumerateTemplates(Localization, func(string))
	EnumerateDependencies(Localization, func(assets.Reference))
	EnumerateResults(Node, func(*ResultInfo))
}

type RunEnvironment added in v0.8.0

type RunEnvironment interface {
	envs.Environment

	FindLocations(string, utils.LocationLevel, *utils.Location) ([]*utils.Location, error)
	FindLocationsFuzzy(string, utils.LocationLevel, *utils.Location) ([]*utils.Location, error)
	LookupLocation(utils.LocationPath) (*utils.Location, error)
}

RunEnvironment is a run specific environment which adds location functionality required by some router tests

type RunStatus

type RunStatus string

RunStatus represents the current status of the flow run

const (
	// RunStatusActive represents a run that is still active
	RunStatusActive RunStatus = "active"

	// RunStatusCompleted represents a run that has run to completion
	RunStatusCompleted RunStatus = "completed"

	// RunStatusWaiting represents a run which is waiting for something from the caller
	RunStatusWaiting RunStatus = "waiting"

	// RunStatusFailed represents a run that encountered an unrecoverable error
	RunStatusFailed RunStatus = "failed"

	// RunStatusExpired represents a run that expired due to inactivity
	RunStatusExpired RunStatus = "expired"
)

type RunSummary added in v0.4.0

type RunSummary interface {
	UUID() RunUUID
	Contact() *Contact
	Flow() Flow
	Status() RunStatus
	Results() Results
}

RunSummary represents the minimum information available about all runs (current or related) and is the representation of runs made accessible to router tests.

type RunUUID

type RunUUID uuids.UUID

RunUUID is the UUID of a flow run

type Services added in v0.48.0

type Services interface {
	Webhook(Session) (WebhookService, error)
	Classification(Session, *Classifier) (ClassificationService, error)
	Airtime(Session) (AirtimeService, error)
}

Services groups together interfaces for several services whose implementation is provided outside of the flow engine.

type Session

type Session interface {
	Assets() SessionAssets

	UUID() SessionUUID
	Type() FlowType
	SetType(FlowType)

	Environment() envs.Environment
	SetEnvironment(envs.Environment)

	Contact() *Contact
	SetContact(*Contact)

	Input() Input
	SetInput(Input)

	Status() SessionStatus
	Trigger() Trigger
	PushFlow(Flow, FlowRun, bool)
	Wait() ActivatedWait

	Resume(Resume) (Sprint, error)
	Runs() []FlowRun
	GetRun(RunUUID) (FlowRun, error)
	GetCurrentChild(FlowRun) FlowRun
	ParentRun() RunSummary

	Engine() Engine
}

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

type SessionAssets added in v0.4.0

type SessionAssets interface {
	Source() assets.Source

	Channels() *ChannelAssets
	Classifiers() *ClassifierAssets
	Fields() *FieldAssets
	Flows() FlowAssets
	Groups() *GroupAssets
	Labels() *LabelAssets
	Locations() *LocationAssets
	Resthooks() *ResthookAssets
	Templates() *TemplateAssets
}

SessionAssets is the assets available to a session

type SessionStatus added in v0.4.0

type SessionStatus string

SessionStatus represents the current status of the engine session

const (
	// SessionStatusActive represents a session that is still active
	SessionStatusActive SessionStatus = "active"

	// SessionStatusCompleted represents a session that has run to completion
	SessionStatusCompleted SessionStatus = "completed"

	// SessionStatusWaiting represents a session which is waiting for something from the caller
	SessionStatusWaiting SessionStatus = "waiting"

	// SessionStatusFailed represents a session that encountered an unrecoverable error
	SessionStatusFailed SessionStatus = "failed"
)

type SessionUUID added in v0.44.0

type SessionUUID uuids.UUID

SessionUUID is the UUID of a session

type Sprint added in v0.24.0

type Sprint interface {
	Modifiers() []Modifier
	LogModifier(Modifier)
	Events() []Event
	LogEvent(Event)
}

Sprint is an interaction with the engine - i.e. a start or resume of a session

type Step

type Step interface {
	Contextable

	UUID() StepUUID
	NodeUUID() NodeUUID
	ExitUUID() ExitUUID
	ArrivedOn() time.Time

	Leave(ExitUUID)
}

type StepUUID

type StepUUID uuids.UUID

StepUUID is the UUID of a run step

type Template added in v0.32.0

type Template struct {
	assets.Template
}

Template represents messaging templates used by channels types such as WhatsApp

func NewTemplate added in v0.32.0

func NewTemplate(t assets.Template) *Template

NewTemplate returns a new template objects based on the passed in asset

func (*Template) Asset added in v0.32.0

func (t *Template) Asset() assets.Template

Asset returns the underlying asset

func (*Template) FindTranslation added in v0.32.0

func (t *Template) FindTranslation(channel assets.ChannelUUID, langs []envs.Language) *TemplateTranslation

FindTranslation finds the matching translation for the passed in channel and languages (in priority order)

func (*Template) Reference added in v0.38.1

func (t *Template) Reference() *assets.TemplateReference

Reference returns the reference for this template

type TemplateAssets added in v0.32.0

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

TemplateAssets is our type for all the templates in an environment

func NewTemplateAssets added in v0.32.0

func NewTemplateAssets(ts []assets.Template) *TemplateAssets

NewTemplateAssets creates a new template list

func (*TemplateAssets) FindTranslation added in v0.32.0

func (a *TemplateAssets) FindTranslation(uuid assets.TemplateUUID, channel *assets.ChannelReference, langs []envs.Language) *TemplateTranslation

FindTranslation looks through our list of templates to find the template matching the passed in uuid If no template or translation is found then empty string is returned

func (*TemplateAssets) Get added in v0.38.1

Get returns the template with the passed in UUID if any

type TemplateTranslation added in v0.32.0

type TemplateTranslation struct {
	assets.TemplateTranslation
}

TemplateTranslation represents a single translation for a template

func NewTemplateTranslation added in v0.32.0

func NewTemplateTranslation(t assets.TemplateTranslation) *TemplateTranslation

NewTemplateTranslation returns a new TemplateTranslation for the passed in asset

func (*TemplateTranslation) Asset added in v0.32.0

Asset returns the underlying asset

func (*TemplateTranslation) Substitute added in v0.32.0

func (t *TemplateTranslation) Substitute(vars []string) string

Substitute substitutes the passed in variables in our template

type Timeout added in v0.33.0

type Timeout interface {
	Seconds() int
	CategoryUUID() CategoryUUID
}

type Translations

type Translations interface {
	GetTextArray(uuids.UUID, string) []string
	SetTextArray(uuids.UUID, string, []string)
}

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

type Trigger added in v0.4.0

type Trigger interface {
	utils.Typed
	Contextable

	Initialize(Session, EventCallback) error
	InitializeRun(FlowRun, EventCallback) error

	Environment() envs.Environment
	Flow() *assets.FlowReference
	Contact() *Contact
	Connection() *Connection
	Params() *types.XObject
	TriggeredOn() time.Time
}

Trigger represents something which can initiate a session with the flow engine

type TriggerWithRun added in v0.24.0

type TriggerWithRun interface {
	Trigger

	RunSummary() json.RawMessage
}

TriggerWithRun is special case of trigger that provides a parent run to the session

type URNList

type URNList []*ContactURN

URNList is the list of a contact's URNs

func ReadURNList added in v0.6.0

func ReadURNList(a SessionAssets, rawURNs []urns.URN, missing assets.MissingCallback) (URNList, error)

ReadURNList parses contact URN list from the given list of raw URNs

func (URNList) Equal added in v0.23.0

func (l URNList) Equal(other URNList) bool

Equal returns whether this list of URNs is equal to another

func (URNList) MapContext added in v0.31.0

func (l URNList) MapContext(env envs.Environment) map[string]types.XValue

MapContext returns a map of the highest priority URN for each scheme - exposed in expressions as @urns

func (URNList) RawURNs added in v0.6.0

func (l URNList) RawURNs() []urns.URN

RawURNs returns the raw URNs

func (URNList) ToXValue added in v0.32.0

func (l URNList) ToXValue(env envs.Environment) types.XValue

ToXValue returns a representation of this object for use in expressions

func (URNList) WithScheme added in v0.4.4

func (l URNList) WithScheme(scheme string) URNList

WithScheme returns a new URN list containing of only URNs of the given scheme

type Value added in v0.15.2

type Value struct {
	Text     types.XText        `json:"text" validate:"required"`
	Datetime *types.XDateTime   `json:"datetime,omitempty"`
	Number   *types.XNumber     `json:"number,omitempty"`
	State    utils.LocationPath `json:"state,omitempty"`
	District utils.LocationPath `json:"district,omitempty"`
	Ward     utils.LocationPath `json:"ward,omitempty"`
}

Value represents a value in each of the field types

func NewValue added in v0.15.2

func NewValue(text types.XText, datetime *types.XDateTime, number *types.XNumber, state utils.LocationPath, district utils.LocationPath, ward utils.LocationPath) *Value

NewValue creates an empty value

func (*Value) Equals added in v0.19.2

func (v *Value) Equals(o *Value) bool

Equals determines whether two values are equal

type Wait

type Wait interface {
	utils.Typed

	Timeout() Timeout

	Begin(FlowRun, EventCallback) ActivatedWait
	End(Resume) error
}

type WebhookCall added in v0.8.0

type WebhookCall struct {
	URL         string
	Method      string
	StatusCode  int
	Status      CallStatus
	TimeTaken   time.Duration
	Request     []byte
	Response    []byte
	BodyIgnored bool
	Resthook    string
}

WebhookCall is the result of a webhook call

type WebhookService added in v0.49.0

type WebhookService interface {
	Call(session Session, request *http.Request, resthook string) (*WebhookCall, error)
}

WebhookService provides webhook functionality to the engine

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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