diff --git a/flows/actions/testdata/open_ticket.json b/flows/actions/testdata/open_ticket.json index e6d44153c..6e525e4dd 100644 --- a/flows/actions/testdata/open_ticket.json +++ b/flows/actions/testdata/open_ticket.json @@ -120,12 +120,7 @@ "email": "bob@nyaruka.com", "name": "Bob" } - } - }, - { - "type": "ticket_note_added", - "created_on": "2018-10-18T14:20:30.000123456Z", - "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", + }, "note": "Last message: Hi everybody" }, { @@ -234,12 +229,7 @@ "uuid": "0d9a2c56-6fc2-4f27-93c5-a6322e26b740", "name": "General" } - } - }, - { - "type": "ticket_note_added", - "created_on": "2018-10-18T14:20:30.000123456Z", - "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", + }, "note": "Last message: Hi everybody" }, { @@ -342,12 +332,7 @@ "email": "jim@nyaruka.com", "name": "Jim" } - } - }, - { - "type": "ticket_note_added", - "created_on": "2018-10-18T14:20:30.000123456Z", - "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", + }, "note": "Last message: Hi everybody" }, { @@ -463,12 +448,7 @@ "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" } - } - }, - { - "type": "ticket_note_added", - "created_on": "2018-10-18T14:20:30.000123456Z", - "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", + }, "note": "Last message: Hi everybody" }, { diff --git a/flows/events/base_test.go b/flows/events/base_test.go index 1f2d3d44c..5b62920d7 100644 --- a/flows/events/base_test.go +++ b/flows/events/base_test.go @@ -611,15 +611,7 @@ func TestEventMarshaling(t *testing.T) { }`, }, { - events.NewTicketNoteAdded("this is weird"), - `{ - "type": "ticket_note_added", - "created_on": "2018-10-18T14:20:30.000123456Z", - "note": "this is weird" - }`, - }, - { - events.NewTicketOpened(ticket), + events.NewTicketOpened(ticket, "this is weird"), `{ "type": "ticket_opened", "created_on": "2018-10-18T14:20:30.000123456Z", @@ -633,7 +625,8 @@ func TestEventMarshaling(t *testing.T) { "email": "bob@nyaruka.com", "name": "Bob" } - } + }, + "note": "this is weird" }`, }, } diff --git a/flows/events/ticket_note_added.go b/flows/events/ticket_note_added.go deleted file mode 100644 index 7dad5eceb..000000000 --- a/flows/events/ticket_note_added.go +++ /dev/null @@ -1,35 +0,0 @@ -package events - -import ( - "github.com/nyaruka/goflow/flows" -) - -func init() { - registerType(TypeTicketNoteAdded, func() flows.Event { return &TicketNoteAddedEvent{} }) -} - -// TypeTicketNoteAdded is the type for our ticket note added events -const TypeTicketNoteAdded string = "ticket_note_added" - -// TicketNoteAddedEvent events are created when a note is added to the currently open ticket. -// -// { -// "type": "ticket_note_added", -// "created_on": "2006-01-02T15:04:05Z", -// "note": "this is weird" -// } -// -// @event ticket_note_added -type TicketNoteAddedEvent struct { - BaseEvent - - Note string `json:"note"` -} - -// NewTicketNoteAdded returns a new ticket note added event -func NewTicketNoteAdded(note string) *TicketNoteAddedEvent { - return &TicketNoteAddedEvent{ - BaseEvent: NewBaseEvent(TypeTicketNoteAdded), - Note: note, - } -} diff --git a/flows/events/ticket_opened.go b/flows/events/ticket_opened.go index 3e87ebd34..7ce8c6fad 100644 --- a/flows/events/ticket_opened.go +++ b/flows/events/ticket_opened.go @@ -30,7 +30,8 @@ type Ticket struct { // "name": "Weather" // }, // "assignee": {"email": "bob@nyaruka.com", "name": "Bob"} -// } +// }, +// "note": "this is weird" // } // // @event ticket_opened @@ -38,10 +39,11 @@ type TicketOpenedEvent struct { BaseEvent Ticket *Ticket `json:"ticket"` + Note string `json:"note,omitempty"` } // NewTicketOpened returns a new ticket opened event -func NewTicketOpened(ticket *flows.Ticket) *TicketOpenedEvent { +func NewTicketOpened(ticket *flows.Ticket, note string) *TicketOpenedEvent { return &TicketOpenedEvent{ BaseEvent: NewBaseEvent(TypeTicketOpened), Ticket: &Ticket{ @@ -49,5 +51,6 @@ func NewTicketOpened(ticket *flows.Ticket) *TicketOpenedEvent { Topic: ticket.Topic().Reference(), Assignee: ticket.Assignee().Reference(), }, + Note: note, } } diff --git a/flows/modifiers/testdata/ticket.json b/flows/modifiers/testdata/ticket.json index 89a4916b8..85ea96536 100644 --- a/flows/modifiers/testdata/ticket.json +++ b/flows/modifiers/testdata/ticket.json @@ -52,11 +52,7 @@ "email": "bob@nyaruka.com", "name": "Bob" } - } - }, - { - "type": "ticket_note_added", - "created_on": "2018-10-18T14:20:30.000123456Z", + }, "note": "this is a note" } ] diff --git a/flows/modifiers/ticket.go b/flows/modifiers/ticket.go index be8aa5da0..1efbd7f02 100644 --- a/flows/modifiers/ticket.go +++ b/flows/modifiers/ticket.go @@ -45,10 +45,7 @@ func (m *TicketModifier) Apply(eng flows.Engine, env envs.Environment, sa flows. } ticket := flows.OpenTicket(m.topic, m.assignee) - log(events.NewTicketOpened(ticket)) - if m.note != "" { - log(events.NewTicketNoteAdded(m.note)) - } + log(events.NewTicketOpened(ticket, m.note)) contact.SetTicket(ticket) return true diff --git a/test/testdata/runner/ticketing.test.json b/test/testdata/runner/ticketing.test.json index a53baff64..d28ba9008 100644 --- a/test/testdata/runner/ticketing.test.json +++ b/test/testdata/runner/ticketing.test.json @@ -161,6 +161,7 @@ }, { "created_on": "2018-07-06T12:30:18.123456789Z", + "note": "Last message: Rats", "step_uuid": "970b8069-50f5-4f6f-8f41-6b2d9f33d623", "ticket": { "topic": { @@ -171,15 +172,9 @@ }, "type": "ticket_opened" }, - { - "created_on": "2018-07-06T12:30:20.123456789Z", - "note": "Last message: Rats", - "step_uuid": "970b8069-50f5-4f6f-8f41-6b2d9f33d623", - "type": "ticket_note_added" - }, { "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", @@ -187,7 +182,7 @@ }, { "body": "[{\"assignee\":null,\"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": [ @@ -211,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": { @@ -297,6 +292,7 @@ }, { "created_on": "2018-07-06T12:30:18.123456789Z", + "note": "Last message: Rats", "step_uuid": "970b8069-50f5-4f6f-8f41-6b2d9f33d623", "ticket": { "topic": { @@ -307,15 +303,9 @@ }, "type": "ticket_opened" }, - { - "created_on": "2018-07-06T12:30:20.123456789Z", - "note": "Last message: Rats", - "step_uuid": "970b8069-50f5-4f6f-8f41-6b2d9f33d623", - "type": "ticket_note_added" - }, { "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", @@ -323,7 +313,7 @@ }, { "body": "[{\"assignee\":null,\"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": [ @@ -332,12 +322,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", @@ -358,7 +348,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" @@ -375,7 +365,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"