-
Notifications
You must be signed in to change notification settings - Fork 19
/
broadcast_created.go
76 lines (67 loc) · 2.62 KB
/
broadcast_created.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package events
import (
"github.com/nyaruka/gocommon/urns"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/utils"
)
func init() {
RegisterType(TypeBroadcastCreated, func() flows.Event { return &BroadcastCreatedEvent{} })
}
// TypeBroadcastCreated is a constant for outgoing message events
const TypeBroadcastCreated string = "broadcast_created"
// BroadcastTranslation is the broadcast content in a particular language
type BroadcastTranslation struct {
Text string `json:"text"`
Attachments []flows.Attachment `json:"attachments,omitempty"`
QuickReplies []string `json:"quick_replies,omitempty"`
}
// BroadcastCreatedEvent events are created for outgoing broadcasts.
//
// {
// "type": "broadcast_created",
// "created_on": "2006-01-02T15:04:05Z",
// "translations": {
// "eng": {
// "text": "hi, what's up",
// "attachments": [],
// "quick_replies": ["All good", "Got 99 problems"]
// },
// "spa": {
// "text": "Que pasa",
// "attachments": [],
// "quick_replies": ["Todo bien", "Tengo 99 problemas"]
// }
// },
// "base_language": "eng",
// "urns": ["tel:+12065551212"],
// "contacts": [{"uuid": "0e06f977-cbb7-475f-9d0b-a0c4aaec7f6a", "name": "Bob"}]
// }
//
// @event broadcast_created
type BroadcastCreatedEvent struct {
BaseEvent
engineOnlyEvent
Translations map[utils.Language]*BroadcastTranslation `json:"translations,min=1" validate:"dive"`
BaseLanguage utils.Language `json:"base_language" validate:"required"`
URNs []urns.URN `json:"urns,omitempty" validate:"dive,urn"`
Contacts []*flows.ContactReference `json:"contacts,omitempty" validate:"dive"`
Groups []*flows.GroupReference `json:"groups,omitempty" validate:"dive"`
}
// NewBroadcastCreatedEvent creates a new outgoing msg event for the given recipients
func NewBroadcastCreatedEvent(translations map[utils.Language]*BroadcastTranslation, baseLanguage utils.Language, urns []urns.URN, contacts []*flows.ContactReference, groups []*flows.GroupReference) *BroadcastCreatedEvent {
event := BroadcastCreatedEvent{
BaseEvent: NewBaseEvent(),
Translations: translations,
BaseLanguage: baseLanguage,
URNs: urns,
Contacts: contacts,
Groups: groups,
}
return &event
}
// Type returns the type of this event
func (e *BroadcastCreatedEvent) Type() string { return TypeBroadcastCreated }
// Apply applies this event to the given run
func (e *BroadcastCreatedEvent) Apply(run flows.FlowRun) error {
return nil
}