-
Notifications
You must be signed in to change notification settings - Fork 20
/
flows.go
44 lines (35 loc) · 1.27 KB
/
flows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package flows
import (
"github.com/go-playground/validator/v10"
"github.com/nyaruka/goflow/utils"
)
func init() {
utils.RegisterValidatorAlias("flow_type", "eq=messaging|eq=messaging_background|eq=messaging_offline|eq=voice", func(validator.FieldError) string {
return "is not a valid flow type"
})
}
// FlowType represents the different types of flows
type FlowType string
const (
// FlowTypeMessaging is a flow that is run over a messaging channel
FlowTypeMessaging FlowType = "messaging"
// FlowTypeMessagingBackground is a non-interactive messaging flow (i.e. never waits for input)
FlowTypeMessagingBackground FlowType = "messaging_background"
// 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"
)
// Allows returns whether this flow type allows the given item
func (t FlowType) Allows(r FlowTypeRestricted) bool {
for _, allowedType := range r.AllowedFlowTypes() {
if t == allowedType {
return true
}
}
return false
}
// FlowTypeRestricted is a part of a flow which can be restricted to certain flow types
type FlowTypeRestricted interface {
AllowedFlowTypes() []FlowType
}