Skip to content

Commit

Permalink
Replace ticket body with initial note
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Aug 6, 2024
1 parent 8c99100 commit 2c6b97b
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 99 deletions.
2 changes: 1 addition & 1 deletion flows/actions/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "Help"))
}

// and switch their language
Expand Down
8 changes: 4 additions & 4 deletions flows/actions/open_ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ 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)

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 {
Expand All @@ -79,7 +79,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
Expand All @@ -90,7 +90,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
Expand Down
26 changes: 13 additions & 13 deletions flows/actions/testdata/open_ticket.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"name": "Weather"
},
"body": "Last message: Hi everybody",
"assignee": {
"email": "[email protected]",
"name": "Bob"
}
},
"note": "Last message: Hi everybody"
}
},
{
Expand Down Expand Up @@ -180,11 +180,11 @@
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"name": "Weather"
},
"body": "Last message: Hi everybody",
"assignee": {
"email": "[email protected]",
"name": "Bob"
}
},
"note": "Last message: Hi everybody"
}
},
"templates": [
Expand Down Expand Up @@ -230,7 +230,7 @@
"uuid": "0d9a2c56-6fc2-4f27-93c5-a6322e26b740",
"name": "General"
},
"body": "Last message: Hi everybody"
"note": "Last message: Hi everybody"
}
},
{
Expand Down Expand Up @@ -290,7 +290,7 @@
"uuid": "0d9a2c56-6fc2-4f27-93c5-a6322e26b740",
"name": "General"
},
"body": "Last message: Hi everybody"
"note": "Last message: Hi everybody"
}
},
"templates": [
Expand Down Expand Up @@ -330,11 +330,11 @@
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"name": "Weather"
},
"body": "Last message: Hi everybody",
"assignee": {
"email": "[email protected]",
"name": "Jim"
}
},
"note": "Last message: Hi everybody"
}
},
{
Expand Down Expand Up @@ -394,11 +394,11 @@
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"name": "Weather"
},
"body": "Last message: Hi everybody",
"assignee": {
"email": "[email protected]",
"name": "Jim"
}
},
"note": "Last message: Hi everybody"
}
},
"templates": [
Expand Down Expand Up @@ -451,7 +451,7 @@
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"name": "Weather"
},
"body": "Last message: Hi everybody"
"note": "Last message: Hi everybody"
}
},
{
Expand Down Expand Up @@ -511,7 +511,7 @@
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"name": "Weather"
},
"body": "Last message: Hi everybody"
"note": "Last message: Hi everybody"
}
},
"templates": [
Expand Down Expand Up @@ -559,7 +559,7 @@
"uuid": "0d9a2c56-6fc2-4f27-93c5-a6322e26b740",
"name": "General"
},
"body": "Where are my cookies? "
"note": "Where are my cookies? "
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion flows/contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "spam?")
contact.SetTicket(ticket)

