Skip to content

Commit

Permalink
Merge pull request #1192 from nyaruka/contact_required
Browse files Browse the repository at this point in the history
Drop support for contact-less sessions
  • Loading branch information
rowanseymour authored Oct 6, 2023
2 parents e3856f2 + c35e2a2 commit fbb853d
Show file tree
Hide file tree
Showing 41 changed files with 61 additions and 754 deletions.
7 changes: 0 additions & 7 deletions flows/actions/add_contact_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package actions
import (
"github.com/nyaruka/goflow/assets"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/flows/events"
"github.com/nyaruka/goflow/flows/modifiers"
)

Expand Down Expand Up @@ -44,12 +43,6 @@ func NewAddContactGroups(uuid flows.ActionUUID, groups []*assets.GroupReference)

// Execute adds our contact to the specified groups
func (a *AddContactGroupsAction) Execute(run flows.Run, step flows.Step, logModifier flows.ModifierCallback, logEvent flows.EventCallback) error {
contact := run.Contact()
if contact == nil {
logEvent(events.NewErrorf("can't execute action in session without a contact"))
return nil
}

groups := resolveGroups(run, a.Groups, logEvent)

a.applyModifier(run, modifiers.NewGroups(groups, modifiers.GroupsAdd), logModifier, logEvent)
Expand Down
7 changes: 0 additions & 7 deletions flows/actions/add_contact_urn.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ func NewAddContactURN(uuid flows.ActionUUID, scheme string, path string) *AddCon

// Execute runs the labeling action
func (a *AddContactURNAction) Execute(run flows.Run, step flows.Step, logModifier flows.ModifierCallback, logEvent flows.EventCallback) error {
// only generate event if run has a contact
contact := run.Contact()
if contact == nil {
logEvent(events.NewErrorf("can't execute action in session without a contact"))
return nil
}

evaluatedPath, err := run.EvaluateTemplate(a.Path)

// if we received an error, log it although it might just be a non-expression like [email protected]
Expand Down
32 changes: 14 additions & 18 deletions flows/actions/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func testActionType(t *testing.T, assetsJSON json.RawMessage, typeName string) {
Description string `json:"description"`
HTTPMocks *httpx.MockRequestor `json:"http_mocks,omitempty"`
SMTPError string `json:"smtp_error,omitempty"`
NoContact bool `json:"no_contact,omitempty"`
Contact json.RawMessage `json:"contact,omitempty"`
HasTicket bool `json:"has_ticket,omitempty"`
NoInput bool `json:"no_input,omitempty"`
Expand Down Expand Up @@ -165,26 +164,23 @@ func testActionType(t *testing.T, assetsJSON json.RawMessage, typeName string) {
}

// optionally load our contact
var contact *flows.Contact
if !tc.NoContact {
contactJSON := defaultContactJSON
if tc.Contact != nil {
contactJSON = tc.Contact
}
contactJSON := defaultContactJSON
if tc.Contact != nil {
contactJSON = tc.Contact
}

contact, err = flows.ReadContact(sa, contactJSON, assets.PanicOnMissing)
require.NoError(t, err)
contact, err := flows.ReadContact(sa, contactJSON, assets.PanicOnMissing)
require.NoError(t, err)

if tc.HasTicket {
ticketer := sa.Ticketers().Get("d605bb96-258d-4097-ad0a-080937db2212")
topic := sa.Topics().Get("0d9a2c56-6fc2-4f27-93c5-a6322e26b740")
contact.SetTicket(flows.NewTicket("7f44b065-ec28-4d7a-bbb4-0bda3b75b19d", ticketer, topic, "Help", "", nil))
}
if tc.HasTicket {
ticketer := sa.Ticketers().Get("d605bb96-258d-4097-ad0a-080937db2212")
topic := sa.Topics().Get("0d9a2c56-6fc2-4f27-93c5-a6322e26b740")
contact.SetTicket(flows.NewTicket("7f44b065-ec28-4d7a-bbb4-0bda3b75b19d", ticketer, topic, "Help", "", nil))
}

// and switch their language
if tc.Localization != nil {
contact.SetLanguage(i18n.Language("spa"))
}
// and switch their language
if tc.Localization != nil {
contact.SetLanguage(i18n.Language("spa"))
}

envBuilder := envs.NewBuilder().
Expand Down
7 changes: 0 additions & 7 deletions flows/actions/remove_contact_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package actions
import (
"github.com/nyaruka/goflow/assets"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/flows/events"
"github.com/nyaruka/goflow/flows/modifiers"

"github.com/pkg/errors"
Expand Down Expand Up @@ -57,12 +56,6 @@ func (a *RemoveContactGroupsAction) Validate() error {

// Execute runs the action
func (a *RemoveContactGroupsAction) Execute(run flows.Run, step flows.Step, logModifier flows.ModifierCallback, logEvent flows.EventCallback) error {
contact := run.Contact()
if contact == nil {
logEvent(events.NewErrorf("can't execute action in session without a contact"))
return nil
}

var groups []*flows.Group

if a.AllGroups {
Expand Down
5 changes: 0 additions & 5 deletions flows/actions/send_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ func NewSendMsg(uuid flows.ActionUUID, text string, attachments []string, quickR

// Execute runs this action
func (a *SendMsgAction) Execute(run flows.Run, step flows.Step, logModifier flows.ModifierCallback, logEvent flows.EventCallback) error {
if run.Contact() == nil {
logEvent(events.NewErrorf("can't execute action in session without a contact"))
return nil
}

// a message to a non-active contact is unsendable but can still be created
unsendableReason := flows.NilUnsendableReason
if run.Contact().Status() != flows.ContactStatusActive {
Expand Down
6 changes: 0 additions & 6 deletions flows/actions/set_contact_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ func NewSetContactChannel(uuid flows.ActionUUID, channel *assets.ChannelReferenc

// Execute runs our action
func (a *SetContactChannelAction) Execute(run flows.Run, step flows.Step, logModifier flows.ModifierCallback, logEvent flows.EventCallback) error {
contact := run.Contact()
if contact == nil {
logEvent(events.NewErrorf("can't execute action in session without a contact"))
return nil
}

var channel *flows.Channel
if a.Channel != nil {
channel = run.Session().Assets().Channels().Get(a.Channel.UUID)
Expand Down
5 changes: 0 additions & 5 deletions flows/actions/set_contact_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ func NewSetContactField(uuid flows.ActionUUID, field *assets.FieldReference, val

// Execute runs this action
func (a *SetContactFieldAction) Execute(run flows.Run, step flows.Step, logModifier flows.ModifierCallback, logEvent flows.EventCallback) error {
if run.Contact() == nil {
logEvent(events.NewErrorf("can't execute action in session without a contact"))
return nil
}

value, err := run.EvaluateTemplate(a.Value)
value = strings.TrimSpace(value)

Expand Down
5 changes: 0 additions & 5 deletions flows/actions/set_contact_language.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ func NewSetContactLanguage(uuid flows.ActionUUID, language string) *SetContactLa

// Execute runs this action
func (a *SetContactLanguageAction) Execute(run flows.Run, step flows.Step, logModifier flows.ModifierCallback, logEvent flows.EventCallback) error {
if run.Contact() == nil {
logEvent(events.NewErrorf("can't execute action in session without a contact"))
return nil
}

language, err := run.EvaluateTemplate(a.Language)
language = strings.TrimSpace(language)

Expand Down
5 changes: 0 additions & 5 deletions flows/actions/set_contact_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ func NewSetContactName(uuid flows.ActionUUID, name string) *SetContactNameAction

// Execute runs this action
func (a *SetContactNameAction) Execute(run flows.Run, step flows.Step, logModifier flows.ModifierCallback, logEvent flows.EventCallback) error {
if run.Contact() == nil {
logEvent(events.NewErrorf("can't execute action in session without a contact"))
return nil
}

name, err := run.EvaluateTemplate(a.Name)
name = strings.TrimSpace(name)

Expand Down
6 changes: 0 additions & 6 deletions flows/actions/set_contact_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package actions

import (
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/flows/events"
"github.com/nyaruka/goflow/flows/modifiers"
)

Expand Down Expand Up @@ -40,11 +39,6 @@ func NewSetContactStatus(uuid flows.ActionUUID, status flows.ContactStatus) *Set

// Execute runs this action
func (a *SetContactStatusAction) Execute(run flows.Run, step flows.Step, logModifier flows.ModifierCallback, logEvent flows.EventCallback) error {
if run.Contact() == nil {
logEvent(events.NewErrorf("can't execute action in session without a contact"))
return nil
}

a.applyModifier(run, modifiers.NewStatus(a.Status), logModifier, logEvent)
return nil
}
5 changes: 0 additions & 5 deletions flows/actions/set_contact_timezone.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ func NewSetContactTimezone(uuid flows.ActionUUID, timezone string) *SetContactTi

// Execute runs this action
func (a *SetContactTimezoneAction) Execute(run flows.Run, step flows.Step, logModifier flows.ModifierCallback, logEvent flows.EventCallback) error {
if run.Contact() == nil {
logEvent(events.NewErrorf("can't execute action in session without a contact"))
return nil
}

timezone, err := run.EvaluateTemplate(a.Timezone)
timezone = strings.TrimSpace(timezone)

Expand Down
22 changes: 0 additions & 22 deletions flows/actions/testdata/add_contact_groups.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,4 @@
[
{
"description": "Error event if session has no contact",
"no_contact": true,
"action": {
"type": "add_contact_groups",
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"groups": [
{
"uuid": "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d",
"name": "Testers"
}
]
},
"events": [
{
"type": "error",
"created_on": "2018-10-18T14:20:30.000123456Z",
"step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c",
"text": "can't execute action in session without a contact"
}
]
},
{
"description": "Error event and NOOP for missing group",
"action": {
Expand Down
28 changes: 0 additions & 28 deletions flows/actions/testdata/add_contact_urn.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,4 @@
[
{
"description": "Error event if session has no contact",
"no_contact": true,
"action": {
"type": "add_contact_urn",
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"scheme": "tel",
"path": "+1234567890"
},
"events": [
{
"type": "error",
"created_on": "2018-10-18T14:20:30.000123456Z",
"step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c",
"text": "can't execute action in session without a contact"
}
],
"templates": [
"+1234567890"
],
"inspection": {
"dependencies": [],
"issues": [],
"results": [],
"waiting_exits": [],
"parent_refs": []
}
},
{
"description": "Error event if path evaluates to empty",
"action": {
Expand Down
22 changes: 0 additions & 22 deletions flows/actions/testdata/remove_contact_groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,6 @@
},
"read_error": "can't specify specific groups when all_groups=true"
},
{
"description": "Error event if session has no contact",
"no_contact": true,
"action": {
"type": "remove_contact_groups",
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"groups": [
{
"uuid": "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d",
"name": "Testers"
}
]
},
"events": [
{
"type": "error",
"created_on": "2018-10-18T14:20:30.000123456Z",
"step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c",
"text": "can't execute action in session without a contact"
}
]
},
{
"description": "Error event if a group is query based",
"action": {
Expand Down
44 changes: 0 additions & 44 deletions flows/actions/testdata/send_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,50 +21,6 @@
},
"read_error": "field 'topic' is not a valid message topic"
},
{
"description": "Error event if session has no contact",
"no_contact": true,
"action": {
"type": "send_msg",
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"text": "Hi there",
"attachments": [
"http://example.com/red.jpg"
],
"quick_replies": [
"Red",
"Blue"
],
"all_urns": true
},
"events": [
{
"type": "error",
"created_on": "2018-10-18T14:20:30.000123456Z",
"step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c",
"text": "can't execute action in session without a contact"
}
],
"templates": [
"Hi there",
"http://example.com/red.jpg",
"Red",
"Blue"
],
"localizables": [
"Hi there",
"http://example.com/red.jpg",
"Red",
"Blue"
],
"inspection": {
"dependencies": [],
"issues": [],
"results": [],
"waiting_exits": [],
"parent_refs": []
}
},
{
"description": "Error events if msg text, attachments and quick replies have expression errors",
"action": {
Expand Down
20 changes: 0 additions & 20 deletions flows/actions/testdata/set_contact_channel.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
[
{
"description": "Error event if session has no contact",
"no_contact": true,
"action": {
"type": "set_contact_channel",
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"channel": {
"uuid": "57f1078f-88aa-46f4-a59a-948a5739c03d",
"name": "My Android Phone"
}
},
"events": [
{
"type": "error",
"created_on": "2018-10-18T14:20:30.000123456Z",
"step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c",
"text": "can't execute action in session without a contact"
}
]
},
{
"description": "NOOP if channel doesn't change",
"action": {
Expand Down
Loading

0 comments on commit fbb853d

Please sign in to comment.