-
Notifications
You must be signed in to change notification settings - Fork 19
/
contact_changed.go
47 lines (39 loc) · 1.18 KB
/
contact_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
package events
import "github.com/nyaruka/goflow/flows"
import "encoding/json"
// TypeContactChanged is the type of our set contact event
const TypeContactChanged string = "contact_changed"
// ContactChangedEvent events are created to set a contact on a session
//
// {
// "type": "contact_changed",
// "created_on": "2006-01-02T15:04:05Z",
// "contact": {
// "uuid": "0e06f977-cbb7-475f-9d0b-a0c4aaec7f6a",
// "name": "Bob",
// "urns": ["tel:+11231234567"]
// }
// }
//
// @event contact_changed
type ContactChangedEvent struct {
baseEvent
callerOrEngineEvent
Contact json.RawMessage `json:"contact"`
}
// Type returns the type of this event
func (e *ContactChangedEvent) Type() string { return TypeContactChanged }
// Validate validates our event is valid and has all the assets it needs
func (e *ContactChangedEvent) Validate(assets flows.SessionAssets) error {
return nil
}
// Apply applies this event to the given run
func (e *ContactChangedEvent) Apply(run flows.FlowRun) error {
contact, err := flows.ReadContact(run.Session(), e.Contact)
if err != nil {
return err
}
run.SetContact(contact)
run.Session().SetContact(contact)
return nil
}