-
Notifications
You must be signed in to change notification settings - Fork 19
/
contact_name_changed.go
56 lines (45 loc) · 1.41 KB
/
contact_name_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
56
package events
import (
"fmt"
"github.com/nyaruka/goflow/flows"
)
func init() {
RegisterType(TypeContactNameChanged, func() flows.Event { return &ContactNameChangedEvent{} })
}
// TypeContactNameChanged is the type of our contact name changed event
const TypeContactNameChanged string = "contact_name_changed"
// ContactNameChangedEvent events are created when a name of a contact has been changed
//
// {
// "type": "contact_name_changed",
// "created_on": "2006-01-02T15:04:05Z",
// "name": "Bob Smith"
// }
//
// @event contact_name_changed
type ContactNameChangedEvent struct {
BaseEvent
callerOrEngineEvent
Name string `json:"name"`
}
// NewContactNameChangedEvent returns a new contact name changed event
func NewContactNameChangedEvent(name string) *ContactNameChangedEvent {
return &ContactNameChangedEvent{
BaseEvent: NewBaseEvent(),
Name: name,
}
}
// Type returns the type of this event
func (e *ContactNameChangedEvent) Type() string { return TypeContactNameChanged }
// Validate validates our event is valid and has all the assets it needs
func (e *ContactNameChangedEvent) Validate(assets flows.SessionAssets) error {
return nil
}
// Apply applies this event to the given run
func (e *ContactNameChangedEvent) Apply(run flows.FlowRun) error {
if run.Contact() == nil {
return fmt.Errorf("can't apply event in session without a contact")
}
run.Contact().SetName(e.Name)
return nil
}