diff --git a/assets/optin.go b/assets/optin.go index 92b04a897..8ee7d995e 100644 --- a/assets/optin.go +++ b/assets/optin.go @@ -9,22 +9,17 @@ import ( // OptInUUID is the UUID of an opt in type OptInUUID uuids.UUID -// OptIn are channel specific opt-ins +// OptIn are opt-ins for messaging campaign. // // { // "uuid": "8925c76f-926b-4a63-a6eb-ab69e7a6b79b", -// "name": "Joke Of The Day", -// "channel": { -// "uuid": "204e5af9-42c3-4d46-8aab-ce204dff25b4", -// "name": "Facebook" -// } +// "name": "Joke Of The Day" // } // // @asset optin type OptIn interface { UUID() OptInUUID Name() string - Channel() *ChannelReference } // OptInReference is used to reference an opt in diff --git a/assets/static/optin.go b/assets/static/optin.go index b709a708e..6439e8094 100644 --- a/assets/static/optin.go +++ b/assets/static/optin.go @@ -6,17 +6,15 @@ import ( // 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"` - Channel_ *assets.ChannelReference `json:"channel" validate:"required,dive"` + 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, - Channel_: channel, + UUID_: uuid, + Name_: name, } } @@ -25,6 +23,3 @@ func (t *OptIn) UUID() assets.OptInUUID { return t.UUID_ } // Name returns the name of this ticketer func (t *OptIn) Name() string { return t.Name_ } - -// Channel returns a reference to this optin's channel -func (c *OptIn) Channel() *assets.ChannelReference { return c.Channel_ } diff --git a/assets/static/optin_test.go b/assets/static/optin_test.go index 687b435fb..c10516907 100644 --- a/assets/static/optin_test.go +++ b/assets/static/optin_test.go @@ -17,5 +17,4 @@ func TestOptIn(t *testing.T) { ) assert.Equal(t, assets.OptInUUID("37657cf7-5eab-4286-9cb0-bbf270587bad"), optin.UUID()) assert.Equal(t, "Weather Updates", optin.Name()) - assert.Equal(t, assets.NewChannelReference("f4366920-cb05-47b9-a974-29be2d528984", "Facebook"), optin.Channel()) } diff --git a/assets/static/source_test.go b/assets/static/source_test.go index 71d357f55..b7832d0e3 100644 --- a/assets/static/source_test.go +++ b/assets/static/source_test.go @@ -52,11 +52,7 @@ var assetsJSON = `{ "optins": [ { "uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb", - "name": "Joke Of The Day", - "channel": { - "uuid": "58e9b092-fe42-4173-876c-ff45a14a24fe", - "name": "Facebook" - } + "name": "Joke Of The Day" } ], "resthooks": [ diff --git a/cmd/docgen/docs/base_test.go b/cmd/docgen/docs/base_test.go index 73ac99e84..c8053bc39 100644 --- a/cmd/docgen/docs/base_test.go +++ b/cmd/docgen/docs/base_test.go @@ -46,7 +46,7 @@ func TestGenerateDocs(t *testing.T) { assert.Equal(t, 88, len(functions)) types := context["types"].([]any) - assert.Equal(t, 18, len(types)) + assert.Equal(t, 19, len(types)) root := context["root"].([]any) assert.Equal(t, 14, len(root)) diff --git a/flows/engine/assets.go b/flows/engine/assets.go index 9038bc4f9..1c62e33ea 100644 --- a/flows/engine/assets.go +++ b/flows/engine/assets.go @@ -87,8 +87,6 @@ func NewSessionAssets(env envs.Environment, source assets.Source, migrationConfi fieldAssets := flows.NewFieldAssets(fields) groupAssets, _ := flows.NewGroupAssets(env, fieldAssets, groups) - channelAssets := flows.NewChannelAssets(channels) - optInAssets, _ := flows.NewOptInAssets(channelAssets, optIns) return &sessionAssets{ source: source, @@ -100,7 +98,7 @@ func NewSessionAssets(env envs.Environment, source assets.Source, migrationConfi groups: groupAssets, labels: flows.NewLabelAssets(labels), locations: flows.NewLocationAssets(locations), - optIns: optInAssets, + optIns: flows.NewOptInAssets(optIns), resthooks: flows.NewResthookAssets(resthooks), templates: flows.NewTemplateAssets(templates), ticketers: flows.NewTicketerAssets(ticketers), diff --git a/flows/engine/assets_test.go b/flows/engine/assets_test.go index bda44248a..db5d54759 100644 --- a/flows/engine/assets_test.go +++ b/flows/engine/assets_test.go @@ -58,11 +58,7 @@ var assetsJSON = `{ "optins": [ { "uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb", - "name": "Joke Of The Day", - "channel": { - "uuid": "58e9b092-fe42-4173-876c-ff45a14a24fe", - "name": "Facebook" - } + "name": "Joke Of The Day" } ], "resthooks": [ diff --git a/flows/optin.go b/flows/optin.go index 816a05265..a1d03612d 100644 --- a/flows/optin.go +++ b/flows/optin.go @@ -4,32 +4,21 @@ import ( "github.com/nyaruka/goflow/assets" "github.com/nyaruka/goflow/envs" "github.com/nyaruka/goflow/excellent/types" - "github.com/pkg/errors" ) // OptIn adds some functionality to optin assets. type OptIn struct { assets.OptIn - - channel *Channel } // NewOptIn returns a new optin object from the given optin asset -func NewOptIn(channels *ChannelAssets, asset assets.OptIn) (*OptIn, error) { - ch := channels.Get(asset.Channel().UUID) - if ch == nil { - return nil, errors.Errorf("no such channel with UUID %s", asset.Channel().UUID) - } - - return &OptIn{OptIn: asset, channel: ch}, nil +func NewOptIn(asset assets.OptIn) *OptIn { + return &OptIn{OptIn: asset} } // Asset returns the underlying asset func (o *OptIn) Asset() assets.OptIn { return o.OptIn } -// Channel returns the associated channel -func (o *OptIn) Channel() *Channel { return o.channel } - // Reference returns a reference to this optin func (o *OptIn) Reference() *assets.OptInReference { if o == nil { @@ -42,15 +31,13 @@ func (o *OptIn) Reference() *assets.OptInReference { // // uuid:text -> the UUID of the optin // name:text -> the name of the optin -// channel:channel -> the channel of the optin // -// @context ticket +// @context optin func (o *OptIn) Context(env envs.Environment) map[string]types.XValue { return map[string]types.XValue{ "__default__": types.NewXText(string(o.Name())), "uuid": types.NewXText(string(o.UUID())), "name": types.NewXText(string(o.Name())), - "channel": Context(env, o.channel), } } @@ -60,20 +47,15 @@ type OptInAssets struct { } // NewOptInAssets creates a new set of optin assets -func NewOptInAssets(channels *ChannelAssets, optins []assets.OptIn) (*OptInAssets, []assets.OptIn) { - broken := make([]assets.OptIn, 0) +func NewOptInAssets(optins []assets.OptIn) *OptInAssets { s := &OptInAssets{ byUUID: make(map[assets.OptInUUID]*OptIn, len(optins)), } for _, asset := range optins { - optin, err := NewOptIn(channels, asset) - if err != nil { - broken = append(broken, asset) - } else { - s.byUUID[asset.UUID()] = optin - } + optin := NewOptIn(asset) + s.byUUID[asset.UUID()] = optin } - return s, broken + return s } // Get finds the optin with the given UUID diff --git a/flows/optin_test.go b/flows/optin_test.go index c3f8fb8d1..7fabb7b9d 100644 --- a/flows/optin_test.go +++ b/flows/optin_test.go @@ -22,28 +22,10 @@ func TestOptIns(t *testing.T) { env := envs.NewBuilder().Build() source, err := static.NewSource([]byte(`{ - "channels": [ - { - "uuid": "58e9b092-fe42-4173-876c-ff45a14a24fe", - "name": "Facebook", - "address": "457547478475", - "schemes": [ - "facebook" - ], - "roles": [ - "send", - "receive" - ] - } - ], "optins": [ { "uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb", - "name": "Joke Of The Day", - "channel": { - "uuid": "58e9b092-fe42-4173-876c-ff45a14a24fe", - "name": "Facebook" - } + "name": "Joke Of The Day" } ] }`)) @@ -55,7 +37,6 @@ func TestOptIns(t *testing.T) { jotd := sa.OptIns().Get("248be71d-78e9-4d71-a6c4-9981d369e5cb") assert.Equal(t, assets.OptInUUID("248be71d-78e9-4d71-a6c4-9981d369e5cb"), jotd.UUID()) assert.Equal(t, "Joke Of The Day", jotd.Name()) - assert.Equal(t, "Facebook", jotd.Channel().Name()) assert.Equal(t, assets.NewOptInReference("248be71d-78e9-4d71-a6c4-9981d369e5cb", "Joke Of The Day"), jotd.Reference()) // check use in expressions @@ -63,12 +44,6 @@ func TestOptIns(t *testing.T) { "__default__": types.NewXText("Joke Of The Day"), "uuid": types.NewXText("248be71d-78e9-4d71-a6c4-9981d369e5cb"), "name": types.NewXText("Joke Of The Day"), - "channel": types.NewXObject(map[string]types.XValue{ - "__default__": types.NewXText("Facebook"), - "uuid": types.NewXText("58e9b092-fe42-4173-876c-ff45a14a24fe"), - "name": types.NewXText("Facebook"), - "address": types.NewXText("457547478475"), - }), }), flows.Context(env, jotd)) assert.Nil(t, (*flows.OptIn)(nil).Reference()) diff --git a/flows/triggers/testdata/_assets.json b/flows/triggers/testdata/_assets.json index df9420591..f0c756f8d 100644 --- a/flows/triggers/testdata/_assets.json +++ b/flows/triggers/testdata/_assets.json @@ -36,11 +36,7 @@ "optins": [ { "uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb", - "name": "Joke Of The Day", - "channel": { - "uuid": "58e9b092-fe42-4173-876c-ff45a14a24fe", - "name": "Facebook" - } + "name": "Joke Of The Day" } ], "ticketers": [ diff --git a/flows/triggers/testdata/optin.json b/flows/triggers/testdata/optin.json index 714f75132..68db0066b 100644 --- a/flows/triggers/testdata/optin.json +++ b/flows/triggers/testdata/optin.json @@ -61,12 +61,7 @@ "keyword": "", "optin": { "uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb", - "name": "Joke Of The Day", - "channel": { - "uuid": "58e9b092-fe42-4173-876c-ff45a14a24fe", - "name": "Facebook", - "address": "457547478475" - } + "name": "Joke Of The Day" }, "origin": "", "params": {}, diff --git a/test/session.go b/test/session.go index 14fbad9cb..07581d046 100644 --- a/test/session.go +++ b/test/session.go @@ -58,11 +58,7 @@ var sessionAssets = `{ "optins": [ { "uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb", - "name": "Joke Of The Day", - "channel": { - "uuid": "4bb288a0-7fca-4da1-abe8-59a593aff648", - "name": "Facebook" - } + "name": "Joke Of The Day" } ], "ticketers": [