From f50648fcc15321b4b77f289e4876de93e2281eff Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Thu, 19 Sep 2024 13:23:27 -0500 Subject: [PATCH] Add query to trigger_session and create_broadcast action constructors --- flows/actions/base.go | 2 +- flows/actions/base_test.go | 49 ++++++++++++++++++--------------- flows/actions/send_broadcast.go | 11 ++++---- flows/actions/start_session.go | 11 ++++---- 4 files changed, 40 insertions(+), 33 deletions(-) diff --git a/flows/actions/base.go b/flows/actions/base.go index 08ca13224..5a2dee0d2 100644 --- a/flows/actions/base.go +++ b/flows/actions/base.go @@ -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"` } diff --git a/flows/actions/base_test.go b/flows/actions/base_test.go index 14d777a4b..92a55867a 100644 --- a/flows/actions/base_test.go +++ b/flows/actions/base_test.go @@ -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, ), `{ @@ -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"] }`, }, { @@ -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 ), @@ -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 }`, diff --git a/flows/actions/send_broadcast.go b/flows/actions/send_broadcast.go index d34f421c4..408081f3e 100644 --- a/flows/actions/send_broadcast.go +++ b/flows/actions/send_broadcast.go @@ -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, diff --git a/flows/actions/start_session.go b/flows/actions/start_session.go index 1fc56b3b7..6a5c4d456 100644 --- a/flows/actions/start_session.go +++ b/flows/actions/start_session.go @@ -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,