-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename send_optin to request_optin and optin_created to optin_requested
- Loading branch information
1 parent
5882b8c
commit fa48995
Showing
6 changed files
with
78 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters