-
Notifications
You must be signed in to change notification settings - Fork 20
/
run_result_changed.go
54 lines (47 loc) · 1.68 KB
/
run_result_changed.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
package events
import (
"encoding/json"
"github.com/nyaruka/goflow/flows"
)
func init() {
registerType(TypeRunResultChanged, func() flows.Event { return &RunResultChangedEvent{} })
}
// TypeRunResultChanged is the type of our run result event
const TypeRunResultChanged string = "run_result_changed"
// RunResultChangedEvent events are created when a run result is saved. They contain not only
// the name, value and category of the result, but also the UUID of the node where
// the result was generated.
//
// {
// "type": "run_result_changed",
// "created_on": "2006-01-02T15:04:05Z",
// "name": "Gender",
// "value": "m",
// "category": "Male",
// "category_localized": "Homme",
// "node_uuid": "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d",
// "input": "M"
// }
//
// @event run_result_changed
type RunResultChangedEvent struct {
baseEvent
Name string `json:"name" validate:"required"`
Value string `json:"value"`
Category string `json:"category"`
CategoryLocalized string `json:"category_localized,omitempty"`
Input string `json:"input,omitempty"`
Extra json.RawMessage `json:"extra,omitempty"`
}
// NewRunResultChanged returns a new save result event for the passed in values
func NewRunResultChanged(result *flows.Result) *RunResultChangedEvent {
return &RunResultChangedEvent{
baseEvent: newBaseEvent(TypeRunResultChanged),
Name: result.Name,
Value: result.Value,
Category: result.Category,
CategoryLocalized: result.CategoryLocalized,
Input: result.Input,
Extra: result.Extra,
}
}