Skip to content

Commit

Permalink
Rename send_optin to request_optin and optin_created to optin_requested
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Sep 21, 2023
1 parent 5882b8c commit 62222ef
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 80 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
v0.195.2 (2023-09-18)
-------------------------
* Rename optin_sent to optin_created for consistency with msg_created and add channel/URN properties
* Rename optin_sent to optin_requested for consistency with msg_created and add channel/URN properties

v0.195.1 (2023-09-18)
-------------------------
* Fix optin triggers marshaling with type ticket

v0.195.0 (2023-09-14)
-------------------------
* Add send_optin action and optin_sent event
* Add request_optin action and optin_sent event
* Add features to channel assets and define optins as a feature
* Add trigger type for optins
* Add OptIn as new asset type
Expand Down
4 changes: 2 additions & 2 deletions flows/actions/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,12 @@ func TestConstructors(t *testing.T) {
}`,
},
{
actions.NewSendOptIn(
actions.NewRequestOptIn(
actionUUID,
assets.NewOptInReference("248be71d-78e9-4d71-a6c4-9981d369e5cb", "Joke Of The Day"),
),
`{
"type": "send_optin",
"type": "request_optin",
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"optin": {
"uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb",
Expand Down
60 changes: 60 additions & 0 deletions flows/actions/request_optin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package actions

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

func init() {
registerType(TypeRequestOptIn, func() flows.Action { return &RequestOptInAction{} })
}

// TypeRequestOptIn is the type for the send optin action
const TypeRequestOptIn string = "request_optin"

// RequestOptInAction can be used to send an optin to the contact if the channel supports that.
//
// An [event:optin_requested] event will be created if the optin was requested.
//
// {
// "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
// "type": "request_optin",
// "optin": {
// "uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb",
// "name": "Joke Of The Day"
// }
// }
//
// @action request_optin
type RequestOptInAction struct {
baseAction
onlineAction

OptIn *assets.OptInReference `json:"optin" validate:"required,dive"`
}

// NewRequestOptIn creates a new request optin action
func NewRequestOptIn(uuid flows.ActionUUID, optIn *assets.OptInReference) *RequestOptInAction {
return &RequestOptInAction{
baseAction: newBaseAction(TypeRequestOptIn, uuid),
OptIn: optIn,
}
}

// Execute creates the optin events
func (a *RequestOptInAction) Execute(run flows.Run, step flows.Step, logModifier flows.ModifierCallback, logEvent flows.EventCallback) error {
optIn := run.Session().Assets().OptIns().Get(a.OptIn.UUID)
destinations := run.Contact().ResolveDestinations(false)

if len(destinations) > 0 {
ch := destinations[0].Channel
urn := destinations[0].URN

if ch.HasFeature(assets.ChannelFeatureOptIns) {
logEvent(events.NewOptInRequested(optIn, ch, urn.URN()))
}
}

return nil
}
60 changes: 0 additions & 60 deletions flows/actions/send_optin.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"description": "NOOP when channel doesn't support optins feature",
"action": {
"type": "send_optin",
"type": "request_optin",
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"optin": {
"uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb",
Expand All @@ -26,7 +26,7 @@
"created_on": "2018-06-20T11:40:30.123456789-00:00"
},
"action": {
"type": "send_optin",
"type": "request_optin",
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"optin": {
"uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb",
Expand All @@ -35,7 +35,7 @@
},
"events": [
{
"type": "optin_created",
"type": "optin_requested",
"created_on": "2018-10-18T14:20:30.000123456Z",
"step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c",
"optin": {
Expand Down
4 changes: 2 additions & 2 deletions flows/events/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,9 @@ func TestEventMarshaling(t *testing.T) {
}`,
},
{
events.NewOptInCreated(jotd, facebook, urns.URN("facebook:1234567890")),
events.NewOptInRequested(jotd, facebook, urns.URN("facebook:1234567890")),
`{
"type": "optin_created",
"type": "optin_requested",
"created_on": "2018-10-18T14:20:30.000123456Z",
"optin": {
"uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb",
Expand Down
22 changes: 11 additions & 11 deletions flows/events/optin_created.go → flows/events/optin_requested.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import (
)

func init() {
registerType(TypeOptInCreated, func() flows.Event { return &OptInCreatedEvent{} })
registerType(TypeOptInRequested, func() flows.Event { return &OptInRequestedEvent{} })
}

// TypeOptInCreated is our type for the optin event
const TypeOptInCreated string = "optin_created"
// TypeOptInRequested is our type for the optin event
const TypeOptInRequested string = "optin_requested"

// OptInCreatedEvent events are created when an action has created an optin to be sent.
// OptInRequestedEvent events are created when an action has created an optin to be sent.
//
// {
// "type": "optin_created",
// "type": "optin_requested",
// "created_on": "2006-01-02T15:04:05Z",
// "optin": {
// "uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb",
Expand All @@ -29,19 +29,19 @@ const TypeOptInCreated string = "optin_created"
// "urn": "tel:+12065551212"
// }
//
// @event optin_created
type OptInCreatedEvent struct {
// @event optin_requested
type OptInRequestedEvent struct {
BaseEvent

OptIn *assets.OptInReference `json:"optin" validate:"required,dive"`
Channel *assets.ChannelReference `json:"channel" validate:"required,dive"`
URN urns.URN `json:"urn" validate:"required"`
}

// NewOptInCreated returns a new optin sent event
func NewOptInCreated(optIn *flows.OptIn, ch *flows.Channel, urn urns.URN) *OptInCreatedEvent {
return &OptInCreatedEvent{
BaseEvent: NewBaseEvent(TypeOptInCreated),
// NewOptInRequested returns a new optin requested event
func NewOptInRequested(optIn *flows.OptIn, ch *flows.Channel, urn urns.URN) *OptInRequestedEvent {
return &OptInRequestedEvent{
BaseEvent: NewBaseEvent(TypeOptInRequested),
OptIn: optIn.Reference(),
Channel: ch.Reference(),
URN: urn,
Expand Down

0 comments on commit 62222ef

Please sign in to comment.