diff --git a/flows/actions/base_test.go b/flows/actions/base_test.go index c3dfcd662..14d777a4b 100644 --- a/flows/actions/base_test.go +++ b/flows/actions/base_test.go @@ -172,7 +172,7 @@ func testActionType(t *testing.T, assetsJSON json.RawMessage, typeName string) { if tc.HasTicket { topic := sa.Topics().Get("0d9a2c56-6fc2-4f27-93c5-a6322e26b740") - contact.SetTicket(flows.NewTicket("7f44b065-ec28-4d7a-bbb4-0bda3b75b19d", topic, "Help", nil)) + contact.SetTicket(flows.NewTicket("7f44b065-ec28-4d7a-bbb4-0bda3b75b19d", topic, nil)) } // and switch their language diff --git a/flows/actions/open_ticket.go b/flows/actions/open_ticket.go index da1a84bb4..ecba7289d 100644 --- a/flows/actions/open_ticket.go +++ b/flows/actions/open_ticket.go @@ -1,6 +1,8 @@ package actions import ( + "strings" + "github.com/nyaruka/goflow/assets" "github.com/nyaruka/goflow/flows" "github.com/nyaruka/goflow/flows/events" @@ -34,7 +36,7 @@ type OpenTicketAction struct { onlineAction Topic *assets.TopicReference `json:"topic" validate:"omitempty"` - Body string `json:"body" engine:"evaluated"` + Body string `json:"body" engine:"evaluated"` // TODO will become "note" in future migration Assignee *assets.UserReference `json:"assignee" validate:"omitempty"` ResultName string `json:"result_name" validate:"required"` } @@ -67,9 +69,10 @@ func (a *OpenTicketAction) Execute(run flows.Run, step flows.Step, logModifier f assignee = resolveUser(run, a.Assignee, logEvent) } - evaluatedBody, _ := run.EvaluateTemplate(a.Body, logEvent) + evaluatedNote, _ := run.EvaluateTemplate(a.Body, logEvent) + evaluatedNote = strings.TrimSpace(evaluatedNote) - ticket := a.open(run, topic, evaluatedBody, assignee, logModifier, logEvent) + ticket := a.open(run, topic, assignee, evaluatedNote, logModifier, logEvent) if ticket != nil { a.saveResult(run, step, a.ResultName, string(ticket.UUID()), CategorySuccess, "", "", nil, logEvent) } else { @@ -79,7 +82,7 @@ func (a *OpenTicketAction) Execute(run flows.Run, step flows.Step, logModifier f return nil } -func (a *OpenTicketAction) open(run flows.Run, topic *flows.Topic, body string, assignee *flows.User, logModifier flows.ModifierCallback, logEvent flows.EventCallback) *flows.Ticket { +func (a *OpenTicketAction) open(run flows.Run, topic *flows.Topic, assignee *flows.User, note string, logModifier flows.ModifierCallback, logEvent flows.EventCallback) *flows.Ticket { if run.Session().BatchStart() { logEvent(events.NewErrorf("can't open tickets during batch starts")) return nil @@ -90,7 +93,7 @@ func (a *OpenTicketAction) open(run flows.Run, topic *flows.Topic, body string, return nil } - mod := modifiers.NewTicket(topic, body, assignee) + mod := modifiers.NewTicket(topic, assignee, note) if a.applyModifier(run, mod, logModifier, logEvent) { // if we were able to open a ticket, return it diff --git a/flows/actions/testdata/open_ticket.json b/flows/actions/testdata/open_ticket.json index ff9f06f5b..e6d44153c 100644 --- a/flows/actions/testdata/open_ticket.json +++ b/flows/actions/testdata/open_ticket.json @@ -116,13 +116,18 @@ "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" }, - "body": "Last message: Hi everybody", "assignee": { "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" + }, { "type": "contact_groups_changed", "created_on": "2018-10-18T14:20:30.000123456Z", @@ -180,7 +185,6 @@ "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" }, - "body": "Last message: Hi everybody", "assignee": { "email": "bob@nyaruka.com", "name": "Bob" @@ -229,10 +233,15 @@ "topic": { "uuid": "0d9a2c56-6fc2-4f27-93c5-a6322e26b740", "name": "General" - }, - "body": "Last message: Hi everybody" + } } }, + { + "type": "ticket_note_added", + "created_on": "2018-10-18T14:20:30.000123456Z", + "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", + "note": "Last message: Hi everybody" + }, { "type": "contact_groups_changed", "created_on": "2018-10-18T14:20:30.000123456Z", @@ -289,8 +298,7 @@ "topic": { "uuid": "0d9a2c56-6fc2-4f27-93c5-a6322e26b740", "name": "General" - }, - "body": "Last message: Hi everybody" + } } }, "templates": [ @@ -330,13 +338,18 @@ "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" }, - "body": "Last message: Hi everybody", "assignee": { "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" + }, { "type": "contact_groups_changed", "created_on": "2018-10-18T14:20:30.000123456Z", @@ -394,7 +407,6 @@ "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" }, - "body": "Last message: Hi everybody", "assignee": { "email": "jim@nyaruka.com", "name": "Jim" @@ -450,10 +462,15 @@ "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" - }, - "body": "Last message: Hi everybody" + } } }, + { + "type": "ticket_note_added", + "created_on": "2018-10-18T14:20:30.000123456Z", + "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", + "note": "Last message: Hi everybody" + }, { "type": "contact_groups_changed", "created_on": "2018-10-18T14:20:30.000123456Z", @@ -510,8 +527,7 @@ "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" - }, - "body": "Last message: Hi everybody" + } } }, "templates": [ @@ -533,12 +549,12 @@ } }, { - "description": "Error events if subject or body contain expression errors", + "description": "Error events if note contains expression errors", "action": { "type": "open_ticket", "uuid": "ad154980-7bf7-4ab8-8728-545fd6378912", "topic": null, - "body": "Where are my cookies? @(1/ 0)", + "body": "@(1/ 0)", "assignee": null, "result_name": "Ticket" }, @@ -558,8 +574,7 @@ "topic": { "uuid": "0d9a2c56-6fc2-4f27-93c5-a6322e26b740", "name": "General" - }, - "body": "Where are my cookies? " + } } }, { @@ -583,7 +598,7 @@ } ], "templates": [ - "Where are my cookies? @(1/ 0)" + "@(1/ 0)" ], "inspection": { "dependencies": [], diff --git a/flows/contact_test.go b/flows/contact_test.go index ba7aa0ea6..39d0ed81a 100644 --- a/flows/contact_test.go +++ b/flows/contact_test.go @@ -139,7 +139,7 @@ func TestContact(t *testing.T) { assert.Nil(t, contact.Ticket()) weather := sa.Topics().Get("472a7a73-96cb-4736-b567-056d987cc5b4") - ticket := flows.OpenTicket(weather, "I have issues", nil) + ticket := flows.OpenTicket(weather, nil) contact.SetTicket(ticket) assert.NotNil(t, contact.Ticket()) diff --git a/flows/engine/testdata/templates.json b/flows/engine/testdata/templates.json index 597a5c91f..e55d73d54 100644 --- a/flows/engine/testdata/templates.json +++ b/flows/engine/testdata/templates.json @@ -398,15 +398,15 @@ }, { "template": "@(json(contact.tickets))", - "output": "[{\"assignee\":{\"email\":\"bob@nyaruka.com\",\"first_name\":\"Bob\",\"name\":\"Bob\"},\"body\":\"What day is it?\",\"topic\":{\"name\":\"Weather\",\"uuid\":\"472a7a73-96cb-4736-b567-056d987cc5b4\"},\"uuid\":\"78d1fe0d-7e39-461e-81c3-a6a25f15ed69\"}]" + "output": "[{\"assignee\":{\"email\":\"bob@nyaruka.com\",\"first_name\":\"Bob\",\"name\":\"Bob\"},\"topic\":{\"name\":\"Weather\",\"uuid\":\"472a7a73-96cb-4736-b567-056d987cc5b4\"},\"uuid\":\"78d1fe0d-7e39-461e-81c3-a6a25f15ed69\"}]" }, { "template": "@ticket", - "output": "{assignee: Bob, body: What day is it?, topic: Weather, uuid: 78d1fe0d-7e39-461e-81c3-a6a25f15ed69}" + "output": "{assignee: Bob, topic: Weather, uuid: 78d1fe0d-7e39-461e-81c3-a6a25f15ed69}" }, { "template": "@(json(ticket))", - "output": "{\"assignee\":{\"email\":\"bob@nyaruka.com\",\"first_name\":\"Bob\",\"name\":\"Bob\"},\"body\":\"What day is it?\",\"topic\":{\"name\":\"Weather\",\"uuid\":\"472a7a73-96cb-4736-b567-056d987cc5b4\"},\"uuid\":\"78d1fe0d-7e39-461e-81c3-a6a25f15ed69\"}" + "output": "{\"assignee\":{\"email\":\"bob@nyaruka.com\",\"first_name\":\"Bob\",\"name\":\"Bob\"},\"topic\":{\"name\":\"Weather\",\"uuid\":\"472a7a73-96cb-4736-b567-056d987cc5b4\"},\"uuid\":\"78d1fe0d-7e39-461e-81c3-a6a25f15ed69\"}" }, { "template": "@(json(contact))", @@ -449,7 +449,6 @@ "first_name": "Bob", "name": "Bob" }, - "body": "What day is it?", "topic": { "name": "Weather", "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4" @@ -529,7 +528,6 @@ "first_name": "Bob", "name": "Bob" }, - "body": "What day is it?", "topic": { "name": "Weather", "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4" @@ -750,7 +748,6 @@ "first_name": "Bob", "name": "Bob" }, - "body": "What day is it?", "topic": { "name": "Weather", "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4" diff --git a/flows/events/base_test.go b/flows/events/base_test.go index cf83fcc5b..1f2d3d44c 100644 --- a/flows/events/base_test.go +++ b/flows/events/base_test.go @@ -48,7 +48,7 @@ func TestEventMarshaling(t *testing.T) { 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", weather, "Where are my cookies?", user) + ticket := flows.NewTicket("7481888c-07dd-47dc-bf22-ef7448696ffe", weather, user) eventTests := []struct { event flows.Event @@ -309,16 +309,15 @@ func TestEventMarshaling(t *testing.T) { "name": "Ryan Lewis", "status": "active", "ticket": { - "assignee": { - "email": "bob@nyaruka.com", - "name": "Bob" - }, - "body": "What day is it?", + "uuid": "78d1fe0d-7e39-461e-81c3-a6a25f15ed69", "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" }, - "uuid": "78d1fe0d-7e39-461e-81c3-a6a25f15ed69" + "assignee": { + "email": "bob@nyaruka.com", + "name": "Bob" + } }, "timezone": "America/Guayaquil", "urns": [ @@ -611,6 +610,14 @@ 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), `{ @@ -622,7 +629,6 @@ func TestEventMarshaling(t *testing.T) { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" }, - "body": "Where are my cookies?", "assignee": { "email": "bob@nyaruka.com", "name": "Bob" diff --git a/flows/events/ticket_note_added.go b/flows/events/ticket_note_added.go new file mode 100644 index 000000000..7dad5eceb --- /dev/null +++ b/flows/events/ticket_note_added.go @@ -0,0 +1,35 @@ +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 03d08be22..3e87ebd34 100644 --- a/flows/events/ticket_opened.go +++ b/flows/events/ticket_opened.go @@ -15,7 +15,6 @@ const TypeTicketOpened string = "ticket_opened" type Ticket struct { 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"` } @@ -30,7 +29,6 @@ type Ticket struct { // "uuid": "add17edf-0b6e-4311-bcd7-a64b2a459157", // "name": "Weather" // }, -// "body": "Where are my cookies?", // "assignee": {"email": "bob@nyaruka.com", "name": "Bob"} // } // } @@ -49,7 +47,6 @@ func NewTicketOpened(ticket *flows.Ticket) *TicketOpenedEvent { Ticket: &Ticket{ UUID: ticket.UUID(), Topic: ticket.Topic().Reference(), - Body: ticket.Body(), Assignee: ticket.Assignee().Reference(), }, } diff --git a/flows/inspect/issues/testdata/legacy_vars.json b/flows/inspect/issues/testdata/legacy_vars.json index 71b8701e5..18001d760 100644 --- a/flows/inspect/issues/testdata/legacy_vars.json +++ b/flows/inspect/issues/testdata/legacy_vars.json @@ -35,10 +35,10 @@ }, "issues": [ { + "type": "legacy_vars", + "node_uuid": "a58be63b-907d-4a1a-856b-0bb5579d7507", "action_uuid": "8eebd020-1af5-431c-b943-aa670fc74da9", "description": "use of expressions instead of contact query", - "node_uuid": "a58be63b-907d-4a1a-856b-0bb5579d7507", - "type": "legacy_vars", "vars": [ "@contact.uuid", "@fields.friend_tel" diff --git a/flows/modifiers/testdata/ticket.json b/flows/modifiers/testdata/ticket.json index 3afca058a..89a4916b8 100644 --- a/flows/modifiers/testdata/ticket.json +++ b/flows/modifiers/testdata/ticket.json @@ -14,11 +14,12 @@ "uuid": "daa356b6-32af-44f0-9d35-6126d55ec3e9", "name": "Computers" }, - "body": "Where are my keys?", "assignee": { "email": "bob@nyaruka.com", "name": "Bob" - } + }, + "note": "this is a note", + "body": "this is a note" }, "contact_after": { "uuid": "5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f", @@ -31,7 +32,6 @@ "uuid": "daa356b6-32af-44f0-9d35-6126d55ec3e9", "name": "Computers" }, - "body": "Where are my keys?", "assignee": { "email": "bob@nyaruka.com", "name": "Bob" @@ -48,12 +48,16 @@ "uuid": "daa356b6-32af-44f0-9d35-6126d55ec3e9", "name": "Computers" }, - "body": "Where are my keys?", "assignee": { "email": "bob@nyaruka.com", "name": "Bob" } } + }, + { + "type": "ticket_note_added", + "created_on": "2018-10-18T14:20:30.000123456Z", + "note": "this is a note" } ] }, @@ -71,7 +75,7 @@ "uuid": "daa356b6-32af-44f0-9d35-6126d55ec3e9", "name": "Computers" }, - "body": "Where are my keys?", + "body": "this is a note", "assignee": { "email": "bob@nyaruka.com", "name": "Bob" @@ -84,8 +88,9 @@ "uuid": "daa356b6-32af-44f0-9d35-6126d55ec3e9", "name": "Computers" }, - "body": "Should fail", - "assignee": null + "assignee": null, + "note": "Should fail", + "body": "Should fail" }, "contact_after": { "uuid": "5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f", @@ -98,7 +103,6 @@ "uuid": "daa356b6-32af-44f0-9d35-6126d55ec3e9", "name": "Computers" }, - "body": "Where are my keys?", "assignee": { "email": "bob@nyaruka.com", "name": "Bob" diff --git a/flows/modifiers/ticket.go b/flows/modifiers/ticket.go index 64eded65e..be8aa5da0 100644 --- a/flows/modifiers/ticket.go +++ b/flows/modifiers/ticket.go @@ -23,17 +23,17 @@ type TicketModifier struct { baseModifier topic *flows.Topic - body string assignee *flows.User + note string } // NewTicket creates a new ticket modifier -func NewTicket(topic *flows.Topic, body string, assignee *flows.User) *TicketModifier { +func NewTicket(topic *flows.Topic, assignee *flows.User, note string) *TicketModifier { return &TicketModifier{ baseModifier: newBaseModifier(TypeTicket), topic: topic, - body: body, assignee: assignee, + note: note, } } @@ -44,8 +44,11 @@ func (m *TicketModifier) Apply(eng flows.Engine, env envs.Environment, sa flows. return false } - ticket := flows.OpenTicket(m.topic, m.body, m.assignee) + ticket := flows.OpenTicket(m.topic, m.assignee) log(events.NewTicketOpened(ticket)) + if m.note != "" { + log(events.NewTicketNoteAdded(m.note)) + } contact.SetTicket(ticket) return true @@ -61,8 +64,10 @@ type ticketModifierEnvelope struct { utils.TypedEnvelope Topic *assets.TopicReference `json:"topic" validate:"required"` - Body string `json:"body"` Assignee *assets.UserReference `json:"assignee"` + Note string `json:"note"` + + Body string `json:"body"` // deprecated } func readTicketModifier(assets flows.SessionAssets, data json.RawMessage, missing assets.MissingCallback) (flows.Modifier, error) { @@ -71,6 +76,10 @@ func readTicketModifier(assets flows.SessionAssets, data json.RawMessage, missin return nil, err } + if e.Note == "" && e.Body != "" { + e.Note = e.Body + } + topic := assets.Topics().Get(e.Topic.UUID) if topic == nil { missing(e.Topic, nil) @@ -85,14 +94,15 @@ func readTicketModifier(assets flows.SessionAssets, data json.RawMessage, missin } } - return NewTicket(topic, e.Body, assignee), nil + return NewTicket(topic, assignee, e.Note), nil } func (m *TicketModifier) MarshalJSON() ([]byte, error) { return jsonx.Marshal(&ticketModifierEnvelope{ TypedEnvelope: utils.TypedEnvelope{Type: m.Type()}, Topic: m.topic.Reference(), - Body: m.body, Assignee: m.assignee.Reference(), + Note: m.note, + Body: m.note, }) } diff --git a/flows/tickets.go b/flows/tickets.go index 6d2eb4054..ba6ee8af2 100644 --- a/flows/tickets.go +++ b/flows/tickets.go @@ -16,42 +16,38 @@ type TicketUUID uuids.UUID type Ticket struct { uuid TicketUUID topic *Topic - body string assignee *User } // NewTicket creates a new ticket -func NewTicket(uuid TicketUUID, topic *Topic, body string, assignee *User) *Ticket { +func NewTicket(uuid TicketUUID, topic *Topic, assignee *User) *Ticket { return &Ticket{ uuid: uuid, topic: topic, - body: body, assignee: assignee, } } // OpenTicket creates a new ticket. Used by ticketing services to open a new ticket. -func OpenTicket(topic *Topic, body string, assignee *User) *Ticket { - return NewTicket(TicketUUID(uuids.NewV4()), topic, body, assignee) +func OpenTicket(topic *Topic, assignee *User) *Ticket { + return NewTicket(TicketUUID(uuids.NewV4()), topic, 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 // // uuid:text -> the UUID of the ticket -// subject:text -> the subject of the ticket -// body:text -> the body of the ticket +// topic:any -> the topic of the ticket +// assignee:any -> the assignee of the ticket // // @context ticket func (t *Ticket) Context(env envs.Environment) map[string]types.XValue { return map[string]types.XValue{ "uuid": types.NewXText(string(t.uuid)), "topic": Context(env, t.topic), - "body": types.NewXText(t.body), "assignee": Context(env, t.assignee), } } @@ -63,7 +59,6 @@ func (t *Ticket) Context(env envs.Environment) map[string]types.XValue { type ticketEnvelope struct { 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"` } @@ -92,12 +87,7 @@ func ReadTicket(sa SessionAssets, data []byte, missing assets.MissingCallback) ( } } - return &Ticket{ - uuid: e.UUID, - topic: topic, - body: e.Body, - assignee: assignee, - }, nil + return &Ticket{uuid: e.UUID, topic: topic, assignee: assignee}, nil } // MarshalJSON marshals this ticket into JSON @@ -115,7 +105,6 @@ func (t *Ticket) MarshalJSON() ([]byte, error) { return jsonx.Marshal(&ticketEnvelope{ UUID: t.uuid, Topic: topicRef, - Body: t.body, Assignee: assigneeRef, }) } diff --git a/flows/tickets_test.go b/flows/tickets_test.go index 37aea83e8..26072fd6b 100644 --- a/flows/tickets_test.go +++ b/flows/tickets_test.go @@ -68,15 +68,12 @@ func TestTickets(t *testing.T) { ticket1, err := flows.ReadTicket(sa, []byte(`{ "uuid": "349c851f-3f8e-4353-8bf2-8e90b6d73530", "topic": {"uuid": "fd3ffcf3-c609-423e-b40f-f7f291a91cc6", "name": "Deleted"}, - "subject": "Very Old Ticket", - "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.Topic()) - assert.Equal(t, "Topic and assignee gone!", ticket1.Body()) assert.Nil(t, ticket1.Assignee()) // check that missing topic and assignee are logged as a missing dependencies @@ -89,8 +86,6 @@ func TestTickets(t *testing.T) { ticket2, err := flows.ReadTicket(sa, []byte(`{ "uuid": "5a4af021-d2c2-47fc-9abc-abbb8635d8c0", "topic": {"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather"}, - "subject": "Old Ticket", - "body": "Where are my shoes?", "assignee": {"email": "bob@nyaruka.com", "name": "Bob"} }`), missing) require.NoError(t, err) @@ -98,10 +93,9 @@ func TestTickets(t *testing.T) { assert.Equal(t, 0, len(missingRefs)) assert.Equal(t, "Bob", ticket2.Assignee().Name()) - ticket3 := flows.OpenTicket(weather, "Where are my pants?", bob) + ticket3 := flows.OpenTicket(weather, bob) assert.Equal(t, flows.TicketUUID("1ae96956-4b34-433e-8d1a-f05fe6923d6d"), ticket3.UUID()) assert.Equal(t, weather, ticket3.Topic()) - assert.Equal(t, "Where are my pants?", ticket3.Body()) assert.Equal(t, "Bob", ticket2.Assignee().Name()) } diff --git a/flows/triggers/base_test.go b/flows/triggers/base_test.go index ddecb704b..a5ba4daad 100644 --- a/flows/triggers/base_test.go +++ b/flows/triggers/base_test.go @@ -184,7 +184,7 @@ func TestTriggerMarshaling(t *testing.T) { jotd := sa.OptIns().Get("248be71d-78e9-4d71-a6c4-9981d369e5cb") weather := sa.Topics().Get("472a7a73-96cb-4736-b567-056d987cc5b4") user := sa.Users().Get("bob@nyaruka.com") - ticket := flows.NewTicket("276c2e43-d6f9-4c36-8e54-b5af5039acf6", weather, "Where are my shoes?", user) + ticket := flows.NewTicket("276c2e43-d6f9-4c36-8e54-b5af5039acf6", weather, 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 112a6e5a7..c5d1fa818 100644 --- a/flows/triggers/testdata/TestTriggerMarshaling_ticket_closed.snap +++ b/flows/triggers/testdata/TestTriggerMarshaling_ticket_closed.snap @@ -31,7 +31,6 @@ "ticket": { "uuid": "276c2e43-d6f9-4c36-8e54-b5af5039acf6", "topic": null, - "body": "Where are my shoes?", "assignee": { "email": "bob@nyaruka.com", "name": "Bob McTickets" diff --git a/flows/triggers/testdata/optin.json b/flows/triggers/testdata/optin.json index 6abcdd4c0..1928b0e06 100644 --- a/flows/triggers/testdata/optin.json +++ b/flows/triggers/testdata/optin.json @@ -46,22 +46,22 @@ "status": "active", "created_on": "2018-01-01T12:00:00Z" }, + "triggered_on": "2000-01-01T00:00:00Z", "event": { "type": "started", "optin": { "uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb", "name": "Joke Of The Day" } - }, - "triggered_on": "2000-01-01T00:00:00Z" + } }, "events": [], "context": { "campaign": null, "keyword": "", "optin": { - "uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb", - "name": "Joke Of The Day" + "name": "Joke Of The Day", + "uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb" }, "origin": "", "params": {}, diff --git a/flows/triggers/testdata/ticket.json b/flows/triggers/testdata/ticket.json index f2f4af366..e56fcc98b 100644 --- a/flows/triggers/testdata/ticket.json +++ b/flows/triggers/testdata/ticket.json @@ -39,8 +39,7 @@ "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" - }, - "body": "Where are my shoes?" + } } } }, @@ -53,7 +52,6 @@ "params": {}, "ticket": { "assignee": null, - "body": "Where are my shoes?", "topic": { "name": "Weather", "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4" diff --git a/test/session.go b/test/session.go index ec9ef04f1..70f1c1ef8 100644 --- a/test/session.go +++ b/test/session.go @@ -327,8 +327,6 @@ var sessionTrigger = `{ }, "ticket": { "uuid": "78d1fe0d-7e39-461e-81c3-a6a25f15ed69", - "subject": "Question", - "body": "What day is it?", "topic": { "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4", "name": "Weather" diff --git a/test/testdata/runner/ticketing.test.json b/test/testdata/runner/ticketing.test.json index fd846e557..a53baff64 100644 --- a/test/testdata/runner/ticketing.test.json +++ b/test/testdata/runner/ticketing.test.json @@ -163,7 +163,6 @@ "created_on": "2018-07-06T12:30:18.123456789Z", "step_uuid": "970b8069-50f5-4f6f-8f41-6b2d9f33d623", "ticket": { - "body": "Last message: Rats", "topic": { "name": "Weather", "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4" @@ -172,17 +171,23 @@ }, "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:22.123456789Z", + "created_on": "2018-07-06T12:30:24.123456789Z", "name": "Ticket", "step_uuid": "970b8069-50f5-4f6f-8f41-6b2d9f33d623", "type": "run_result_changed", "value": "5ecda5fc-951c-437b-a17e-f85e49829fb9" }, { - "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:26.123456789Z", + "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", "step_uuid": "312d3af0-a565-4c96-ba00-bd7f0d08e671", "subject": "New ticket: 5ecda5fc-951c-437b-a17e-f85e49829fb9", "to": [ @@ -206,7 +211,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:24.123456789Z" + "time": "2018-07-06T12:30:26.123456789Z" } ], "session": { @@ -218,7 +223,6 @@ "name": "Ben Haggerty", "status": "active", "ticket": { - "body": "Last message: Rats", "topic": { "name": "Weather", "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4" @@ -295,7 +299,6 @@ "created_on": "2018-07-06T12:30:18.123456789Z", "step_uuid": "970b8069-50f5-4f6f-8f41-6b2d9f33d623", "ticket": { - "body": "Last message: Rats", "topic": { "name": "Weather", "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4" @@ -304,17 +307,23 @@ }, "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:22.123456789Z", + "created_on": "2018-07-06T12:30:24.123456789Z", "name": "Ticket", "step_uuid": "970b8069-50f5-4f6f-8f41-6b2d9f33d623", "type": "run_result_changed", "value": "5ecda5fc-951c-437b-a17e-f85e49829fb9" }, { - "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:26.123456789Z", + "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", "step_uuid": "312d3af0-a565-4c96-ba00-bd7f0d08e671", "subject": "New ticket: 5ecda5fc-951c-437b-a17e-f85e49829fb9", "to": [ @@ -323,12 +332,12 @@ "type": "email_sent" } ], - "exited_on": "2018-07-06T12:30:28.123456789Z", + "exited_on": "2018-07-06T12:30:30.123456789Z", "flow": { "name": "Support", "uuid": "3486fc59-d417-4189-93cd-e0aa8e3112ac" }, - "modified_on": "2018-07-06T12:30:28.123456789Z", + "modified_on": "2018-07-06T12:30:30.123456789Z", "path": [ { "arrived_on": "2018-07-06T12:30:01.123456789Z", @@ -349,7 +358,7 @@ "uuid": "970b8069-50f5-4f6f-8f41-6b2d9f33d623" }, { - "arrived_on": "2018-07-06T12:30:25.123456789Z", + "arrived_on": "2018-07-06T12:30:27.123456789Z", "exit_uuid": "b6562dea-d21c-4a99-b904-0fb9583fb5ab", "node_uuid": "ac3fcd8e-e7bb-4545-865d-39424a8f1d7b", "uuid": "312d3af0-a565-4c96-ba00-bd7f0d08e671" @@ -366,7 +375,7 @@ }, "ticket": { "category": "Success", - "created_on": "2018-07-06T12:30:20.123456789Z", + "created_on": "2018-07-06T12:30:22.123456789Z", "name": "Ticket", "node_uuid": "145eb3d3-b841-4e66-abac-297ae525c7ad", "value": "5ecda5fc-951c-437b-a17e-f85e49829fb9"