-
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.
Merge pull request #1185 from nyaruka/optin_action
Optin action and event
- Loading branch information
Showing
17 changed files
with
271 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name: CI | ||
on: [push, pull_request] | ||
env: | ||
go-version: "1.19.x" | ||
go-version: "1.20.x" | ||
jobs: | ||
test: | ||
name: Test | ||
|
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
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,55 @@ | ||
package actions | ||
|
||
import ( | ||
"github.com/nyaruka/goflow/assets" | ||
"github.com/nyaruka/goflow/flows" | ||
"github.com/nyaruka/goflow/flows/events" | ||
) | ||
|
||
func init() { | ||
registerType(TypeSendOptIn, func() flows.Action { return &SendOptInAction{} }) | ||
} | ||
|
||
// TypeSendOptIn is the type for the send optin action | ||
const TypeSendOptIn string = "send_optin" | ||
|
||
// SendOptInAction can be used to send an optin to the contact if the channel supports that. | ||
// | ||
// An [event:optin_sent] event will be created if the optin was sent. | ||
// | ||
// { | ||
// "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9", | ||
// "type": "send_optin", | ||
// "optin": { | ||
// "uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb", | ||
// "name": "Joke Of The Day" | ||
// } | ||
// } | ||
// | ||
// @action send_optin | ||
type SendOptInAction struct { | ||
baseAction | ||
onlineAction | ||
|
||
OptIn *assets.OptInReference `json:"optin" validate:"required,dive"` | ||
} | ||
|
||
// NewSendOptIn creates a new send optin action | ||
func NewSendOptIn(uuid flows.ActionUUID, optIn *assets.OptInReference) *SendOptInAction { | ||
return &SendOptInAction{ | ||
baseAction: newBaseAction(TypeSendOptIn, uuid), | ||
OptIn: optIn, | ||
} | ||
} | ||
|
||
// Execute creates the optin events | ||
func (a *SendOptInAction) 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 && destinations[0].Channel.HasFeature(assets.ChannelFeatureOptIns) { | ||
logEvent(events.NewOptInSent(optIn)) | ||
} | ||
|
||
return nil | ||
} |
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
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,48 @@ | ||
[ | ||
{ | ||
"description": "NOOP when channel doesn't support optins feature", | ||
"action": { | ||
"type": "send_optin", | ||
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912", | ||
"optin": { | ||
"uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb", | ||
"name": "Joke Of The Day" | ||
} | ||
}, | ||
"events": [] | ||
}, | ||
{ | ||
"description": "Event created when channel does support optins feature", | ||
"contact": { | ||
"uuid": "5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f", | ||
"name": "Ryan Lewis", | ||
"language": "eng", | ||
"timezone": "America/Guayaquil", | ||
"urns": [ | ||
"facebook:1234567890" | ||
], | ||
"groups": [], | ||
"fields": {}, | ||
"created_on": "2018-06-20T11:40:30.123456789-00:00" | ||
}, | ||
"action": { | ||
"type": "send_optin", | ||
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912", | ||
"optin": { | ||
"uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb", | ||
"name": "Joke Of The Day" | ||
} | ||
}, | ||
"events": [ | ||
{ | ||
"type": "optin_sent", | ||
"created_on": "2018-10-18T14:20:30.000123456Z", | ||
"step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", | ||
"optin": { | ||
"name": "Joke Of The Day", | ||
"uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb" | ||
} | ||
} | ||
] | ||
} | ||
] |
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
Oops, something went wrong.