-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OptIn assets and triggers #1184
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
49fc542
Add OptIn as new asset type
rowanseymour 174387b
Add trigger type for optins
rowanseymour 828201c
Merge branch 'main' into optins
rowanseymour 233276a
More tests
rowanseymour eeff921
Change optins to be channel agnostic
rowanseymour File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package assets | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/nyaruka/gocommon/uuids" | ||
) | ||
|
||
// OptInUUID is the UUID of an opt in | ||
type OptInUUID uuids.UUID | ||
|
||
// OptIn are opt-ins for messaging campaign. | ||
// | ||
// { | ||
// "uuid": "8925c76f-926b-4a63-a6eb-ab69e7a6b79b", | ||
// "name": "Joke Of The Day" | ||
// } | ||
// | ||
// @asset optin | ||
type OptIn interface { | ||
UUID() OptInUUID | ||
Name() string | ||
} | ||
|
||
// OptInReference is used to reference an opt in | ||
type OptInReference struct { | ||
UUID OptInUUID `json:"uuid" validate:"required,uuid"` | ||
Name string `json:"name"` | ||
} | ||
|
||
// NewOptInReference creates a new optin reference with the given UUID and name | ||
func NewOptInReference(uuid OptInUUID, name string) *OptInReference { | ||
return &OptInReference{UUID: uuid, Name: name} | ||
} | ||
|
||
// Type returns the name of the asset type | ||
func (r *OptInReference) Type() string { | ||
return "optin" | ||
} | ||
|
||
// GenericUUID returns the untyped UUID | ||
func (r *OptInReference) GenericUUID() uuids.UUID { | ||
return uuids.UUID(r.UUID) | ||
} | ||
|
||
// Identity returns the unique identity of the asset | ||
func (r *OptInReference) Identity() string { | ||
return string(r.UUID) | ||
} | ||
|
||
// Variable returns whether this a variable (vs concrete) reference | ||
func (r *OptInReference) Variable() bool { | ||
return false | ||
} | ||
|
||
func (r *OptInReference) String() string { | ||
return fmt.Sprintf("%s[uuid=%s,name=%s]", r.Type(), r.Identity(), r.Name) | ||
} | ||
|
||
var _ UUIDReference = (*OptInReference)(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,25 @@ | ||
package static | ||
|
||
import ( | ||
"github.com/nyaruka/goflow/assets" | ||
) | ||
|
||
// OptIn is a JSON serializable implementation of an optin asset | ||
type OptIn struct { | ||
UUID_ assets.OptInUUID `json:"uuid" validate:"required,uuid"` | ||
Name_ string `json:"name" validate:"required"` | ||
} | ||
|
||
// NewOptIn creates a new topic | ||
func NewOptIn(uuid assets.OptInUUID, name string, channel *assets.ChannelReference) assets.OptIn { | ||
return &OptIn{ | ||
UUID_: uuid, | ||
Name_: name, | ||
} | ||
} | ||
|
||
// UUID returns the UUID of this ticketer | ||
func (t *OptIn) UUID() assets.OptInUUID { return t.UUID_ } | ||
|
||
// Name returns the name of this ticketer | ||
func (t *OptIn) Name() string { return t.Name_ } |
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,20 @@ | ||
package static_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/nyaruka/goflow/assets" | ||
"github.com/nyaruka/goflow/assets/static" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestOptIn(t *testing.T) { | ||
optin := static.NewOptIn( | ||
"37657cf7-5eab-4286-9cb0-bbf270587bad", | ||
"Weather Updates", | ||
assets.NewChannelReference("f4366920-cb05-47b9-a974-29be2d528984", "Facebook"), | ||
) | ||
assert.Equal(t, assets.OptInUUID("37657cf7-5eab-4286-9cb0-bbf270587bad"), optin.UUID()) | ||
assert.Equal(t, "Weather Updates", optin.Name()) | ||
} |
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated cleanup