-
Notifications
You must be signed in to change notification settings - Fork 19
/
contact_urn_added.go
54 lines (43 loc) · 1.38 KB
/
contact_urn_added.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 (
"fmt"
"github.com/nyaruka/gocommon/urns"
"github.com/nyaruka/goflow/flows"
)
func init() {
RegisterType(TypeContactURNAdded, func() flows.Event { return &ContactURNAddedEvent{} })
}
// TypeContactURNAdded is the type of our add URN event
const TypeContactURNAdded string = "contact_urn_added"
// ContactURNAddedEvent events will be created with the URN that should be added to the current contact.
//
// {
// "type": "contact_urn_added",
// "created_on": "2006-01-02T15:04:05Z",
// "urn": "tel:+12345678900"
// }
//
// @event contact_urn_added
type ContactURNAddedEvent struct {
BaseEvent
callerOrEngineEvent
URN urns.URN `json:"urn" validate:"urn"`
}
// NewURNAddedEvent returns a new add URN event
func NewURNAddedEvent(urn urns.URN) *ContactURNAddedEvent {
return &ContactURNAddedEvent{BaseEvent: NewBaseEvent(), URN: urn}
}
// Type returns the type of this event
func (e *ContactURNAddedEvent) Type() string { return TypeContactURNAdded }
// Validate validates our event is valid and has all the assets it needs
func (e *ContactURNAddedEvent) Validate(assets flows.SessionAssets) error {
return nil
}
// Apply applies this event to the given run
func (e *ContactURNAddedEvent) Apply(run flows.FlowRun) error {
if run.Contact() == nil {
return fmt.Errorf("can't apply event in session without a contact")
}
run.Contact().AddURN(e.URN)
return nil
}