Skip to content

Commit

Permalink
Add query to trigger_session and create_broadcast action constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Sep 19, 2024
1 parent b128c81 commit f50648f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
2 changes: 1 addition & 1 deletion flows/actions/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ func (a *voiceAction) AllowedFlowTypes() []flows.FlowType {

// utility struct for actions which operate on other contacts
type otherContactsAction struct {
URNs []urns.URN `json:"urns,omitempty"`
Groups []*assets.GroupReference `json:"groups,omitempty" validate:"dive"`
Contacts []*flows.ContactReference `json:"contacts,omitempty" validate:"dive"`
ContactQuery string `json:"contact_query,omitempty" engine:"evaluated"`
URNs []urns.URN `json:"urns,omitempty"`
LegacyVars []string `json:"legacy_vars,omitempty" engine:"evaluated"`
}

Expand Down
49 changes: 27 additions & 22 deletions flows/actions/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,14 @@ func TestConstructors(t *testing.T) {
"Hi there",
[]string{"http://example.com/red.jpg"},
[]string{"Red", "Blue"},
[]urns.URN{"twitter:nyaruka"},
[]*flows.ContactReference{
flows.NewContactReference(flows.ContactUUID("cbe87f5c-cda2-4f90-b5dd-0ac93a884950"), "Bob Smith"),
},
[]*assets.GroupReference{
assets.NewGroupReference(assets.GroupUUID("b7cf0d83-f1c9-411c-96fd-c511a4cfa86d"), "Testers"),
},
[]*flows.ContactReference{
flows.NewContactReference(flows.ContactUUID("cbe87f5c-cda2-4f90-b5dd-0ac93a884950"), "Bob Smith"),
},
"fields.age > 20",
[]urns.URN{"twitter:nyaruka"},
nil,
),
`{
Expand All @@ -525,19 +526,20 @@ func TestConstructors(t *testing.T) {
"text": "Hi there",
"attachments": ["http://example.com/red.jpg"],
"quick_replies": ["Red", "Blue"],
"urns": ["twitter:nyaruka"],
"groups": [
{
"uuid": "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d",
"name": "Testers"
}
],
"contacts": [
{
"uuid": "cbe87f5c-cda2-4f90-b5dd-0ac93a884950",
"name": "Bob Smith"
}
],
"groups": [
{
"uuid": "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d",
"name": "Testers"
}
]
"contact_query": "fields.age > 20",
"urns": ["twitter:nyaruka"]
}`,
},
{
Expand Down Expand Up @@ -695,13 +697,15 @@ func TestConstructors(t *testing.T) {
actions.NewStartSession(
actionUUID,
assets.NewFlowReference(assets.FlowUUID("fece6eac-9127-4343-9269-56e88f391562"), "Parent"),
[]urns.URN{"twitter:nyaruka"},
[]*flows.ContactReference{
flows.NewContactReference(flows.ContactUUID("cbe87f5c-cda2-4f90-b5dd-0ac93a884950"), "Bob Smith"),
},

[]*assets.GroupReference{
assets.NewGroupReference(assets.GroupUUID("b7cf0d83-f1c9-411c-96fd-c511a4cfa86d"), "Testers"),
},
[]*flows.ContactReference{
flows.NewContactReference(flows.ContactUUID("cbe87f5c-cda2-4f90-b5dd-0ac93a884950"), "Bob Smith"),
},
"fields.age > 20",
[]urns.URN{"twitter:nyaruka"},
nil, // legacy vars
true, // create new contact
),
Expand All @@ -712,19 +716,20 @@ func TestConstructors(t *testing.T) {
"uuid": "fece6eac-9127-4343-9269-56e88f391562",
"name": "Parent"
},
"urns": ["twitter:nyaruka"],
"contacts": [
{
"uuid": "cbe87f5c-cda2-4f90-b5dd-0ac93a884950",
"name": "Bob Smith"
}
],
"groups": [
{
"uuid": "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d",
"name": "Testers"
}
],
"contacts": [
{
"uuid": "cbe87f5c-cda2-4f90-b5dd-0ac93a884950",
"name": "Bob Smith"
}
],
"contact_query": "fields.age > 20",
"urns": ["twitter:nyaruka"],
"exclusions": {},
"create_contact": true
}`,
Expand Down
11 changes: 6 additions & 5 deletions flows/actions/send_broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ type SendBroadcastAction struct {
}

// NewSendBroadcast creates a new send broadcast action
func NewSendBroadcast(uuid flows.ActionUUID, text string, attachments []string, quickReplies []string, urns []urns.URN, contacts []*flows.ContactReference, groups []*assets.GroupReference, legacyVars []string) *SendBroadcastAction {
func NewSendBroadcast(uuid flows.ActionUUID, text string, attachments []string, quickReplies []string, groups []*assets.GroupReference, contacts []*flows.ContactReference, contactQuery string, urns []urns.URN, legacyVars []string) *SendBroadcastAction {
return &SendBroadcastAction{
baseAction: newBaseAction(TypeSendBroadcast, uuid),
otherContactsAction: otherContactsAction{
URNs: urns,
Contacts: contacts,
Groups: groups,
LegacyVars: legacyVars,
Groups: groups,
Contacts: contacts,
ContactQuery: contactQuery,
URNs: urns,
LegacyVars: legacyVars,
},
createMsgAction: createMsgAction{
Text: text,
Expand Down
11 changes: 6 additions & 5 deletions flows/actions/start_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ type StartSessionAction struct {
}

// NewStartSession creates a new start session action
func NewStartSession(uuid flows.ActionUUID, flow *assets.FlowReference, urns []urns.URN, contacts []*flows.ContactReference, groups []*assets.GroupReference, legacyVars []string, createContact bool) *StartSessionAction {
func NewStartSession(uuid flows.ActionUUID, flow *assets.FlowReference, groups []*assets.GroupReference, contacts []*flows.ContactReference, contactQuery string, urns []urns.URN, legacyVars []string, createContact bool) *StartSessionAction {
return &StartSessionAction{
baseAction: newBaseAction(TypeStartSession, uuid),
otherContactsAction: otherContactsAction{
URNs: urns,
Contacts: contacts,
Groups: groups,
LegacyVars: legacyVars,
Groups: groups,
Contacts: contacts,
ContactQuery: contactQuery,
URNs: urns,
LegacyVars: legacyVars,
},
Flow: flow,
CreateContact: createContact,
Expand Down

0 comments on commit f50648f

Please sign in to comment.