-
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 #1187 from nyaruka/optin_created
Rename `optin_sent` to `optin_created` for consistency with `msg_created` and add channel/URN properties
- Loading branch information
Showing
5 changed files
with
73 additions
and
47 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
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 |
---|---|---|
|
@@ -49,6 +49,7 @@ func TestEventMarshaling(t *testing.T) { | |
mailgun := session.Assets().Ticketers().Get("19dc6346-9623-4fe4-be80-538d493ecdf5") | ||
weather := session.Assets().Topics().Get("472a7a73-96cb-4736-b567-056d987cc5b4") | ||
user := session.Assets().Users().Get("[email protected]") | ||
facebook := session.Assets().Channels().Get("4bb288a0-7fca-4da1-abe8-59a593aff648") | ||
ticket := flows.NewTicket("7481888c-07dd-47dc-bf22-ef7448696ffe", mailgun, weather, "Where are my cookies?", "1243252", user) | ||
|
||
eventTests := []struct { | ||
|
@@ -545,14 +546,19 @@ func TestEventMarshaling(t *testing.T) { | |
}`, | ||
}, | ||
{ | ||
events.NewOptInSent(jotd), | ||
events.NewOptInCreated(jotd, facebook, urns.URN("facebook:1234567890")), | ||
`{ | ||
"type": "optin_sent", | ||
"type": "optin_created", | ||
"created_on": "2018-10-18T14:20:30.000123456Z", | ||
"optin": { | ||
"uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb", | ||
"name": "Joke Of The Day" | ||
} | ||
}, | ||
"channel": { | ||
"uuid": "4bb288a0-7fca-4da1-abe8-59a593aff648", | ||
"name": "Facebook Channel" | ||
}, | ||
"urn": "facebook:1234567890" | ||
}`, | ||
}, | ||
{ | ||
|
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,49 @@ | ||
package events | ||
|
||
import ( | ||
"github.com/nyaruka/gocommon/urns" | ||
"github.com/nyaruka/goflow/assets" | ||
"github.com/nyaruka/goflow/flows" | ||
) | ||
|
||
func init() { | ||
registerType(TypeOptInCreated, func() flows.Event { return &OptInCreatedEvent{} }) | ||
} | ||
|
||
// TypeOptInCreated is our type for the optin event | ||
const TypeOptInCreated string = "optin_created" | ||
|
||
// OptInCreatedEvent events are created when an action has created an optin to be sent. | ||
// | ||
// { | ||
// "type": "optin_created", | ||
// "created_on": "2006-01-02T15:04:05Z", | ||
// "optin": { | ||
// "uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb", | ||
// "name": "Joke Of The Day" | ||
// }, | ||
// "channel": { | ||
// "uuid": "4bb288a0-7fca-4da1-abe8-59a593aff648", | ||
// "name": "Facebook" | ||
// }, | ||
// "urn": "tel:+12065551212" | ||
// } | ||
// | ||
// @event optin_created | ||
type OptInCreatedEvent 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), | ||
OptIn: optIn.Reference(), | ||
Channel: ch.Reference(), | ||
URN: urn, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.