Skip to content

Commit

Permalink
Rename contact actions
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Mar 12, 2018
1 parent 0b5ff74 commit d9585e5
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 85 deletions.
8 changes: 4 additions & 4 deletions cmd/flowrunner/testdata/flows/all_actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
},
{
"uuid": "ca5138c1-2a26-44c6-a29c-6ef695bc67ee",
"type": "add_urn",
"type": "add_contact_urn",
"scheme": "twitter",
"path": "@(replace(lower(contact.name), \" \", \"_\"))"
},
{
"uuid": "7bd8b3bf-0a3c-4928-bc46-df416e77ddf4",
"type": "save_contact_field",
"type": "set_contact_field",
"field": {
"key": "activation_token",
"label": "Activation Token"
Expand Down Expand Up @@ -147,13 +147,13 @@
},
{
"uuid": "f3581032-e122-45ee-8be7-4f3c955d97f8",
"type": "update_contact",
"type": "set_contact_property",
"field_name": "language",
"value": "eng"
},
{
"uuid": "7bd8b3bf-0a3c-4928-bc46-df416e77ddf4",
"type": "save_contact_field",
"type": "set_contact_field",
"field": {
"key": "gender",
"label": "Gender"
Expand Down
2 changes: 1 addition & 1 deletion cmd/flowrunner/testdata/flows/brochure.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"actions": [
{
"uuid": "455ba297-f6d2-45e6-bf3e-c1ef028b55ae",
"type": "update_contact",
"type": "set_contact_property",
"field_name": "name",
"value": "@run.input.text"
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/flowrunner/testdata/flows/date_parse.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"actions": [
{
"uuid": "afd5ac22-2a86-4576-a2c7-715f0bb10194",
"type": "save_contact_field",
"type": "set_contact_field",
"field": {
"key": "birth_date",
"label": "Birth Date"
Expand Down
4 changes: 2 additions & 2 deletions cmd/flowrunner/testdata/flows/default_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
"uuid": "2929d2fc-2778-4d98-a4bc-73a7345710b0",
"actions": [
{
"type": "update_contact",
"type": "set_contact_property",
"uuid": "aafb505c-603d-4025-864d-471345ed236d",
"field_name": "name",
"value": "@run.results.contact_name"
},
{
"type": "save_contact_field",
"type": "set_contact_field",
"uuid": "aafb505c-603d-4025-864d-471345ed237d",
"field": {
"key": "first_name",
Expand Down
8 changes: 4 additions & 4 deletions cmd/flowrunner/testdata/flows/dynamic_groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"actions": [
{
"uuid": "7bd8b3bf-0a3c-4928-bc46-df416e77ddf4",
"type": "save_contact_field",
"type": "set_contact_field",
"field": {
"key": "gender",
"label": "Gender"
Expand All @@ -21,7 +21,7 @@
},
{
"uuid": "ee4cd27e-1296-40fd-ac9c-8cd43e9fb8b5",
"type": "save_contact_field",
"type": "set_contact_field",
"field": {
"key": "age",
"label": "Age"
Expand All @@ -35,7 +35,7 @@
},
{
"uuid": "bc94b3ba-4aad-410a-ae71-1861f69da0fe",
"type": "add_urn",
"type": "add_contact_urn",
"scheme": "tel",
"path": "+250781234567"
},
Expand All @@ -46,7 +46,7 @@
},
{
"uuid": "4ecf6abd-e8c8-424b-aef6-e904cf5b4fbe",
"type": "save_contact_field",
"type": "set_contact_field",
"field": {
"key": "age",
"label": "Age"
Expand Down
2 changes: 1 addition & 1 deletion cmd/flowrunner/testdata/flows/no_contact.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
{
"uuid": "ca5138c1-2a26-44c6-a29c-6ef695bc67ee",
"type": "add_urn",
"type": "add_contact_urn",
"scheme": "twitter",
"path": "@(replace(lower(contact.name), \" \", \"_\"))"
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flowrunner/testdata/flows/two_questions.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"actions": [
{
"uuid": "afd5ac22-2a86-4576-a2c7-715f0bb10194",
"type": "update_contact",
"type": "set_contact_property",
"field_name": "language",
"value": "fra"
},
Expand Down
18 changes: 9 additions & 9 deletions flows/actions/add_urn.go → flows/actions/add_contact_urn.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,39 @@ import (
"github.com/nyaruka/goflow/flows/events"
)

// TypeAddURN is our type for add URN actions
const TypeAddURN string = "add_urn"
// TypeAddContactURN is our type for add URN actions
const TypeAddContactURN string = "add_contact_urn"

// AddURNAction can be used to add a URN to the current contact. An `contact_urn_added` event
// AddContactURNAction can be used to add a URN to the current contact. An `contact_urn_added` event
// will be created when this action is encountered. If there is no contact then this
// action will be ignored.
//
// ```
// {
// "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
// "type": "add_urn",
// "type": "add_contact_urn",
// "scheme": "tel",
// "path": "@flow.phone_number"
// }
// ```
//
// @action add_urn
type AddURNAction struct {
// @action add_contact_urn
type AddContactURNAction struct {
BaseAction
Scheme string `json:"scheme" validate:"urnscheme"`
Path string `json:"path" validate:"required"`
}

// Type returns the type of this action
func (a *AddURNAction) Type() string { return TypeAddURN }
func (a *AddContactURNAction) Type() string { return TypeAddContactURN }

// Validate validates our action is valid and has all the assets it needs
func (a *AddURNAction) Validate(assets flows.SessionAssets) error {
func (a *AddContactURNAction) Validate(assets flows.SessionAssets) error {
return nil
}

// Execute runs the labeling action
func (a *AddURNAction) Execute(run flows.FlowRun, step flows.Step, log flows.EventLog) error {
func (a *AddContactURNAction) Execute(run flows.FlowRun, step flows.Step, log flows.EventLog) error {
// only generate event if run has a contact
contact := run.Contact()
if contact == nil {
Expand Down
20 changes: 10 additions & 10 deletions flows/actions/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func ActionFromEnvelope(envelope *utils.TypedEnvelope) (flows.Action, error) {
action = &AddInputLabelsAction{}
case TypeAddContactGroups:
action = &AddContactGroupsAction{}
case TypeAddURN:
action = &AddURNAction{}
case TypeAddContactURN:
action = &AddContactURNAction{}
case TypeSendEmail:
action = &EmailAction{}
case TypeStartFlow:
Expand All @@ -25,18 +25,18 @@ func ActionFromEnvelope(envelope *utils.TypedEnvelope) (flows.Action, error) {
action = &StartSessionAction{}
case TypeSendMsg:
action = &SendMsgAction{}
case TypeRemoveFromGroup:
action = &RemoveFromGroupAction{}
case TypeRemoveContactGroups:
action = &RemoveContactGroupsAction{}
case TypeReply:
action = &ReplyAction{}
case TypeSaveFlowResult:
action = &SaveFlowResultAction{}
case TypeSaveContactField:
action = &SaveContactField{}
case TypeSetPreferredChannel:
action = &PreferredChannelAction{}
case TypeUpdateContact:
action = &UpdateContactAction{}
case TypeSetContactField:
action = &SetContactFieldAction{}
case TypeSetContactChannel:
action = &SetContactChannelAction{}
case TypeSetContactProperty:
action = &SetContactPropertyAction{}
case TypeCallWebhook:
action = &WebhookAction{}
default:
Expand Down
14 changes: 7 additions & 7 deletions flows/actions/remove_contact_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"github.com/nyaruka/goflow/flows/events"
)

// TypeRemoveFromGroup is our type for our remove from group action
const TypeRemoveFromGroup string = "remove_contact_groups"
// TypeRemoveContactGroups is our type for our remove from group action
const TypeRemoveContactGroups string = "remove_contact_groups"

// RemoveFromGroupAction can be used to remove a contact from one or more groups. A `contact_groups_removed` event will be created
// RemoveContactGroupsAction can be used to remove a contact from one or more groups. A `contact_groups_removed` event will be created
// for the groups which the contact is removed from. If no groups are specified, then the contact will be removed from
// all groups.
//
Expand All @@ -26,22 +26,22 @@ const TypeRemoveFromGroup string = "remove_contact_groups"
// ```
//
// @action remove_contact_groups
type RemoveFromGroupAction struct {
type RemoveContactGroupsAction struct {
BaseAction
Groups []*flows.GroupReference `json:"groups" validate:"required,min=1,dive"`
}

// Type returns the type of this action
func (a *RemoveFromGroupAction) Type() string { return TypeRemoveFromGroup }
func (a *RemoveContactGroupsAction) Type() string { return TypeRemoveContactGroups }

// Validate validates our action is valid and has all the assets it needs
func (a *RemoveFromGroupAction) Validate(assets flows.SessionAssets) error {
func (a *RemoveContactGroupsAction) Validate(assets flows.SessionAssets) error {
// check we have all groups
return a.validateGroups(assets, a.Groups)
}

// Execute runs the action
func (a *RemoveFromGroupAction) Execute(run flows.FlowRun, step flows.Step, log flows.EventLog) error {
func (a *RemoveContactGroupsAction) Execute(run flows.FlowRun, step flows.Step, log flows.EventLog) error {
contact := run.Contact()
if contact == nil {
log.Add(events.NewFatalErrorEvent(fmt.Errorf("can't execute action in session without a contact")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ import (
"github.com/nyaruka/goflow/flows/events"
)

const TypeSetPreferredChannel string = "set_preferred_channel"
const TypeSetContactChannel string = "set_contact_channel"

type PreferredChannelAction struct {
type SetContactChannelAction struct {
BaseAction
Channel *flows.ChannelReference `json:"channel"`
}

// Type returns the type of this action
func (a *PreferredChannelAction) Type() string { return TypeSetPreferredChannel }
func (a *SetContactChannelAction) Type() string { return TypeSetContactChannel }

// Validate validates our action is valid and has all the assets it needs
func (a *PreferredChannelAction) Validate(assets flows.SessionAssets) error {
func (a *SetContactChannelAction) Validate(assets flows.SessionAssets) error {
_, err := assets.GetChannel(a.Channel.UUID)
return err
}

func (a *PreferredChannelAction) Execute(run flows.FlowRun, step flows.Step, log flows.EventLog) error {
func (a *SetContactChannelAction) Execute(run flows.FlowRun, step flows.Step, log flows.EventLog) error {
if run.Contact() == nil {
log.Add(events.NewFatalErrorEvent(fmt.Errorf("can't execute action in session without a contact")))
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,39 @@ import (
"github.com/nyaruka/goflow/utils"
)

// TypeSaveContactField is the type for our save to contact action
const TypeSaveContactField string = "save_contact_field"
// TypeSetContactField is the type for our set contact field action
const TypeSetContactField string = "set_contact_field"

// SaveContactField can be used to save a value to a contact. The value can be a template and will
// SetContactFieldAction can be used to save a value to a contact. The value can be a template and will
// be evaluated during the flow. A `contact_field_changed` event will be created with the corresponding value.
//
// ```
// {
// "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
// "type": "save_contact_field",
// "type": "set_contact_field",
// "field": {"key": "gender", "label": "Gender"},
// "value": "Male"
// }
// ```
//
// @action save_contact_field
type SaveContactField struct {
// @action set_contact_field
type SetContactFieldAction struct {
BaseAction
Field *flows.FieldReference `json:"field" validate:"required"`
Value string `json:"value"`
}

// Type returns the type of this action
func (a *SaveContactField) Type() string { return TypeSaveContactField }
func (a *SetContactFieldAction) Type() string { return TypeSetContactField }

// Validate validates our action is valid and has all the assets it needs
func (a *SaveContactField) Validate(assets flows.SessionAssets) error {
func (a *SetContactFieldAction) Validate(assets flows.SessionAssets) error {
_, err := assets.GetField(a.Field.Key)
return err
}

// Execute runs this action
func (a *SaveContactField) Execute(run flows.FlowRun, step flows.Step, log flows.EventLog) error {
func (a *SetContactFieldAction) Execute(run flows.FlowRun, step flows.Step, log flows.EventLog) error {
if run.Contact() == nil {
log.Add(events.NewFatalErrorEvent(fmt.Errorf("can't execute action in session without a contact")))
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@ import (
"github.com/nyaruka/goflow/utils"
)

// TypeUpdateContact is the type for our update contact action
const TypeUpdateContact string = "update_contact"
// TypeSetContactProperty is the type for our set contact property action
const TypeSetContactProperty string = "set_contact_property"

// UpdateContactAction can be used to update one of the built in fields for a contact of "name" or
// SetContactPropertyAction can be used to update one of the built in fields for a contact of "name" or
// "language". An `contact_property_changed` event will be created with the corresponding values.
//
// ```
// {
// "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
// "type": "update_contact",
// "type": "set_contact_property",
// "field_name": "language",
// "value": "eng"
// }
// ```
//
// @action update_contact
type UpdateContactAction struct {
// @action set_contact_property
type SetContactPropertyAction struct {
BaseAction
FieldName string `json:"field_name" validate:"required,eq=name|eq=language"`
Value string `json:"value"`
}

// Type returns the type of this action
func (a *UpdateContactAction) Type() string { return TypeUpdateContact }
func (a *SetContactPropertyAction) Type() string { return TypeSetContactProperty }

// Validate validates our action is valid and has all the assets it needs
func (a *UpdateContactAction) Validate(assets flows.SessionAssets) error {
func (a *SetContactPropertyAction) Validate(assets flows.SessionAssets) error {
// check language is valid if specified
if a.FieldName == "language" && a.Value != "" {
if _, err := utils.ParseLanguage(a.Value); err != nil {
Expand All @@ -47,7 +47,7 @@ func (a *UpdateContactAction) Validate(assets flows.SessionAssets) error {
}

// Execute runs this action
func (a *UpdateContactAction) Execute(run flows.FlowRun, step flows.Step, log flows.EventLog) error {
func (a *SetContactPropertyAction) Execute(run flows.FlowRun, step flows.Step, log flows.EventLog) error {
if run.Contact() == nil {
log.Add(events.NewFatalErrorEvent(fmt.Errorf("can't execute action in session without a contact")))
return nil
Expand Down
Loading

0 comments on commit d9585e5

Please sign in to comment.