forked from nyaruka/goflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flow_exited.go
77 lines (61 loc) · 2.03 KB
/
flow_exited.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package events
import (
"fmt"
"time"
"github.com/nyaruka/goflow/flows"
)
// TypeFlowExited is the type of our flow exit
const TypeFlowExited string = "flow_exited"
// FlowExitedEvent events are created when a contact exits a flow. It contains not only the
// contact and flow which was exited, but also the time it was exited and the exit status.
//
// ```
// {
// "type": "flow_exited",
// "step_uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
// "created_on": "2006-01-02T15:04:05Z",
// "flow_uuid": "0e06f977-cbb7-475f-9d0b-a0c4aaec7f6a",
// "contact_uuid": "95eb96df-461b-4668-b168-727f8ceb13dd",
// "exited_on": "2006-01-02T15:04:05Z",
// "status": "C"
// }
// ```
//
// @event flow_exited
type FlowExitedEvent struct {
BaseEvent
FlowUUID flows.FlowUUID `json:"flow_uuid" validate:"required"`
ContactUUID flows.ContactUUID `json:"contact_uuid" validate:"required"`
Status flows.RunStatus `json:"status" validate:"required"`
ExitedOn *time.Time `json:"exited_on" validate:"required"`
}
// NewFlowExitedEvent returns a new flow exit event
func NewFlowExitedEvent(run flows.FlowRunReference) *FlowExitedEvent {
event := FlowExitedEvent{FlowUUID: run.FlowUUID(), Status: run.Status(), ContactUUID: run.ContactUUID(), ExitedOn: run.ExitedOn()}
return &event
}
// Type returns the type of our event
func (e *FlowExitedEvent) Type() string { return TypeFlowExited }
// Resolve resolves the passed in key
func (e *FlowExitedEvent) Resolve(key string) interface{} {
switch key {
case "contact_uuid":
return e.ContactUUID
case "exited_on":
return e.ExitedOn
case "flow_uuid":
return e.FlowUUID
case "status":
return e.Status
}
return fmt.Errorf("no such field '%s' on Flow Exit event", key)
}
// Default returns the default value for this event
func (e *FlowExitedEvent) Default() interface{} {
return e
}
// String returns the default string value
func (e *FlowExitedEvent) String() string {
return string(e.FlowUUID)
}
var _ flows.Input = (*FlowExitedEvent)(nil)