-
Notifications
You must be signed in to change notification settings - Fork 19
/
contact_changed.go
55 lines (44 loc) · 1.36 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
48
49
50
51
52
53
54
55
package events
import (
"encoding/json"
"github.com/nyaruka/goflow/flows"
)
func init() {
RegisterType(TypeContactChanged, func() flows.Event { return &ContactChangedEvent{} })
}
// TypeContactChanged is the type of our set contact event
const TypeContactChanged string = "contact_changed"
// ContactChangedEvent events are sent by the caller to tell the engine to update the session contact.
//
// {
// "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
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().Assets(), e.Contact, true)
if err != nil {
return err
}
run.SetContact(contact)
run.Session().SetContact(contact)
return nil
}
var _ flows.CallerEvent = (*ContactChangedEvent)(nil)