assert.NotNil(t, contact.Ticket())
Expand Down
9 changes: 3 additions & 6 deletions flows/engine/testdata/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,15 @@
},
{
"template": "@(json(contact.tickets))",
"output": "[{\"assignee\":{\"email\":\"[email protected]\",\"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\":\"[email protected]\",\"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\":\"[email protected]\",\"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\":\"[email protected]\",\"first_name\":\"Bob\",\"name\":\"Bob\"},\"topic\":{\"name\":\"Weather\",\"uuid\":\"472a7a73-96cb-4736-b567-056d987cc5b4\"},\"uuid\":\"78d1fe0d-7e39-461e-81c3-a6a25f15ed69\"}"
},
{
"template": "@(json(contact))",
Expand Down Expand Up @@ -449,7 +449,6 @@
"first_name": "Bob",
"name": "Bob"
},
"body": "What day is it?",
"topic": {
"name": "Weather",
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4"
Expand Down Expand Up @@ -529,7 +528,6 @@
"first_name": "Bob",
"name": "Bob"
},
"body": "What day is it?",
"topic": {
"name": "Weather",
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4"
Expand Down Expand Up @@ -750,7 +748,6 @@
"first_name": "Bob",
"name": "Bob"
},
"body": "What day is it?",
"topic": {
"name": "Weather",
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4"
Expand Down
17 changes: 8 additions & 9 deletions flows/events/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestEventMarshaling(t *testing.T) {
weather := session.Assets().Topics().Get("472a7a73-96cb-4736-b567-056d987cc5b4")
user := session.Assets().Users().Get("[email protected]")
facebook := session.Assets().Channels().Get("4bb288a0-7fca-4da1-abe8-59a593aff648")
ticket := flows.NewTicket("7481888c-07dd-47dc-bf22-ef7448696ffe", weather, "Where are my cookies?", user)
ticket := flows.NewTicket("7481888c-07dd-47dc-bf22-ef7448696ffe", weather, user, "this is weird")

eventTests := []struct {
event flows.Event
Expand Down Expand Up @@ -309,16 +309,15 @@ func TestEventMarshaling(t *testing.T) {
"name": "Ryan Lewis",
"status": "active",
"ticket": {
"assignee": {
"email": "[email protected]",
"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": "[email protected]",
"name": "Bob"
}
},
"timezone": "America/Guayaquil",
"urns": [
Expand Down Expand Up @@ -622,11 +621,11 @@ func TestEventMarshaling(t *testing.T) {
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"name": "Weather"
},
"body": "Where are my cookies?",
"assignee": {
"email": "[email protected]",
"name": "Bob"
}
},
"note": "this is weird"
}
}`,
},
Expand Down
8 changes: 4 additions & 4 deletions flows/events/ticket_opened.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ 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"`
Note string `json:"note,omitempty"`
}

// TicketOpenedEvent events are created when a new ticket is opened.
Expand All @@ -30,8 +30,8 @@ type Ticket struct {
// "uuid": "add17edf-0b6e-4311-bcd7-a64b2a459157",
// "name": "Weather"
// },
// "body": "Where are my cookies?",
// "assignee": {"email": "[email protected]", "name": "Bob"}
// "assignee": {"email": "[email protected]", "name": "Bob"},
// "note": "this is weird"
// }
// }
//
Expand All @@ -49,8 +49,8 @@ func NewTicketOpened(ticket *flows.Ticket) *TicketOpenedEvent {
Ticket: &Ticket{
UUID: ticket.UUID(),
Topic: ticket.Topic().Reference(),
Body: ticket.Body(),
Assignee: ticket.Assignee().Reference(),
Note: ticket.Note(),
},
}
}
4 changes: 2 additions & 2 deletions flows/inspect/issues/testdata/legacy_vars.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 10 additions & 9 deletions flows/modifiers/testdata/ticket.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
"uuid": "daa356b6-32af-44f0-9d35-6126d55ec3e9",
"name": "Computers"
},
"body": "Where are my keys?",
"assignee": {
"email": "[email protected]",
"name": "Bob"
}
},
"note": "Where are my keys?",
"body": "Where are my keys?"
},
"contact_after": {
"uuid": "5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f",
Expand All @@ -31,11 +32,11 @@
"uuid": "daa356b6-32af-44f0-9d35-6126d55ec3e9",
"name": "Computers"
},
"body": "Where are my keys?",
"assignee": {
"email": "[email protected]",
"name": "Bob"
}
},
"note": "Where are my keys?"
}
},
"events": [
Expand All @@ -48,11 +49,11 @@
"uuid": "daa356b6-32af-44f0-9d35-6126d55ec3e9",
"name": "Computers"
},
"body": "Where are my keys?",
"assignee": {
"email": "[email protected]",
"name": "Bob"
}
},
"note": "Where are my keys?"
}
}
]
Expand Down Expand Up @@ -84,8 +85,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",
Expand All @@ -98,7 +100,6 @@
"uuid": "daa356b6-32af-44f0-9d35-6126d55ec3e9",
"name": "Computers"
},
"body": "Where are my keys?",
"assignee": {
"email": "[email protected]",
"name": "Bob"
Expand Down
Loading

0 comments on commit 2c6b97b

Please sign in to comment.