-
Notifications
You must be signed in to change notification settings - Fork 20
/
environment_changed.go
51 lines (42 loc) · 1.27 KB
/
environment_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
package events
import (
"encoding/json"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/utils"
)
// TypeEnvironmentChanged is the type of our environment changed event
const TypeEnvironmentChanged string = "environment_changed"
// EnvironmentChangedEvent events are created to set the environment on a session
//
// {
// "type": "environment_changed",
// "created_on": "2006-01-02T15:04:05Z",
// "environment": {
// "date_format": "YYYY-MM-DD",
// "time_format": "hh:mm",
// "timezone": "Africa/Kigali",
// "languages": ["eng", "fra"]
// }
// }
//
// @event environment_changed
type EnvironmentChangedEvent struct {
baseEvent
callerOnlyEvent
Environment json.RawMessage `json:"environment"`
}
// Type returns the type of this event
func (e *EnvironmentChangedEvent) Type() string { return TypeEnvironmentChanged }
// Validate validates our event is valid and has all the assets it needs
func (e *EnvironmentChangedEvent) Validate(assets flows.SessionAssets) error {
return nil
}
// Apply applies this event to the given run
func (e *EnvironmentChangedEvent) Apply(run flows.FlowRun) error {
env, err := utils.ReadEnvironment(e.Environment)
if err != nil {
return err
}
run.Session().SetEnvironment(env)
return nil
}