diff --git a/assets/references_test.go b/assets/references_test.go index 1b140f78c..1990c18f5 100644 --- a/assets/references_test.go +++ b/assets/references_test.go @@ -122,17 +122,6 @@ func TestReferences(t *testing.T) { assert.False(t, templateRef.Variable()) assert.NoError(t, utils.Validate(templateRef)) - ticketerRef := assets.NewTicketerReference("61602f3e-f603-4c70-8a8f-c477505bf4bf", "Support Tickets") - assert.Equal(t, "ticketer", ticketerRef.Type()) - assert.Equal(t, "61602f3e-f603-4c70-8a8f-c477505bf4bf", ticketerRef.Identity()) - assert.Equal(t, uuids.UUID("61602f3e-f603-4c70-8a8f-c477505bf4bf"), ticketerRef.GenericUUID()) - assert.Equal(t, "ticketer[uuid=61602f3e-f603-4c70-8a8f-c477505bf4bf,name=Support Tickets]", ticketerRef.String()) - assert.False(t, ticketerRef.Variable()) - assert.NoError(t, utils.Validate(ticketerRef)) - - // ticketer references must always be concrete - assert.EqualError(t, utils.Validate(assets.NewTicketerReference("", "Booking")), "field 'uuid' is required") - topicRef := assets.NewTopicReference("61602f3e-f603-4c70-8a8f-c477505bf4bf", "Weather") assert.Equal(t, "topic", topicRef.Type()) assert.Equal(t, "61602f3e-f603-4c70-8a8f-c477505bf4bf", topicRef.Identity()) diff --git a/assets/source.go b/assets/source.go index 2d4ef0b79..ba7f3623d 100644 --- a/assets/source.go +++ b/assets/source.go @@ -14,7 +14,6 @@ type Source interface { OptIns() ([]OptIn, error) Resthooks() ([]Resthook, error) Templates() ([]Template, error) - Ticketers() ([]Ticketer, error) Topics() ([]Topic, error) Users() ([]User, error) } diff --git a/assets/static/optin.go b/assets/static/optin.go index 6439e8094..55aa6a7ca 100644 --- a/assets/static/optin.go +++ b/assets/static/optin.go @@ -18,8 +18,8 @@ func NewOptIn(uuid assets.OptInUUID, name string, channel *assets.ChannelReferen } } -// UUID returns the UUID of this ticketer +// UUID returns the UUID of this optin func (t *OptIn) UUID() assets.OptInUUID { return t.UUID_ } -// Name returns the name of this ticketer +// Name returns the name of this optin func (t *OptIn) Name() string { return t.Name_ } diff --git a/assets/static/source.go b/assets/static/source.go index bc9c57d21..1a9860aaf 100644 --- a/assets/static/source.go +++ b/assets/static/source.go @@ -26,7 +26,6 @@ type StaticSource struct { OptIns []*OptIn `json:"optins" validate:"omitempty,dive"` Resthooks []*Resthook `json:"resthooks" validate:"omitempty,dive"` Templates []*Template `json:"templates" validate:"omitempty,dive"` - Ticketers []*Ticketer `json:"ticketers" validate:"omitempty,dive"` Topics []*Topic `json:"topics" validate:"omitempty,dive"` Users []*User `json:"users" validate:"omitempty,dive"` } @@ -165,15 +164,6 @@ func (s *StaticSource) Templates() ([]assets.Template, error) { return set, nil } -// Ticketers returns all ticketer assets -func (s *StaticSource) Ticketers() ([]assets.Ticketer, error) { - set := make([]assets.Ticketer, len(s.s.Ticketers)) - for i := range s.s.Ticketers { - set[i] = s.s.Ticketers[i] - } - return set, nil -} - // Topics returns all topic assets func (s *StaticSource) Topics() ([]assets.Topic, error) { set := make([]assets.Topic, len(s.s.Topics)) diff --git a/assets/static/source_test.go b/assets/static/source_test.go index b7832d0e3..fc117207b 100644 --- a/assets/static/source_test.go +++ b/assets/static/source_test.go @@ -125,10 +125,6 @@ func TestSource(t *testing.T) { assert.NoError(t, err) assert.Len(t, templates, 0) - ticketers, err := src.Ticketers() - assert.NoError(t, err) - assert.Len(t, ticketers, 0) - topics, err := src.Topics() assert.NoError(t, err) assert.Len(t, topics, 0) diff --git a/assets/static/ticketer.go b/assets/static/ticketer.go deleted file mode 100644 index 4dbb223d1..000000000 --- a/assets/static/ticketer.go +++ /dev/null @@ -1,30 +0,0 @@ -package static - -import ( - "github.com/nyaruka/goflow/assets" -) - -// Ticketer is a JSON serializable implementation of a ticketer asset -type Ticketer struct { - UUID_ assets.TicketerUUID `json:"uuid" validate:"required,uuid"` - Name_ string `json:"name"` - Type_ string `json:"type"` -} - -// NewTicketer creates a new ticketer -func NewTicketer(uuid assets.TicketerUUID, name string, type_ string) assets.Ticketer { - return &Ticketer{ - UUID_: uuid, - Name_: name, - Type_: type_, - } -} - -// UUID returns the UUID of this ticketer -func (t *Ticketer) UUID() assets.TicketerUUID { return t.UUID_ } - -// Name returns the name of this ticketer -func (t *Ticketer) Name() string { return t.Name_ } - -// Type returns the type of this ticketer -func (t *Ticketer) Type() string { return t.Type_ } diff --git a/assets/static/ticketer_test.go b/assets/static/ticketer_test.go deleted file mode 100644 index 9a3014cfc..000000000 --- a/assets/static/ticketer_test.go +++ /dev/null @@ -1,21 +0,0 @@ -package static_test - -import ( - "testing" - - "github.com/nyaruka/goflow/assets" - "github.com/nyaruka/goflow/assets/static" - - "github.com/stretchr/testify/assert" -) - -func TestTicketer(t *testing.T) { - ticketer := static.NewTicketer( - assets.TicketerUUID("37657cf7-5eab-4286-9cb0-bbf270587bad"), - "Support Tickets", - "mailgun", - ) - assert.Equal(t, assets.TicketerUUID("37657cf7-5eab-4286-9cb0-bbf270587bad"), ticketer.UUID()) - assert.Equal(t, "Support Tickets", ticketer.Name()) - assert.Equal(t, "mailgun", ticketer.Type()) -} diff --git a/assets/static/topic.go b/assets/static/topic.go index ee99e21f8..46c6ff512 100644 --- a/assets/static/topic.go +++ b/assets/static/topic.go @@ -18,8 +18,8 @@ func NewTopic(uuid assets.TopicUUID, name string) assets.Topic { } } -// UUID returns the UUID of this ticketer +// UUID returns the UUID of this topic func (t *Topic) UUID() assets.TopicUUID { return t.UUID_ } -// Name returns the name of this ticketer +// Name returns the name of this topic func (t *Topic) Name() string { return t.Name_ } diff --git a/assets/static/user_test.go b/assets/static/user_test.go index 9329597c6..99aba4349 100644 --- a/assets/static/user_test.go +++ b/assets/static/user_test.go @@ -9,7 +9,7 @@ import ( ) func TestUser(t *testing.T) { - ticketer := static.NewUser("bob@nyaruka.com", "Bob") - assert.Equal(t, "bob@nyaruka.com", ticketer.Email()) - assert.Equal(t, "Bob", ticketer.Name()) + user := static.NewUser("bob@nyaruka.com", "Bob") + assert.Equal(t, "bob@nyaruka.com", user.Email()) + assert.Equal(t, "Bob", user.Name()) } diff --git a/assets/ticketer.go b/assets/ticketer.go deleted file mode 100644 index 8afc72aed..000000000 --- a/assets/ticketer.go +++ /dev/null @@ -1,62 +0,0 @@ -package assets - -import ( - "fmt" - - "github.com/nyaruka/gocommon/uuids" -) - -// TicketerUUID is the UUID of a ticketer -type TicketerUUID uuids.UUID - -// Ticketer is a system which can open or close tickets -// -// { -// "uuid": "37657cf7-5eab-4286-9cb0-bbf270587bad", -// "name": "Support Tickets", -// "type": "mailgun" -// } -// -// @asset ticketer -type Ticketer interface { - UUID() TicketerUUID - Name() string - Type() string -} - -// TicketerReference is used to reference a ticketer -type TicketerReference struct { - UUID TicketerUUID `json:"uuid" validate:"required,uuid"` - Name string `json:"name"` -} - -// NewTicketerReference creates a new classifier reference with the given UUID and name -func NewTicketerReference(uuid TicketerUUID, name string) *TicketerReference { - return &TicketerReference{UUID: uuid, Name: name} -} - -// Type returns the name of the asset type -func (r *TicketerReference) Type() string { - return "ticketer" -} - -// GenericUUID returns the untyped UUID -func (r *TicketerReference) GenericUUID() uuids.UUID { - return uuids.UUID(r.UUID) -} - -// Identity returns the unique identity of the asset -func (r *TicketerReference) Identity() string { - return string(r.UUID) -} - -// Variable returns whether this a variable (vs concrete) reference -func (r *TicketerReference) Variable() bool { - return false -} - -func (r *TicketerReference) String() string { - return fmt.Sprintf("%s[uuid=%s,name=%s]", r.Type(), r.Identity(), r.Name) -} - -var _ UUIDReference = (*TicketerReference)(nil) diff --git a/flows/actions/base_test.go b/flows/actions/base_test.go index 2609dfd6e..b8aa49ac7 100644 --- a/flows/actions/base_test.go +++ b/flows/actions/base_test.go @@ -31,7 +31,6 @@ import ( "github.com/nyaruka/goflow/test" "github.com/nyaruka/goflow/utils" "github.com/nyaruka/goflow/utils/smtpx" - "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -173,9 +172,8 @@ func testActionType(t *testing.T, assetsJSON json.RawMessage, typeName string) { require.NoError(t, err) if tc.HasTicket { - ticketer := sa.Ticketers().Get("d605bb96-258d-4097-ad0a-080937db2212") topic := sa.Topics().Get("0d9a2c56-6fc2-4f27-93c5-a6322e26b740") - contact.SetTicket(flows.NewTicket("7f44b065-ec28-4d7a-bbb4-0bda3b75b19d", ticketer, topic, "Help", "", nil)) + contact.SetTicket(flows.NewTicket("7f44b065-ec28-4d7a-bbb4-0bda3b75b19d", topic, "Help", nil)) } // and switch their language @@ -231,9 +229,6 @@ func testActionType(t *testing.T, assetsJSON json.RawMessage, typeName string) { } return nil, errors.Errorf("no classification service available for %s", c.Reference()) }). - WithTicketServiceFactory(func(t *flows.Ticketer) (flows.TicketService, error) { - return test.NewTicketService(t), nil - }). WithAirtimeServiceFactory(func(flows.SessionAssets) (flows.AirtimeService, error) { return dtone.NewService(http.DefaultClient, nil, "nyaruka", "123456789"), nil }). @@ -443,7 +438,6 @@ func TestConstructors(t *testing.T) { { actions.NewOpenTicket( actionUUID, - assets.NewTicketerReference(assets.TicketerUUID("0baee364-07a7-4c93-9778-9f55a35903bb"), "Support Tickets"), assets.NewTopicReference("472a7a73-96cb-4736-b567-056d987cc5b4", "Weather"), "Where are my cookies?", assets.NewUserReference("bob@nyaruka.com", "Bob McTickets"), @@ -452,10 +446,6 @@ func TestConstructors(t *testing.T) { `{ "uuid": "ad154980-7bf7-4ab8-8728-545fd6378912", "type": "open_ticket", - "ticketer": { - "uuid": "0baee364-07a7-4c93-9778-9f55a35903bb", - "name": "Support Tickets" - }, "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" diff --git a/flows/actions/open_ticket.go b/flows/actions/open_ticket.go index 991e114c5..43d5bb1ac 100644 --- a/flows/actions/open_ticket.go +++ b/flows/actions/open_ticket.go @@ -19,10 +19,6 @@ const TypeOpenTicket string = "open_ticket" // { // "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9", // "type": "open_ticket", -// "ticketer": { -// "uuid": "19dc6346-9623-4fe4-be80-538d493ecdf5", -// "name": "Support Tickets" -// }, // "topic": { // "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", // "name": "Weather" @@ -37,18 +33,16 @@ type OpenTicketAction struct { baseAction onlineAction - Ticketer *assets.TicketerReference `json:"ticketer" validate:"required"` - Topic *assets.TopicReference `json:"topic" validate:"omitempty"` - Body string `json:"body" engine:"evaluated"` - Assignee *assets.UserReference `json:"assignee" validate:"omitempty"` - ResultName string `json:"result_name" validate:"required"` + Topic *assets.TopicReference `json:"topic" validate:"omitempty"` + Body string `json:"body" engine:"evaluated"` + Assignee *assets.UserReference `json:"assignee" validate:"omitempty"` + ResultName string `json:"result_name" validate:"required"` } // NewOpenTicket creates a new open ticket action -func NewOpenTicket(uuid flows.ActionUUID, ticketer *assets.TicketerReference, topic *assets.TopicReference, body string, assignee *assets.UserReference, resultName string) *OpenTicketAction { +func NewOpenTicket(uuid flows.ActionUUID, topic *assets.TopicReference, body string, assignee *assets.UserReference, resultName string) *OpenTicketAction { return &OpenTicketAction{ baseAction: newBaseAction(TypeOpenTicket, uuid), - Ticketer: ticketer, Topic: topic, Body: body, Assignee: assignee, @@ -60,8 +54,6 @@ func NewOpenTicket(uuid flows.ActionUUID, ticketer *assets.TicketerReference, to func (a *OpenTicketAction) Execute(run flows.Run, step flows.Step, logModifier flows.ModifierCallback, logEvent flows.EventCallback) error { sa := run.Session().Assets() - ticketer := sa.Ticketers().Get(a.Ticketer.UUID) - var topic *flows.Topic if a.Topic != nil { topic = sa.Topics().Get(a.Topic.UUID) @@ -78,7 +70,7 @@ func (a *OpenTicketAction) Execute(run flows.Run, step flows.Step, logModifier f logEvent(events.NewError(err)) } - ticket := a.open(run, step, ticketer, topic, evaluatedBody, assignee, logModifier, logEvent) + ticket := a.open(run, step, topic, evaluatedBody, assignee, logModifier, logEvent) if ticket != nil { a.saveResult(run, step, a.ResultName, string(ticket.UUID()), CategorySuccess, "", "", nil, logEvent) } else { @@ -88,22 +80,18 @@ func (a *OpenTicketAction) Execute(run flows.Run, step flows.Step, logModifier f return nil } -func (a *OpenTicketAction) open(run flows.Run, step flows.Step, ticketer *flows.Ticketer, topic *flows.Topic, body string, assignee *flows.User, logModifier flows.ModifierCallback, logEvent flows.EventCallback) *flows.Ticket { +func (a *OpenTicketAction) open(run flows.Run, step flows.Step, topic *flows.Topic, body string, assignee *flows.User, logModifier flows.ModifierCallback, logEvent flows.EventCallback) *flows.Ticket { if run.Session().BatchStart() { logEvent(events.NewErrorf("can't open tickets during batch starts")) return nil } - if ticketer == nil { - logEvent(events.NewDependencyError(a.Ticketer)) - return nil - } if a.Topic != nil && topic == nil { logEvent(events.NewDependencyError(a.Topic)) return nil } - mod := modifiers.NewTicket(ticketer, topic, body, assignee) + mod := modifiers.NewTicket(topic, body, assignee) if a.applyModifier(run, mod, logModifier, logEvent) { // if we were able to open a ticket, return it diff --git a/flows/actions/testdata/_assets.json b/flows/actions/testdata/_assets.json index c7c2e8507..8231c750c 100644 --- a/flows/actions/testdata/_assets.json +++ b/flows/actions/testdata/_assets.json @@ -284,13 +284,6 @@ ] } ], - "ticketers": [ - { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets", - "type": "mailgun" - } - ], "topics": [ { "uuid": "0d9a2c56-6fc2-4f27-93c5-a6322e26b740", diff --git a/flows/actions/testdata/open_ticket.json b/flows/actions/testdata/open_ticket.json index 26efa9fda..ff9f06f5b 100644 --- a/flows/actions/testdata/open_ticket.json +++ b/flows/actions/testdata/open_ticket.json @@ -1,73 +1,9 @@ [ - { - "description": "Error event for invalid ticketer reference", - "action": { - "type": "open_ticket", - "uuid": "ad154980-7bf7-4ab8-8728-545fd6378912", - "ticketer": { - "uuid": "dc61e948-26a1-407e-9739-b73b46400b51", - "name": "Deleted" - }, - "topic": null, - "body": "Where are my cookies?", - "assignee": null, - "result_name": "Ticket" - }, - "events": [ - { - "type": "error", - "created_on": "2018-10-18T14:20:30.000123456Z", - "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", - "text": "missing dependency: ticketer[uuid=dc61e948-26a1-407e-9739-b73b46400b51,name=Deleted]" - }, - { - "type": "run_result_changed", - "created_on": "2018-10-18T14:20:30.000123456Z", - "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", - "name": "Ticket", - "value": "", - "category": "Failure" - } - ], - "templates": [ - "Where are my cookies?" - ], - "inspection": { - "dependencies": [ - { - "uuid": "dc61e948-26a1-407e-9739-b73b46400b51", - "name": "Deleted", - "type": "ticketer", - "missing": true - } - ], - "issues": [ - { - "type": "missing_dependency", - "node_uuid": "72a1f5df-49f9-45df-94c9-d86f7ea064e5", - "action_uuid": "ad154980-7bf7-4ab8-8728-545fd6378912", - "description": "missing ticketer dependency 'dc61e948-26a1-407e-9739-b73b46400b51'", - "dependency": { - "uuid": "dc61e948-26a1-407e-9739-b73b46400b51", - "name": "Deleted", - "type": "ticketer" - } - } - ], - "results": [], - "waiting_exits": [], - "parent_refs": [] - } - }, { "description": "Error event for invalid topic reference", "action": { "type": "open_ticket", "uuid": "ad154980-7bf7-4ab8-8728-545fd6378912", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, "topic": { "uuid": "dc61e948-26a1-407e-9739-b73b46400b51", "name": "Deleted" @@ -97,11 +33,6 @@ ], "inspection": { "dependencies": [ - { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets", - "type": "ticketer" - }, { "uuid": "dc61e948-26a1-407e-9739-b73b46400b51", "name": "Deleted", @@ -133,10 +64,6 @@ "action": { "type": "open_ticket", "uuid": "ad154980-7bf7-4ab8-8728-545fd6378912", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, "topic": null, "body": "Where are my cookies?", "assignee": null, @@ -167,10 +94,6 @@ "action": { "type": "open_ticket", "uuid": "ad154980-7bf7-4ab8-8728-545fd6378912", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" @@ -183,44 +106,17 @@ "result_name": "Ticket" }, "events": [ - { - "type": "service_called", - "created_on": "2018-10-18T14:20:30.000123456Z", - "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", - "service": "ticketer", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, - "http_logs": [ - { - "url": "http://nyaruka.tickets.com/tickets.json", - "status_code": 200, - "request": "POST /tickets.json HTTP/1.1\r\nAccept-Encoding: gzip\r\n\r\n{\"body\":\"Last message: Hi everybody\"}", - "response": "HTTP/1.0 200 OK\r\nContent-Length: 15\r\n\r\n{\"status\":\"ok\"}", - "elapsed_ms": 1, - "retries": 0, - "status": "success", - "created_on": "2019-10-16T13:59:30.123456789Z" - } - ] - }, { "type": "ticket_opened", "created_on": "2018-10-18T14:20:30.000123456Z", "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", "ticket": { "uuid": "9688d21d-95aa-4bed-afc7-f31b35731a3d", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" }, "body": "Last message: Hi everybody", - "external_id": "123456", "assignee": { "email": "bob@nyaruka.com", "name": "Bob" @@ -280,16 +176,11 @@ }, "ticket": { "uuid": "9688d21d-95aa-4bed-afc7-f31b35731a3d", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" }, "body": "Last message: Hi everybody", - "external_id": "123456", "assignee": { "email": "bob@nyaruka.com", "name": "Bob" @@ -301,11 +192,6 @@ ], "inspection": { "dependencies": [ - { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets", - "type": "ticketer" - }, { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather", @@ -328,54 +214,23 @@ "action": { "type": "open_ticket", "uuid": "ad154980-7bf7-4ab8-8728-545fd6378912", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, "topic": null, "body": "Last message: @input.text", "assignee": null, "result_name": "Ticket" }, "events": [ - { - "type": "service_called", - "created_on": "2018-10-18T14:20:30.000123456Z", - "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", - "service": "ticketer", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, - "http_logs": [ - { - "url": "http://nyaruka.tickets.com/tickets.json", - "status_code": 200, - "request": "POST /tickets.json HTTP/1.1\r\nAccept-Encoding: gzip\r\n\r\n{\"body\":\"Last message: Hi everybody\"}", - "response": "HTTP/1.0 200 OK\r\nContent-Length: 15\r\n\r\n{\"status\":\"ok\"}", - "elapsed_ms": 1, - "retries": 0, - "status": "success", - "created_on": "2019-10-16T13:59:30.123456789Z" - } - ] - }, { "type": "ticket_opened", "created_on": "2018-10-18T14:20:30.000123456Z", "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", "ticket": { "uuid": "9688d21d-95aa-4bed-afc7-f31b35731a3d", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, "topic": { "uuid": "0d9a2c56-6fc2-4f27-93c5-a6322e26b740", "name": "General" }, - "body": "Last message: Hi everybody", - "external_id": "123456" + "body": "Last message: Hi everybody" } }, { @@ -431,29 +286,18 @@ }, "ticket": { "uuid": "9688d21d-95aa-4bed-afc7-f31b35731a3d", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, "topic": { "uuid": "0d9a2c56-6fc2-4f27-93c5-a6322e26b740", "name": "General" }, - "body": "Last message: Hi everybody", - "external_id": "123456" + "body": "Last message: Hi everybody" } }, "templates": [ "Last message: @input.text" ], "inspection": { - "dependencies": [ - { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets", - "type": "ticketer" - } - ], + "dependencies": [], "issues": [], "results": [], "waiting_exits": [], @@ -465,10 +309,6 @@ "action": { "type": "open_ticket", "uuid": "ad154980-7bf7-4ab8-8728-545fd6378912", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" @@ -480,44 +320,17 @@ "result_name": "Ticket" }, "events": [ - { - "type": "service_called", - "created_on": "2018-10-18T14:20:30.000123456Z", - "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", - "service": "ticketer", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, - "http_logs": [ - { - "url": "http://nyaruka.tickets.com/tickets.json", - "status_code": 200, - "request": "POST /tickets.json HTTP/1.1\r\nAccept-Encoding: gzip\r\n\r\n{\"body\":\"Last message: Hi everybody\"}", - "response": "HTTP/1.0 200 OK\r\nContent-Length: 15\r\n\r\n{\"status\":\"ok\"}", - "elapsed_ms": 1, - "retries": 0, - "status": "success", - "created_on": "2019-10-16T13:59:30.123456789Z" - } - ] - }, { "type": "ticket_opened", "created_on": "2018-10-18T14:20:30.000123456Z", "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", "ticket": { "uuid": "9688d21d-95aa-4bed-afc7-f31b35731a3d", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" }, "body": "Last message: Hi everybody", - "external_id": "123456", "assignee": { "email": "jim@nyaruka.com", "name": "Jim" @@ -577,16 +390,11 @@ }, "ticket": { "uuid": "9688d21d-95aa-4bed-afc7-f31b35731a3d", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" }, "body": "Last message: Hi everybody", - "external_id": "123456", "assignee": { "email": "jim@nyaruka.com", "name": "Jim" @@ -599,11 +407,6 @@ ], "inspection": { "dependencies": [ - { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets", - "type": "ticketer" - }, { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather", @@ -621,10 +424,6 @@ "action": { "type": "open_ticket", "uuid": "ad154980-7bf7-4ab8-8728-545fd6378912", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" @@ -642,44 +441,17 @@ "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", "text": "no such user with email 'EVE@NYARUKA.COM'" }, - { - "type": "service_called", - "created_on": "2018-10-18T14:20:30.000123456Z", - "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", - "service": "ticketer", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, - "http_logs": [ - { - "url": "http://nyaruka.tickets.com/tickets.json", - "status_code": 200, - "request": "POST /tickets.json HTTP/1.1\r\nAccept-Encoding: gzip\r\n\r\n{\"body\":\"Last message: Hi everybody\"}", - "response": "HTTP/1.0 200 OK\r\nContent-Length: 15\r\n\r\n{\"status\":\"ok\"}", - "elapsed_ms": 1, - "retries": 0, - "status": "success", - "created_on": "2019-10-16T13:59:30.123456789Z" - } - ] - }, { "type": "ticket_opened", "created_on": "2018-10-18T14:20:30.000123456Z", "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", "ticket": { "uuid": "9688d21d-95aa-4bed-afc7-f31b35731a3d", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" }, - "body": "Last message: Hi everybody", - "external_id": "123456" + "body": "Last message: Hi everybody" } }, { @@ -735,16 +507,11 @@ }, "ticket": { "uuid": "9688d21d-95aa-4bed-afc7-f31b35731a3d", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" }, - "body": "Last message: Hi everybody", - "external_id": "123456" + "body": "Last message: Hi everybody" } }, "templates": [ @@ -753,11 +520,6 @@ ], "inspection": { "dependencies": [ - { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets", - "type": "ticketer" - }, { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather", @@ -775,10 +537,6 @@ "action": { "type": "open_ticket", "uuid": "ad154980-7bf7-4ab8-8728-545fd6378912", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, "topic": null, "body": "Where are my cookies? @(1/ 0)", "assignee": null, @@ -791,44 +549,17 @@ "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", "text": "error evaluating @(1/ 0): division by zero" }, - { - "type": "service_called", - "created_on": "2018-10-18T14:20:30.000123456Z", - "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", - "service": "ticketer", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, - "http_logs": [ - { - "url": "http://nyaruka.tickets.com/tickets.json", - "status_code": 200, - "request": "POST /tickets.json HTTP/1.1\r\nAccept-Encoding: gzip\r\n\r\n{\"body\":\"Where are my cookies? \"}", - "response": "HTTP/1.0 200 OK\r\nContent-Length: 15\r\n\r\n{\"status\":\"ok\"}", - "elapsed_ms": 1, - "retries": 0, - "status": "success", - "created_on": "2019-10-16T13:59:30.123456789Z" - } - ] - }, { "type": "ticket_opened", "created_on": "2018-10-18T14:20:30.000123456Z", "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", "ticket": { "uuid": "9688d21d-95aa-4bed-afc7-f31b35731a3d", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, "topic": { "uuid": "0d9a2c56-6fc2-4f27-93c5-a6322e26b740", "name": "General" }, - "body": "Where are my cookies? ", - "external_id": "123456" + "body": "Where are my cookies? " } }, { @@ -855,105 +586,7 @@ "Where are my cookies? @(1/ 0)" ], "inspection": { - "dependencies": [ - { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets", - "type": "ticketer" - } - ], - "issues": [], - "results": [], - "waiting_exits": [], - "parent_refs": [] - } - }, - { - "description": "Result with category failure created if ticket couldn't be opened", - "action": { - "type": "open_ticket", - "uuid": "ad154980-7bf7-4ab8-8728-545fd6378912", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, - "topic": null, - "body": "Last message: @input.text", - "assignee": null, - "result_name": "Ticket" - }, - "events": [ - { - "type": "service_called", - "created_on": "2018-10-18T14:20:30.000123456Z", - "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", - "service": "ticketer", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, - "http_logs": [ - { - "url": "http://nyaruka.tickets.com/tickets.json", - "status_code": 200, - "request": "POST /tickets.json HTTP/1.1\r\nAccept-Encoding: gzip\r\n\r\n{\"body\":\"Last message: Hi everybody\"}", - "response": "HTTP/1.0 200 OK\r\nContent-Length: 15\r\n\r\n{\"status\":\"ok\"}", - "elapsed_ms": 1, - "retries": 0, - "status": "success", - "created_on": "2019-10-16T13:59:30.123456789Z" - } - ] - }, - { - "type": "ticket_opened", - "created_on": "2018-10-18T14:20:30.000123456Z", - "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", - "ticket": { - "uuid": "9688d21d-95aa-4bed-afc7-f31b35731a3d", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, - "topic": { - "uuid": "0d9a2c56-6fc2-4f27-93c5-a6322e26b740", - "name": "General" - }, - "body": "Last message: Hi everybody", - "external_id": "123456" - } - }, - { - "type": "contact_groups_changed", - "created_on": "2018-10-18T14:20:30.000123456Z", - "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", - "groups_added": [ - { - "uuid": "91564dee-e7ea-49b2-a903-598ce71b1d07", - "name": "With Tickets" - } - ] - }, - { - "type": "run_result_changed", - "created_on": "2018-10-18T14:20:30.000123456Z", - "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", - "name": "Ticket", - "value": "9688d21d-95aa-4bed-afc7-f31b35731a3d", - "category": "Success" - } - ], - "templates": [ - "Last message: @input.text" - ], - "inspection": { - "dependencies": [ - { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets", - "type": "ticketer" - } - ], + "dependencies": [], "issues": [], "results": [], "waiting_exits": [], @@ -966,10 +599,6 @@ "action": { "type": "open_ticket", "uuid": "ad154980-7bf7-4ab8-8728-545fd6378912", - "ticketer": { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets" - }, "topic": null, "body": "Last message: @input.text", "assignee": null, @@ -989,13 +618,7 @@ "Last message: @input.text" ], "inspection": { - "dependencies": [ - { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets", - "type": "ticketer" - } - ], + "dependencies": [], "issues": [], "results": [], "waiting_exits": [], diff --git a/flows/contact_test.go b/flows/contact_test.go index 191454c6c..762728ef5 100644 --- a/flows/contact_test.go +++ b/flows/contact_test.go @@ -36,13 +36,6 @@ func TestContact(t *testing.T) { "country": "US" } ], - "ticketers": [ - { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets", - "type": "mailgun" - } - ], "topics": [ { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", @@ -146,9 +139,8 @@ func TestContact(t *testing.T) { assert.Nil(t, contact.Ticket()) - mailgun := sa.Ticketers().Get("d605bb96-258d-4097-ad0a-080937db2212") weather := sa.Topics().Get("472a7a73-96cb-4736-b567-056d987cc5b4") - ticket := flows.OpenTicket(mailgun, weather, "I have issues", nil) + ticket := flows.OpenTicket(weather, "I have issues", nil) contact.SetTicket(ticket) assert.NotNil(t, contact.Ticket()) @@ -411,10 +403,6 @@ func TestContactQuery(t *testing.T) { ], "ticket": { "uuid": "e5f5a9b0-1c08-4e56-8f5c-92e00bc3cf52", - "ticketer": { - "uuid": "19dc6346-9623-4fe4-be80-538d493ecdf5", - "name": "Support Tickets" - }, "subject": "Old ticket", "body": "I have a problem", "assignee": null diff --git a/flows/engine/assets.go b/flows/engine/assets.go index 1c62e33ea..d98a36776 100644 --- a/flows/engine/assets.go +++ b/flows/engine/assets.go @@ -23,7 +23,6 @@ type sessionAssets struct { optIns *flows.OptInAssets resthooks *flows.ResthookAssets templates *flows.TemplateAssets - ticketers *flows.TicketerAssets topics *flows.TopicAssets users *flows.UserAssets } @@ -72,10 +71,6 @@ func NewSessionAssets(env envs.Environment, source assets.Source, migrationConfi if err != nil { return nil, err } - ticketers, err := source.Ticketers() - if err != nil { - return nil, err - } topics, err := source.Topics() if err != nil { return nil, err @@ -101,7 +96,6 @@ func NewSessionAssets(env envs.Environment, source assets.Source, migrationConfi optIns: flows.NewOptInAssets(optIns), resthooks: flows.NewResthookAssets(resthooks), templates: flows.NewTemplateAssets(templates), - ticketers: flows.NewTicketerAssets(ticketers), topics: flows.NewTopicAssets(topics), users: flows.NewUserAssets(users), }, nil @@ -119,7 +113,6 @@ func (s *sessionAssets) Locations() *flows.LocationAssets { return s.locatio func (s *sessionAssets) OptIns() *flows.OptInAssets { return s.optIns } func (s *sessionAssets) Resthooks() *flows.ResthookAssets { return s.resthooks } func (s *sessionAssets) Templates() *flows.TemplateAssets { return s.templates } -func (s *sessionAssets) Ticketers() *flows.TicketerAssets { return s.ticketers } func (s *sessionAssets) Topics() *flows.TopicAssets { return s.topics } func (s *sessionAssets) Users() *flows.UserAssets { return s.users } diff --git a/flows/engine/assets_test.go b/flows/engine/assets_test.go index db5d54759..77260060e 100644 --- a/flows/engine/assets_test.go +++ b/flows/engine/assets_test.go @@ -206,10 +206,6 @@ func (s *testSource) Templates() ([]assets.Template, error) { return nil, s.err("templates") } -func (s *testSource) Ticketers() ([]assets.Ticketer, error) { - return nil, s.err("ticketers") -} - func (s *testSource) Topics() ([]assets.Topic, error) { return nil, s.err("topics") } diff --git a/flows/engine/engine.go b/flows/engine/engine.go index 874ce852e..ee24829a5 100644 --- a/flows/engine/engine.go +++ b/flows/engine/engine.go @@ -86,12 +86,6 @@ func (b *Builder) WithClassificationServiceFactory(f ClassificationServiceFactor return b } -// WithTicketServiceFactory sets the ticket service factory -func (b *Builder) WithTicketServiceFactory(f TicketServiceFactory) *Builder { - b.eng.services.ticket = f - return b -} - // WithAirtimeServiceFactory sets the airtime service factory func (b *Builder) WithAirtimeServiceFactory(f AirtimeServiceFactory) *Builder { b.eng.services.airtime = f diff --git a/flows/engine/engine_test.go b/flows/engine/engine_test.go index f050fffd6..f50c9c8d9 100644 --- a/flows/engine/engine_test.go +++ b/flows/engine/engine_test.go @@ -33,8 +33,6 @@ func TestBuilder(t *testing.T) { assert.EqualError(t, err, "no airtime service factory configured") _, err = eng.Services().Classification(nil) assert.EqualError(t, err, "no classification service factory configured") - _, err = eng.Services().Ticket(nil) - assert.EqualError(t, err, "no ticket service factory configured") _, err = eng.Services().Webhook(nil) assert.EqualError(t, err, "no webhook service factory configured") diff --git a/flows/engine/services.go b/flows/engine/services.go index d10dfe4c3..10b604524 100644 --- a/flows/engine/services.go +++ b/flows/engine/services.go @@ -15,9 +15,6 @@ type WebhookServiceFactory func(flows.SessionAssets) (flows.WebhookService, erro // ClassificationServiceFactory resolves a session and classifier to an NLU service type ClassificationServiceFactory func(*flows.Classifier) (flows.ClassificationService, error) -// TicketServiceFactory resolves a session to a ticket service -type TicketServiceFactory func(*flows.Ticketer) (flows.TicketService, error) - // AirtimeServiceFactory resolves a session to an airtime service type AirtimeServiceFactory func(flows.SessionAssets) (flows.AirtimeService, error) @@ -25,7 +22,6 @@ type services struct { email EmailServiceFactory webhook WebhookServiceFactory classification ClassificationServiceFactory - ticket TicketServiceFactory airtime AirtimeServiceFactory } @@ -40,9 +36,6 @@ func newEmptyServices() *services { classification: func(*flows.Classifier) (flows.ClassificationService, error) { return nil, errors.New("no classification service factory configured") }, - ticket: func(*flows.Ticketer) (flows.TicketService, error) { - return nil, errors.New("no ticket service factory configured") - }, airtime: func(flows.SessionAssets) (flows.AirtimeService, error) { return nil, errors.New("no airtime service factory configured") }, @@ -61,10 +54,6 @@ func (s *services) Classification(classifier *flows.Classifier) (flows.Classific return s.classification(classifier) } -func (s *services) Ticket(ticketer *flows.Ticketer) (flows.TicketService, error) { - return s.ticket(ticketer) -} - func (s *services) Airtime(sa flows.SessionAssets) (flows.AirtimeService, error) { return s.airtime(sa) } diff --git a/flows/engine/session_test.go b/flows/engine/session_test.go index 1d958f703..86fa04bc5 100644 --- a/flows/engine/session_test.go +++ b/flows/engine/session_test.go @@ -167,8 +167,6 @@ func TestReadWithMissingAssets(t *testing.T) { "group[uuid=4f1f98fc-27a7-4a69-bbdb-24744ba739a9,name=Males]", "group[uuid=b7cf0d83-f1c9-411c-96fd-c511a4cfa86d,name=Testers]", "group[uuid=b7cf0d83-f1c9-411c-96fd-c511a4cfa86d,name=Testers]", - "ticketer[uuid=19dc6346-9623-4fe4-be80-538d493ecdf5,name=Support Tickets]", - "ticketer[uuid=19dc6346-9623-4fe4-be80-538d493ecdf5,name=Support Tickets]", "topic[uuid=472a7a73-96cb-4736-b567-056d987cc5b4,name=Weather]", "topic[uuid=472a7a73-96cb-4736-b567-056d987cc5b4,name=Weather]", "user[email=bob@nyaruka.com,name=Bob]", diff --git a/flows/events/base_test.go b/flows/events/base_test.go index dcf99c665..90159fe97 100644 --- a/flows/events/base_test.go +++ b/flows/events/base_test.go @@ -26,7 +26,6 @@ import ( "github.com/nyaruka/goflow/test" "github.com/nyaruka/goflow/utils" "github.com/shopspring/decimal" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -46,11 +45,10 @@ func TestEventMarshaling(t *testing.T) { expiresOn := time.Date(2022, 2, 3, 13, 45, 30, 0, time.UTC) gender := session.Assets().Fields().Get("gender") jotd := session.Assets().OptIns().Get("248be71d-78e9-4d71-a6c4-9981d369e5cb") - 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("bob@nyaruka.com") 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) + ticket := flows.NewTicket("7481888c-07dd-47dc-bf22-ef7448696ffe", weather, "Where are my cookies?", user) eventTests := []struct { event flows.Event @@ -312,10 +310,6 @@ func TestEventMarshaling(t *testing.T) { "name": "Bob" }, "body": "What day is it?", - "ticketer": { - "name": "Support Tickets", - "uuid": "19dc6346-9623-4fe4-be80-538d493ecdf5" - }, "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" @@ -618,16 +612,11 @@ func TestEventMarshaling(t *testing.T) { "created_on": "2018-10-18T14:20:30.000123456Z", "ticket": { "uuid": "7481888c-07dd-47dc-bf22-ef7448696ffe", - "ticketer": { - "uuid": "19dc6346-9623-4fe4-be80-538d493ecdf5", - "name": "Support Tickets" - }, "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" }, "body": "Where are my cookies?", - "external_id": "1243252", "assignee": { "email": "bob@nyaruka.com", "name": "Bob" @@ -635,47 +624,6 @@ func TestEventMarshaling(t *testing.T) { } }`, }, - { - events.NewTicketerCalled( - assets.NewTicketerReference(assets.TicketerUUID("4b937f49-7fb7-43a5-8e57-14e2f028a471"), "Support"), - []*flows.HTTPLog{ - { - HTTPLogWithoutTime: &flows.HTTPLogWithoutTime{ - LogWithoutTime: &httpx.LogWithoutTime{ - URL: "https://tickets.com", - StatusCode: 200, - Request: "GET /message?v=20200513&q=hello HTTP/1.1\r\nHost: tickets.com\r\nUser-Agent: Go-http-client/1.1\r\nAccept-Encoding: gzip\r\n\r\n", - Response: "HTTP/1.0 200 OK\r\nContent-Length: 0\r\n\r\n", - ElapsedMS: 12, - }, - Status: flows.CallStatusSuccess, - }, - CreatedOn: dates.Now(), - }, - }, - ), - `{ - "type": "service_called", - "created_on": "2018-10-18T14:20:30.000123456Z", - "service": "ticketer", - "ticketer": { - "uuid": "4b937f49-7fb7-43a5-8e57-14e2f028a471", - "name": "Support" - }, - "http_logs": [ - { - "url": "https://tickets.com", - "status_code": 200, - "status": "success", - "request": "GET /message?v=20200513&q=hello HTTP/1.1\r\nHost: tickets.com\r\nUser-Agent: Go-http-client/1.1\r\nAccept-Encoding: gzip\r\n\r\n", - "response": "HTTP/1.0 200 OK\r\nContent-Length: 0\r\n\r\n", - "elapsed_ms": 12, - "retries": 0, - "created_on": "2018-10-18T14:20:30.000123456Z" - } - ] - }`, - }, } for _, tc := range eventTests { diff --git a/flows/events/service_called.go b/flows/events/service_called.go index 505432294..72f9596c6 100644 --- a/flows/events/service_called.go +++ b/flows/events/service_called.go @@ -37,7 +37,6 @@ type ServiceCalledEvent struct { Service string `json:"service"` Classifier *assets.ClassifierReference `json:"classifier,omitempty"` - Ticketer *assets.TicketerReference `json:"ticketer,omitempty"` HTTPLogs []*flows.HTTPLog `json:"http_logs"` } @@ -50,13 +49,3 @@ func NewClassifierCalled(classifier *assets.ClassifierReference, httpLogs []*flo HTTPLogs: httpLogs, } } - -// NewTicketerCalled returns a service called event for a ticketer -func NewTicketerCalled(ticketer *assets.TicketerReference, httpLogs []*flows.HTTPLog) *ServiceCalledEvent { - return &ServiceCalledEvent{ - BaseEvent: NewBaseEvent(TypeServiceCalled), - Service: "ticketer", - Ticketer: ticketer, - HTTPLogs: httpLogs, - } -} diff --git a/flows/events/ticket_opened.go b/flows/events/ticket_opened.go index 07e619258..03d08be22 100644 --- a/flows/events/ticket_opened.go +++ b/flows/events/ticket_opened.go @@ -13,12 +13,10 @@ func init() { const TypeTicketOpened string = "ticket_opened" type Ticket struct { - UUID flows.TicketUUID `json:"uuid" validate:"required,uuid4"` - Ticketer *assets.TicketerReference `json:"ticketer" validate:"required"` - Topic *assets.TopicReference `json:"topic" validate:"omitempty"` - Body string `json:"body"` - ExternalID string `json:"external_id,omitempty"` - Assignee *assets.UserReference `json:"assignee,omitempty" validate:"omitempty"` + UUID flows.TicketUUID `json:"uuid" validate:"required,uuid4"` + Topic *assets.TopicReference `json:"topic" validate:"omitempty"` + Body string `json:"body"` + Assignee *assets.UserReference `json:"assignee,omitempty" validate:"omitempty"` } // TicketOpenedEvent events are created when a new ticket is opened. @@ -28,16 +26,11 @@ type Ticket struct { // "created_on": "2006-01-02T15:04:05Z", // "ticket": { // "uuid": "2e677ae6-9b57-423c-b022-7950503eef35", -// "ticketer": { -// "uuid": "d605bb96-258d-4097-ad0a-080937db2212", -// "name": "Support Tickets" -// }, // "topic": { // "uuid": "add17edf-0b6e-4311-bcd7-a64b2a459157", // "name": "Weather" // }, // "body": "Where are my cookies?", -// "external_id": "32526523", // "assignee": {"email": "bob@nyaruka.com", "name": "Bob"} // } // } @@ -54,12 +47,10 @@ func NewTicketOpened(ticket *flows.Ticket) *TicketOpenedEvent { return &TicketOpenedEvent{ BaseEvent: NewBaseEvent(TypeTicketOpened), Ticket: &Ticket{ - UUID: ticket.UUID(), - Ticketer: ticket.Ticketer().Reference(), - Topic: ticket.Topic().Reference(), - Body: ticket.Body(), - ExternalID: ticket.ExternalID(), - Assignee: ticket.Assignee().Reference(), + UUID: ticket.UUID(), + Topic: ticket.Topic().Reference(), + Body: ticket.Body(), + Assignee: ticket.Assignee().Reference(), }, } } diff --git a/flows/inspect/dependencies.go b/flows/inspect/dependencies.go index 060a189a5..02aa3a4a7 100644 --- a/flows/inspect/dependencies.go +++ b/flows/inspect/dependencies.go @@ -87,8 +87,6 @@ func CheckReference(sa flows.SessionAssets, ref assets.Reference) bool { return sa.OptIns().Get(typed.UUID) != nil case *assets.TemplateReference: return sa.Templates().Get(typed.UUID) != nil - case *assets.TicketerReference: - return sa.Ticketers().Get(typed.UUID) != nil case *assets.TopicReference: return sa.Topics().Get(typed.UUID) != nil case *assets.UserReference: diff --git a/flows/inspect/dependencies_test.go b/flows/inspect/dependencies_test.go index 6c0f9208b..6928ce320 100644 --- a/flows/inspect/dependencies_test.go +++ b/flows/inspect/dependencies_test.go @@ -47,7 +47,6 @@ func TestDependencies(t *testing.T) { flows.NewExtractedReference(node1, action1, nil, i18n.NilLanguage, assets.NewLabelReference("31c06b7c-010d-4f91-9590-d3fbdc2fb7ac", "Spam")), flows.NewExtractedReference(node1, action1, nil, i18n.NilLanguage, assets.NewOptInReference("c14b2e3f-997a-4547-a04e-6e9d5065c677", "Jokes")), flows.NewExtractedReference(node1, action1, nil, i18n.NilLanguage, assets.NewTemplateReference("ff958d30-f50e-48ab-a524-37ed1e9620d9", "Welcome")), - flows.NewExtractedReference(node1, action1, nil, i18n.NilLanguage, assets.NewTicketerReference("fb9cab80-4450-4a9d-ba9b-cb8df40dd233", "Support")), flows.NewExtractedReference(node1, action1, nil, i18n.NilLanguage, assets.NewTopicReference("531d3fc7-64f4-4170-927d-b477e8145dd3", "Weather")), flows.NewExtractedReference(node1, action1, nil, i18n.NilLanguage, assets.NewUserReference("jim@nyaruka.com", "Jim")), flows.NewExtractedReference(node2, nil, router2, i18n.NilLanguage, assets.NewGlobalReference("org_name", "Org Name")), @@ -134,12 +133,6 @@ func TestDependencies(t *testing.T) { "type": "template", "uuid": "ff958d30-f50e-48ab-a524-37ed1e9620d9" }, - { - "missing": true, - "name": "Support", - "type": "ticketer", - "uuid": "fb9cab80-4450-4a9d-ba9b-cb8df40dd233" - }, { "missing": true, "name": "Weather", diff --git a/flows/interfaces.go b/flows/interfaces.go index 6fd99ba60..9a32aeae0 100644 --- a/flows/interfaces.go +++ b/flows/interfaces.go @@ -113,7 +113,6 @@ type SessionAssets interface { OptIns() *OptInAssets Resthooks() *ResthookAssets Templates() *TemplateAssets - Ticketers() *TicketerAssets Topics() *TopicAssets Users() *UserAssets } diff --git a/flows/modifiers/testdata/_assets.json b/flows/modifiers/testdata/_assets.json index 19d85b153..a0baed408 100644 --- a/flows/modifiers/testdata/_assets.json +++ b/flows/modifiers/testdata/_assets.json @@ -93,18 +93,6 @@ "query": "name = \"\"" } ], - "ticketers": [ - { - "uuid": "856c2537-2af0-4457-8499-129e02f4bc18", - "name": "TextIt", - "type": "internal" - }, - { - "uuid": "d444ef20-0529-44af-966d-0e6be9cf584a", - "name": "Broken", - "type": "mailgun" - } - ], "topics": [ { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", diff --git a/flows/modifiers/testdata/ticket.json b/flows/modifiers/testdata/ticket.json index 3132653a9..3afca058a 100644 --- a/flows/modifiers/testdata/ticket.json +++ b/flows/modifiers/testdata/ticket.json @@ -10,10 +10,6 @@ }, "modifier": { "type": "ticket", - "ticketer": { - "uuid": "856c2537-2af0-4457-8499-129e02f4bc18", - "name": "TextIt" - }, "topic": { "uuid": "daa356b6-32af-44f0-9d35-6126d55ec3e9", "name": "Computers" @@ -31,16 +27,11 @@ "created_on": "2018-06-20T11:40:30.123456789Z", "ticket": { "uuid": "1ae96956-4b34-433e-8d1a-f05fe6923d6d", - "ticketer": { - "uuid": "856c2537-2af0-4457-8499-129e02f4bc18", - "name": "TextIt" - }, "topic": { "uuid": "daa356b6-32af-44f0-9d35-6126d55ec3e9", "name": "Computers" }, "body": "Where are my keys?", - "external_id": "123456", "assignee": { "email": "bob@nyaruka.com", "name": "Bob" @@ -48,42 +39,16 @@ } }, "events": [ - { - "type": "service_called", - "created_on": "2018-10-18T14:20:30.000123456Z", - "service": "ticketer", - "ticketer": { - "uuid": "856c2537-2af0-4457-8499-129e02f4bc18", - "name": "TextIt" - }, - "http_logs": [ - { - "url": "http://nyaruka.tickets.com/tickets.json", - "status_code": 200, - "status": "success", - "request": "POST /tickets.json HTTP/1.1\r\nAccept-Encoding: gzip\r\n\r\n{\"body\":\"Where are my keys?\"}", - "response": "HTTP/1.0 200 OK\r\nContent-Length: 15\r\n\r\n{\"status\":\"ok\"}", - "elapsed_ms": 1, - "retries": 0, - "created_on": "2019-10-16T13:59:30.123456789Z" - } - ] - }, { "type": "ticket_opened", "created_on": "2018-10-18T14:20:30.000123456Z", "ticket": { "uuid": "1ae96956-4b34-433e-8d1a-f05fe6923d6d", - "ticketer": { - "uuid": "856c2537-2af0-4457-8499-129e02f4bc18", - "name": "TextIt" - }, "topic": { "uuid": "daa356b6-32af-44f0-9d35-6126d55ec3e9", "name": "Computers" }, "body": "Where are my keys?", - "external_id": "123456", "assignee": { "email": "bob@nyaruka.com", "name": "Bob" @@ -93,56 +58,28 @@ ] }, { - "description": "error event if ticket service instantiation fails", + "description": "noop if ticket already open", "contact_before": { "uuid": "5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f", "name": "Bob", "status": "active", "fields": {}, - "created_on": "2018-06-20T11:40:30.123456789Z" - }, - "modifier": { - "type": "ticket", - "ticketer": { - "uuid": "d444ef20-0529-44af-966d-0e6be9cf584a", - "name": "Broken" - }, - "topic": { - "uuid": "daa356b6-32af-44f0-9d35-6126d55ec3e9", - "name": "Computers" - }, - "body": "Where are my keys?", - "assignee": null - }, - "contact_after": { - "uuid": "5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f", - "name": "Bob", - "status": "active", - "created_on": "2018-06-20T11:40:30.123456789Z" - }, - "events": [ - { - "type": "error", - "created_on": "2018-10-18T14:20:30.000123456Z", - "text": "can't load ticket service" + "created_on": "2018-06-20T11:40:30.123456789Z", + "ticket": { + "uuid": "1ae96956-4b34-433e-8d1a-f05fe6923d6d", + "topic": { + "uuid": "daa356b6-32af-44f0-9d35-6126d55ec3e9", + "name": "Computers" + }, + "body": "Where are my keys?", + "assignee": { + "email": "bob@nyaruka.com", + "name": "Bob" + } } - ] - }, - { - "description": "error event if ticket opening fails", - "contact_before": { - "uuid": "5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f", - "name": "Bob", - "status": "active", - "fields": {}, - "created_on": "2018-06-20T11:40:30.123456789Z" }, "modifier": { "type": "ticket", - "ticketer": { - "uuid": "856c2537-2af0-4457-8499-129e02f4bc18", - "name": "TextIt" - }, "topic": { "uuid": "daa356b6-32af-44f0-9d35-6126d55ec3e9", "name": "Computers" @@ -154,35 +91,20 @@ "uuid": "5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f", "name": "Bob", "status": "active", - "created_on": "2018-06-20T11:40:30.123456789Z" - }, - "events": [ - { - "type": "error", - "created_on": "2018-10-18T14:20:30.000123456Z", - "text": "error calling ticket API" - }, - { - "type": "service_called", - "created_on": "2018-10-18T14:20:30.000123456Z", - "service": "ticketer", - "ticketer": { - "uuid": "856c2537-2af0-4457-8499-129e02f4bc18", - "name": "TextIt" + "created_on": "2018-06-20T11:40:30.123456789Z", + "ticket": { + "uuid": "1ae96956-4b34-433e-8d1a-f05fe6923d6d", + "topic": { + "uuid": "daa356b6-32af-44f0-9d35-6126d55ec3e9", + "name": "Computers" }, - "http_logs": [ - { - "url": "http://nyaruka.tickets.com/tickets.json", - "status_code": 400, - "status": "response_error", - "request": "POST /tickets.json HTTP/1.1\r\nAccept-Encoding: gzip\r\n\r\n{\"body\":\"Should fail\"}", - "response": "HTTP/1.0 400 OK\r\nContent-Length: 17\r\n\r\n{\"status\":\"fail\"}", - "elapsed_ms": 1, - "retries": 0, - "created_on": "2019-10-16T13:59:30.123456789Z" - } - ] + "body": "Where are my keys?", + "assignee": { + "email": "bob@nyaruka.com", + "name": "Bob" + } } - ] + }, + "events": [] } ] \ No newline at end of file diff --git a/flows/modifiers/ticket.go b/flows/modifiers/ticket.go index ef54f484d..64eded65e 100644 --- a/flows/modifiers/ticket.go +++ b/flows/modifiers/ticket.go @@ -22,17 +22,15 @@ const TypeTicket string = "ticket" type TicketModifier struct { baseModifier - ticketer *flows.Ticketer topic *flows.Topic body string assignee *flows.User } // NewTicket creates a new ticket modifier -func NewTicket(ticketer *flows.Ticketer, topic *flows.Topic, body string, assignee *flows.User) *TicketModifier { +func NewTicket(topic *flows.Topic, body string, assignee *flows.User) *TicketModifier { return &TicketModifier{ baseModifier: newBaseModifier(TypeTicket), - ticketer: ticketer, topic: topic, body: body, assignee: assignee, @@ -46,34 +44,11 @@ func (m *TicketModifier) Apply(eng flows.Engine, env envs.Environment, sa flows. return false } - httpLogger := &flows.HTTPLogger{} + ticket := flows.OpenTicket(m.topic, m.body, m.assignee) + log(events.NewTicketOpened(ticket)) - // try to get a ticket service for this ticketer - svc, err := eng.Services().Ticket(m.ticketer) - if err != nil { - log(events.NewError(err)) - return false - } - - ticket, err := svc.Open(env, contact, m.topic, m.body, m.assignee, httpLogger.Log) - if err != nil { - log(events.NewError(err)) - } - if len(httpLogger.Logs) > 0 { - log(events.NewTicketerCalled(m.ticketer.Reference(), httpLogger.Logs)) - } - if ticket != nil { - log(events.NewTicketOpened(ticket)) - - contact.SetTicket(ticket) - return true - } - - return false -} - -func (m *TicketModifier) Ticketer() *flows.Ticketer { - return m.ticketer + contact.SetTicket(ticket) + return true } var _ flows.Modifier = (*TicketModifier)(nil) @@ -85,10 +60,9 @@ var _ flows.Modifier = (*TicketModifier)(nil) type ticketModifierEnvelope struct { utils.TypedEnvelope - Ticketer *assets.TicketerReference `json:"ticketer" validate:"required"` - Topic *assets.TopicReference `json:"topic" validate:"required"` - Body string `json:"body"` - Assignee *assets.UserReference `json:"assignee"` + Topic *assets.TopicReference `json:"topic" validate:"required"` + Body string `json:"body"` + Assignee *assets.UserReference `json:"assignee"` } func readTicketModifier(assets flows.SessionAssets, data json.RawMessage, missing assets.MissingCallback) (flows.Modifier, error) { @@ -97,12 +71,6 @@ func readTicketModifier(assets flows.SessionAssets, data json.RawMessage, missin return nil, err } - ticketer := assets.Ticketers().Get(e.Ticketer.UUID) - if ticketer == nil { - missing(e.Ticketer, nil) - return nil, ErrNoModifier // can't proceed without a ticketer - } - topic := assets.Topics().Get(e.Topic.UUID) if topic == nil { missing(e.Topic, nil) @@ -117,13 +85,12 @@ func readTicketModifier(assets flows.SessionAssets, data json.RawMessage, missin } } - return NewTicket(ticketer, topic, e.Body, assignee), nil + return NewTicket(topic, e.Body, assignee), nil } func (m *TicketModifier) MarshalJSON() ([]byte, error) { return jsonx.Marshal(&ticketModifierEnvelope{ TypedEnvelope: utils.TypedEnvelope{Type: m.Type()}, - Ticketer: m.ticketer.Reference(), Topic: m.topic.Reference(), Body: m.body, Assignee: m.assignee.Reference(), diff --git a/flows/services.go b/flows/services.go index b3486c976..3b20c3c22 100644 --- a/flows/services.go +++ b/flows/services.go @@ -18,7 +18,6 @@ type Services interface { Email(SessionAssets) (EmailService, error) Webhook(SessionAssets) (WebhookService, error) Classification(*Classifier) (ClassificationService, error) - Ticket(*Ticketer) (TicketService, error) Airtime(SessionAssets) (AirtimeService, error) } diff --git a/flows/tickets.go b/flows/tickets.go index 6354d3e0c..52a8efed8 100644 --- a/flows/tickets.go +++ b/flows/tickets.go @@ -14,38 +14,31 @@ type TicketUUID uuids.UUID // Ticket is a ticket in a ticketing system type Ticket struct { - uuid TicketUUID - ticketer *Ticketer - topic *Topic - body string - externalID string - assignee *User + uuid TicketUUID + topic *Topic + body string + assignee *User } // NewTicket creates a new ticket -func NewTicket(uuid TicketUUID, ticketer *Ticketer, topic *Topic, body, externalID string, assignee *User) *Ticket { +func NewTicket(uuid TicketUUID, topic *Topic, body string, assignee *User) *Ticket { return &Ticket{ - uuid: uuid, - ticketer: ticketer, - topic: topic, - body: body, - externalID: externalID, - assignee: assignee, + uuid: uuid, + topic: topic, + body: body, + assignee: assignee, } } // OpenTicket creates a new ticket. Used by ticketing services to open a new ticket. -func OpenTicket(ticketer *Ticketer, topic *Topic, body string, assignee *User) *Ticket { - return NewTicket(TicketUUID(uuids.New()), ticketer, topic, body, "", assignee) +func OpenTicket(topic *Topic, body string, assignee *User) *Ticket { + return NewTicket(TicketUUID(uuids.New()), topic, body, assignee) } -func (t *Ticket) UUID() TicketUUID { return t.uuid } -func (t *Ticket) Ticketer() *Ticketer { return t.ticketer } -func (t *Ticket) Topic() *Topic { return t.topic } -func (t *Ticket) Body() string { return t.body } -func (t *Ticket) ExternalID() string { return t.externalID } -func (t *Ticket) SetExternalID(id string) { t.externalID = id } -func (t *Ticket) Assignee() *User { return t.assignee } +func (t *Ticket) UUID() TicketUUID { return t.uuid } +func (t *Ticket) Topic() *Topic { return t.topic } +func (t *Ticket) Body() string { return t.body } +func (t *Ticket) Assignee() *User { return t.assignee } // Context returns the properties available in expressions // @@ -68,15 +61,13 @@ func (t *Ticket) Context(env envs.Environment) map[string]types.XValue { //------------------------------------------------------------------------------------------ type ticketEnvelope struct { - UUID TicketUUID `json:"uuid" validate:"required,uuid4"` - Ticketer *assets.TicketerReference `json:"ticketer" validate:"omitempty"` - Topic *assets.TopicReference `json:"topic" validate:"omitempty"` - Body string `json:"body"` - ExternalID string `json:"external_id,omitempty"` - Assignee *assets.UserReference `json:"assignee,omitempty" validate:"omitempty"` + UUID TicketUUID `json:"uuid" validate:"required,uuid4"` + Topic *assets.TopicReference `json:"topic" validate:"omitempty"` + Body string `json:"body"` + Assignee *assets.UserReference `json:"assignee,omitempty" validate:"omitempty"` } -// ReadTicket decodes a contact from the passed in JSON. If the ticketer or assigned user can't +// ReadTicket decodes a contact from the passed in JSON. If the topic or assigned user can't // be found in the assets, we report the missing asset and return ticket without those. func ReadTicket(sa SessionAssets, data []byte, missing assets.MissingCallback) (*Ticket, error) { e := &ticketEnvelope{} @@ -85,11 +76,6 @@ func ReadTicket(sa SessionAssets, data []byte, missing assets.MissingCallback) ( return nil, err } - ticketer := sa.Ticketers().Get(e.Ticketer.UUID) - if ticketer == nil { - missing(e.Ticketer, nil) - } - var topic *Topic if e.Topic != nil { topic = sa.Topics().Get(e.Topic.UUID) @@ -107,22 +93,15 @@ func ReadTicket(sa SessionAssets, data []byte, missing assets.MissingCallback) ( } return &Ticket{ - uuid: e.UUID, - ticketer: ticketer, - topic: topic, - body: e.Body, - externalID: e.ExternalID, - assignee: assignee, + uuid: e.UUID, + topic: topic, + body: e.Body, + assignee: assignee, }, nil } // MarshalJSON marshals this ticket into JSON func (t *Ticket) MarshalJSON() ([]byte, error) { - var ticketerRef *assets.TicketerReference - if t.ticketer != nil { - ticketerRef = t.ticketer.Reference() - } - var topicRef *assets.TopicReference if t.topic != nil { topicRef = t.topic.Reference() @@ -134,53 +113,9 @@ func (t *Ticket) MarshalJSON() ([]byte, error) { } return jsonx.Marshal(&ticketEnvelope{ - UUID: t.uuid, - Ticketer: ticketerRef, - Topic: topicRef, - Body: t.body, - ExternalID: t.externalID, - Assignee: assigneeRef, + UUID: t.uuid, + Topic: topicRef, + Body: t.body, + Assignee: assigneeRef, }) } - -// Ticketer represents a ticket issuing system. -type Ticketer struct { - assets.Ticketer -} - -// NewTicketer returns a new classifier object from the given classifier asset -func NewTicketer(asset assets.Ticketer) *Ticketer { - return &Ticketer{Ticketer: asset} -} - -// Asset returns the underlying asset -func (t *Ticketer) Asset() assets.Ticketer { return t.Ticketer } - -// Reference returns a reference to this classifier -func (t *Ticketer) Reference() *assets.TicketerReference { - if t == nil { - return nil - } - return assets.NewTicketerReference(t.UUID(), t.Name()) -} - -// TicketerAssets provides access to all ticketer assets -type TicketerAssets struct { - byUUID map[assets.TicketerUUID]*Ticketer -} - -// NewTicketerAssets creates a new set of ticketer assets -func NewTicketerAssets(ticketers []assets.Ticketer) *TicketerAssets { - s := &TicketerAssets{ - byUUID: make(map[assets.TicketerUUID]*Ticketer, len(ticketers)), - } - for _, asset := range ticketers { - s.byUUID[asset.UUID()] = NewTicketer(asset) - } - return s -} - -// Get returns the ticketer with the given UUID -func (s *TicketerAssets) Get(uuid assets.TicketerUUID) *Ticketer { - return s.byUUID[uuid] -} diff --git a/flows/tickets_test.go b/flows/tickets_test.go index c3804e47a..a50a23bf9 100644 --- a/flows/tickets_test.go +++ b/flows/tickets_test.go @@ -9,7 +9,6 @@ import ( "github.com/nyaruka/goflow/envs" "github.com/nyaruka/goflow/flows" "github.com/nyaruka/goflow/flows/engine" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -21,18 +20,6 @@ func TestTickets(t *testing.T) { env := envs.NewBuilder().Build() source, err := static.NewSource([]byte(`{ - "ticketers": [ - { - "uuid": "d605bb96-258d-4097-ad0a-080937db2212", - "name": "Support Tickets", - "type": "internal" - }, - { - "uuid": "5885ed52-8d3e-4fd3-be49-57eebe5d4d59", - "name": "Email Tickets", - "type": "mailgun" - } - ], "topics": [ { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", @@ -55,12 +42,6 @@ func TestTickets(t *testing.T) { sa, err := engine.NewSessionAssets(env, source, nil) require.NoError(t, err) - mailgun := sa.Ticketers().Get("5885ed52-8d3e-4fd3-be49-57eebe5d4d59") - assert.Equal(t, assets.TicketerUUID("5885ed52-8d3e-4fd3-be49-57eebe5d4d59"), mailgun.UUID()) - assert.Equal(t, "Email Tickets", mailgun.Name()) - assert.Equal(t, "mailgun", mailgun.Type()) - assert.Equal(t, assets.NewTicketerReference("5885ed52-8d3e-4fd3-be49-57eebe5d4d59", "Email Tickets"), mailgun.Reference()) - weather := sa.Topics().Get("472a7a73-96cb-4736-b567-056d987cc5b4") assert.Equal(t, assets.TopicUUID("472a7a73-96cb-4736-b567-056d987cc5b4"), weather.UUID()) assert.Equal(t, "Weather", weather.Name()) @@ -85,33 +66,27 @@ func TestTickets(t *testing.T) { ticket1, err := flows.ReadTicket(sa, []byte(`{ "uuid": "349c851f-3f8e-4353-8bf2-8e90b6d73530", - "ticketer": {"uuid": "0a0b5ce4-35c9-47b7-b124-40258f0a5b53", "name": "Deleted"}, "topic": {"uuid": "fd3ffcf3-c609-423e-b40f-f7f291a91cc6", "name": "Deleted"}, "subject": "Very Old Ticket", - "body": "Ticketer, topic and assignee gone!", - "external_id": "7654", + "body": "Topic and assignee gone!", "assignee": {"email": "dave@nyaruka.com", "name": "Dave"} }`), missing) require.NoError(t, err) assert.Equal(t, flows.TicketUUID("349c851f-3f8e-4353-8bf2-8e90b6d73530"), ticket1.UUID()) - assert.Nil(t, ticket1.Ticketer()) assert.Nil(t, ticket1.Topic()) - assert.Equal(t, "Ticketer, topic and assignee gone!", ticket1.Body()) - assert.Equal(t, "7654", ticket1.ExternalID()) + assert.Equal(t, "Topic and assignee gone!", ticket1.Body()) assert.Nil(t, ticket1.Assignee()) - // check that missing ticketer, topic and assignee are logged as a missing dependencies - assert.Equal(t, 3, len(missingRefs)) - assert.Equal(t, "0a0b5ce4-35c9-47b7-b124-40258f0a5b53", missingRefs[0].Identity()) - assert.Equal(t, "fd3ffcf3-c609-423e-b40f-f7f291a91cc6", missingRefs[1].Identity()) - assert.Equal(t, "dave@nyaruka.com", missingRefs[2].Identity()) + // check that missing topic and assignee are logged as a missing dependencies + assert.Equal(t, 2, len(missingRefs)) + assert.Equal(t, "fd3ffcf3-c609-423e-b40f-f7f291a91cc6", missingRefs[0].Identity()) + assert.Equal(t, "dave@nyaruka.com", missingRefs[1].Identity()) missingRefs = make([]assets.Reference, 0) ticket2, err := flows.ReadTicket(sa, []byte(`{ "uuid": "5a4af021-d2c2-47fc-9abc-abbb8635d8c0", - "ticketer": {"uuid": "d605bb96-258d-4097-ad0a-080937db2212", "name": "Support Tickets"}, "topic": {"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather"}, "subject": "Old Ticket", "body": "Where are my shoes?", @@ -120,16 +95,12 @@ func TestTickets(t *testing.T) { require.NoError(t, err) assert.Equal(t, 0, len(missingRefs)) - assert.Equal(t, "Support Tickets", ticket2.Ticketer().Name()) assert.Equal(t, "Bob", ticket2.Assignee().Name()) - ticket3 := flows.OpenTicket(mailgun, weather, "Where are my pants?", bob) - ticket3.SetExternalID("24567") + ticket3 := flows.OpenTicket(weather, "Where are my pants?", bob) assert.Equal(t, flows.TicketUUID("1ae96956-4b34-433e-8d1a-f05fe6923d6d"), ticket3.UUID()) - assert.Equal(t, mailgun, ticket3.Ticketer()) assert.Equal(t, weather, ticket3.Topic()) assert.Equal(t, "Where are my pants?", ticket3.Body()) - assert.Equal(t, "24567", ticket3.ExternalID()) assert.Equal(t, "Bob", ticket2.Assignee().Name()) } diff --git a/flows/triggers/base_test.go b/flows/triggers/base_test.go index 4ed2be066..145be3145 100644 --- a/flows/triggers/base_test.go +++ b/flows/triggers/base_test.go @@ -21,7 +21,6 @@ import ( "github.com/nyaruka/goflow/flows/engine" "github.com/nyaruka/goflow/flows/triggers" "github.com/nyaruka/goflow/test" - "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -158,13 +157,6 @@ var assetsJSON = `{ "name": "Joke Of The Day" } ], - "ticketers": [ - { - "uuid": "19dc6346-9623-4fe4-be80-538d493ecdf5", - "name": "Support Tickets", - "type": "mailgun" - } - ], "users": [ { "email": "bob@nyaruka.com", @@ -191,10 +183,9 @@ func TestTriggerMarshaling(t *testing.T) { flow := assets.NewFlowReference("7c37d7e5-6468-4b31-8109-ced2ef8b5ddc", "Registration") channel := assets.NewChannelReference("3a05eaf5-cb1b-4246-bef1-f277419c83a7", "Nexmo") jotd := sa.OptIns().Get("248be71d-78e9-4d71-a6c4-9981d369e5cb") - ticketer := sa.Ticketers().Get("19dc6346-9623-4fe4-be80-538d493ecdf5") weather := sa.Topics().Get("472a7a73-96cb-4736-b567-056d987cc5b4") user := sa.Users().Get("bob@nyaruka.com") - ticket := flows.NewTicket("276c2e43-d6f9-4c36-8e54-b5af5039acf6", ticketer, weather, "Where are my shoes?", "123456", user) + ticket := flows.NewTicket("276c2e43-d6f9-4c36-8e54-b5af5039acf6", weather, "Where are my shoes?", user) contact := flows.NewEmptyContact(sa, "Bob", i18n.Language("eng"), nil) contact.AddURN(urns.URN("tel:+12065551212"), nil) diff --git a/flows/triggers/testdata/TestTriggerMarshaling_ticket_closed.snap b/flows/triggers/testdata/TestTriggerMarshaling_ticket_closed.snap index ec8e05d08..112a6e5a7 100644 --- a/flows/triggers/testdata/TestTriggerMarshaling_ticket_closed.snap +++ b/flows/triggers/testdata/TestTriggerMarshaling_ticket_closed.snap @@ -30,13 +30,8 @@ "type": "closed", "ticket": { "uuid": "276c2e43-d6f9-4c36-8e54-b5af5039acf6", - "ticketer": { - "uuid": "19dc6346-9623-4fe4-be80-538d493ecdf5", - "name": "Support Tickets" - }, "topic": null, "body": "Where are my shoes?", - "external_id": "123456", "assignee": { "email": "bob@nyaruka.com", "name": "Bob McTickets" diff --git a/flows/triggers/testdata/_assets.json b/flows/triggers/testdata/_assets.json index f0c756f8d..b944e0e9e 100644 --- a/flows/triggers/testdata/_assets.json +++ b/flows/triggers/testdata/_assets.json @@ -39,13 +39,6 @@ "name": "Joke Of The Day" } ], - "ticketers": [ - { - "uuid": "19dc6346-9623-4fe4-be80-538d493ecdf5", - "name": "Support Tickets", - "type": "mailgun" - } - ], "topics": [ { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", diff --git a/flows/triggers/testdata/ticket.json b/flows/triggers/testdata/ticket.json index 713cf0d5c..f2f4af366 100644 --- a/flows/triggers/testdata/ticket.json +++ b/flows/triggers/testdata/ticket.json @@ -36,16 +36,11 @@ "type": "closed", "ticket": { "uuid": "0d43506d-b92f-4468-8bee-0f31dd438abf", - "ticketer": { - "uuid": "19dc6346-9623-4fe4-be80-538d493ecdf5", - "name": "Support Tickets" - }, "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" }, - "body": "Where are my shoes?", - "external_id": "12345" + "body": "Where are my shoes?" } } }, diff --git a/flows/triggers/ticket.go b/flows/triggers/ticket.go index fa5eaee37..fa582295b 100644 --- a/flows/triggers/ticket.go +++ b/flows/triggers/ticket.go @@ -47,7 +47,6 @@ type TicketEvent struct { // "type": "closed", // "ticket": { // "uuid": "58e9b092-fe42-4173-876c-ff45a14a24fe", -// "ticketer": {"uuid": "19dc6346-9623-4fe4-be80-538d493ecdf5", "name": "Support Tickets"}, // "topic": {"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather"}, // "body": "Where are my shoes?" // } diff --git a/test/engine.go b/test/engine.go index ffa6c7daf..ca7680993 100644 --- a/test/engine.go +++ b/test/engine.go @@ -1,9 +1,7 @@ package test import ( - "fmt" "net/http" - "strings" "time" "github.com/nyaruka/gocommon/httpx" @@ -12,7 +10,6 @@ import ( "github.com/nyaruka/goflow/flows" "github.com/nyaruka/goflow/flows/engine" "github.com/nyaruka/goflow/services/webhooks" - "github.com/pkg/errors" "github.com/shopspring/decimal" ) @@ -30,12 +27,6 @@ func NewEngine() flows.Engine { WithClassificationServiceFactory(func(c *flows.Classifier) (flows.ClassificationService, error) { return newClassificationService(c), nil }). - WithTicketServiceFactory(func(t *flows.Ticketer) (flows.TicketService, error) { - if t.Name() == "Broken" { - return nil, errors.New("can't load ticket service") - } - return NewTicketService(t), nil - }). WithAirtimeServiceFactory(func(flows.SessionAssets) (flows.AirtimeService, error) { return newAirtimeService("RWF"), nil }). Build() } @@ -98,56 +89,6 @@ func (s *classificationService) Classify(env envs.Environment, input string, log var _ flows.ClassificationService = (*classificationService)(nil) -// implementation of a ticket service for testing which fails if ticket subject contains "fail" and passes if not -type ticketService struct { - ticketer *flows.Ticketer -} - -// NewTicketService creates a new ticket service for testing -func NewTicketService(ticketer *flows.Ticketer) flows.TicketService { - return &ticketService{ticketer: ticketer} -} - -func (s *ticketService) Open(env envs.Environment, contact *flows.Contact, topic *flows.Topic, body string, assignee *flows.User, logHTTP flows.HTTPLogCallback) (*flows.Ticket, error) { - if strings.Contains(body, "fail") { - logHTTP(&flows.HTTPLog{ - HTTPLogWithoutTime: &flows.HTTPLogWithoutTime{ - LogWithoutTime: &httpx.LogWithoutTime{ - URL: "http://nyaruka.tickets.com/tickets.json", - StatusCode: 400, - Request: fmt.Sprintf("POST /tickets.json HTTP/1.1\r\nAccept-Encoding: gzip\r\n\r\n{\"body\":\"%s\"}", body), - Response: "HTTP/1.0 400 OK\r\nContent-Length: 17\r\n\r\n{\"status\":\"fail\"}", - ElapsedMS: 1, - Retries: 0, - }, - Status: flows.CallStatusResponseError, - }, - CreatedOn: time.Date(2019, 10, 16, 13, 59, 30, 123456789, time.UTC), - }) - - return nil, errors.New("error calling ticket API") - } - - logHTTP(&flows.HTTPLog{ - HTTPLogWithoutTime: &flows.HTTPLogWithoutTime{ - LogWithoutTime: &httpx.LogWithoutTime{ - URL: "http://nyaruka.tickets.com/tickets.json", - StatusCode: 200, - Request: fmt.Sprintf("POST /tickets.json HTTP/1.1\r\nAccept-Encoding: gzip\r\n\r\n{\"body\":\"%s\"}", body), - Response: "HTTP/1.0 200 OK\r\nContent-Length: 15\r\n\r\n{\"status\":\"ok\"}", - ElapsedMS: 1, - Retries: 0, - }, - Status: flows.CallStatusSuccess, - }, - CreatedOn: time.Date(2019, 10, 16, 13, 59, 30, 123456789, time.UTC), - }) - - ticket := flows.OpenTicket(s.ticketer, topic, body, assignee) - ticket.SetExternalID("123456") - return ticket, nil -} - // implementation of an airtime service for testing which uses a fixed currency type airtimeService struct { fixedCurrency string diff --git a/test/runner_test.go b/test/runner_test.go index 359bcdcb6..8685ae488 100644 --- a/test/runner_test.go +++ b/test/runner_test.go @@ -125,9 +125,6 @@ func runFlow(assetsPath string, rawTrigger json.RawMessage, rawResumes []json.Ra WithAirtimeServiceFactory(func(flows.SessionAssets) (flows.AirtimeService, error) { return dtone.NewService(http.DefaultClient, nil, "nyaruka", "123456789"), nil }). - WithTicketServiceFactory(func(t *flows.Ticketer) (flows.TicketService, error) { - return NewTicketService(t), nil - }). Build() session, sprint, err := eng.NewSession(sa, trigger) diff --git a/test/session.go b/test/session.go index 6a098b4f8..7f742c752 100644 --- a/test/session.go +++ b/test/session.go @@ -62,13 +62,6 @@ var sessionAssets = `{ "name": "Joke Of The Day" } ], - "ticketers": [ - { - "uuid": "19dc6346-9623-4fe4-be80-538d493ecdf5", - "name": "Support Tickets", - "type": "mailgun" - } - ], "topics": [ { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", @@ -335,10 +328,6 @@ var sessionTrigger = `{ "uuid": "78d1fe0d-7e39-461e-81c3-a6a25f15ed69", "subject": "Question", "body": "What day is it?", - "ticketer": { - "name": "Support Tickets", - "uuid": "19dc6346-9623-4fe4-be80-538d493ecdf5" - }, "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" diff --git a/test/testdata/runner/ticketing.json b/test/testdata/runner/ticketing.json index 3c156069d..1c03176a4 100644 --- a/test/testdata/runner/ticketing.json +++ b/test/testdata/runner/ticketing.json @@ -56,10 +56,6 @@ { "type": "open_ticket", "uuid": "3cd8f2db-8429-462e-ab93-8041dd23abf1", - "ticketer": { - "uuid": "1c0e9407-0e0f-4a00-b08a-c611c225d38d", - "name": "Support" - }, "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" @@ -127,13 +123,6 @@ ] } ], - "ticketers": [ - { - "uuid": "1c0e9407-0e0f-4a00-b08a-c611c225d38d", - "name": "Support", - "type": "mailgun" - } - ], "topics": [ { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", diff --git a/test/testdata/runner/ticketing.test.json b/test/testdata/runner/ticketing.test.json index 2d30e8d68..fd846e557 100644 --- a/test/testdata/runner/ticketing.test.json +++ b/test/testdata/runner/ticketing.test.json @@ -161,36 +161,9 @@ }, { "created_on": "2018-07-06T12:30:18.123456789Z", - "http_logs": [ - { - "created_on": "2019-10-16T13:59:30.123456789Z", - "elapsed_ms": 1, - "request": "POST /tickets.json HTTP/1.1\r\nAccept-Encoding: gzip\r\n\r\n{\"body\":\"Last message: Rats\"}", - "response": "HTTP/1.0 200 OK\r\nContent-Length: 15\r\n\r\n{\"status\":\"ok\"}", - "retries": 0, - "status": "success", - "status_code": 200, - "url": "http://nyaruka.tickets.com/tickets.json" - } - ], - "service": "ticketer", - "step_uuid": "970b8069-50f5-4f6f-8f41-6b2d9f33d623", - "ticketer": { - "name": "Support", - "uuid": "1c0e9407-0e0f-4a00-b08a-c611c225d38d" - }, - "type": "service_called" - }, - { - "created_on": "2018-07-06T12:30:20.123456789Z", "step_uuid": "970b8069-50f5-4f6f-8f41-6b2d9f33d623", "ticket": { "body": "Last message: Rats", - "external_id": "123456", - "ticketer": { - "name": "Support", - "uuid": "1c0e9407-0e0f-4a00-b08a-c611c225d38d" - }, "topic": { "name": "Weather", "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4" @@ -201,7 +174,7 @@ }, { "category": "Success", - "created_on": "2018-07-06T12:30:24.123456789Z", + "created_on": "2018-07-06T12:30:22.123456789Z", "name": "Ticket", "step_uuid": "970b8069-50f5-4f6f-8f41-6b2d9f33d623", "type": "run_result_changed", @@ -209,7 +182,7 @@ }, { "body": "[{\"assignee\":null,\"body\":\"Last message: Rats\",\"topic\":{\"name\":\"Weather\",\"uuid\":\"472a7a73-96cb-4736-b567-056d987cc5b4\"},\"uuid\":\"5ecda5fc-951c-437b-a17e-f85e49829fb9\"}]", - "created_on": "2018-07-06T12:30:28.123456789Z", + "created_on": "2018-07-06T12:30:26.123456789Z", "step_uuid": "312d3af0-a565-4c96-ba00-bd7f0d08e671", "subject": "New ticket: 5ecda5fc-951c-437b-a17e-f85e49829fb9", "to": [ @@ -233,7 +206,7 @@ "flow_uuid": "3486fc59-d417-4189-93cd-e0aa8e3112ac", "node_uuid": "145eb3d3-b841-4e66-abac-297ae525c7ad", "operand": "5ecda5fc-951c-437b-a17e-f85e49829fb9", - "time": "2018-07-06T12:30:26.123456789Z" + "time": "2018-07-06T12:30:24.123456789Z" } ], "session": { @@ -246,11 +219,6 @@ "status": "active", "ticket": { "body": "Last message: Rats", - "external_id": "123456", - "ticketer": { - "name": "Support", - "uuid": "1c0e9407-0e0f-4a00-b08a-c611c225d38d" - }, "topic": { "name": "Weather", "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4" @@ -325,36 +293,9 @@ }, { "created_on": "2018-07-06T12:30:18.123456789Z", - "http_logs": [ - { - "created_on": "2019-10-16T13:59:30.123456789Z", - "elapsed_ms": 1, - "request": "POST /tickets.json HTTP/1.1\r\nAccept-Encoding: gzip\r\n\r\n{\"body\":\"Last message: Rats\"}", - "response": "HTTP/1.0 200 OK\r\nContent-Length: 15\r\n\r\n{\"status\":\"ok\"}", - "retries": 0, - "status": "success", - "status_code": 200, - "url": "http://nyaruka.tickets.com/tickets.json" - } - ], - "service": "ticketer", - "step_uuid": "970b8069-50f5-4f6f-8f41-6b2d9f33d623", - "ticketer": { - "name": "Support", - "uuid": "1c0e9407-0e0f-4a00-b08a-c611c225d38d" - }, - "type": "service_called" - }, - { - "created_on": "2018-07-06T12:30:20.123456789Z", "step_uuid": "970b8069-50f5-4f6f-8f41-6b2d9f33d623", "ticket": { "body": "Last message: Rats", - "external_id": "123456", - "ticketer": { - "name": "Support", - "uuid": "1c0e9407-0e0f-4a00-b08a-c611c225d38d" - }, "topic": { "name": "Weather", "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4" @@ -365,7 +306,7 @@ }, { "category": "Success", - "created_on": "2018-07-06T12:30:24.123456789Z", + "created_on": "2018-07-06T12:30:22.123456789Z", "name": "Ticket", "step_uuid": "970b8069-50f5-4f6f-8f41-6b2d9f33d623", "type": "run_result_changed", @@ -373,7 +314,7 @@ }, { "body": "[{\"assignee\":null,\"body\":\"Last message: Rats\",\"topic\":{\"name\":\"Weather\",\"uuid\":\"472a7a73-96cb-4736-b567-056d987cc5b4\"},\"uuid\":\"5ecda5fc-951c-437b-a17e-f85e49829fb9\"}]", - "created_on": "2018-07-06T12:30:28.123456789Z", + "created_on": "2018-07-06T12:30:26.123456789Z", "step_uuid": "312d3af0-a565-4c96-ba00-bd7f0d08e671", "subject": "New ticket: 5ecda5fc-951c-437b-a17e-f85e49829fb9", "to": [ @@ -382,12 +323,12 @@ "type": "email_sent" } ], - "exited_on": "2018-07-06T12:30:30.123456789Z", + "exited_on": "2018-07-06T12:30:28.123456789Z", "flow": { "name": "Support", "uuid": "3486fc59-d417-4189-93cd-e0aa8e3112ac" }, - "modified_on": "2018-07-06T12:30:30.123456789Z", + "modified_on": "2018-07-06T12:30:28.123456789Z", "path": [ { "arrived_on": "2018-07-06T12:30:01.123456789Z", @@ -408,7 +349,7 @@ "uuid": "970b8069-50f5-4f6f-8f41-6b2d9f33d623" }, { - "arrived_on": "2018-07-06T12:30:27.123456789Z", + "arrived_on": "2018-07-06T12:30:25.123456789Z", "exit_uuid": "b6562dea-d21c-4a99-b904-0fb9583fb5ab", "node_uuid": "ac3fcd8e-e7bb-4545-865d-39424a8f1d7b", "uuid": "312d3af0-a565-4c96-ba00-bd7f0d08e671" @@ -425,7 +366,7 @@ }, "ticket": { "category": "Success", - "created_on": "2018-07-06T12:30:22.123456789Z", + "created_on": "2018-07-06T12:30:20.123456789Z", "name": "Ticket", "node_uuid": "145eb3d3-b841-4e66-abac-297ae525c7ad", "value": "5ecda5fc-951c-437b-a17e-f85e49829fb9"