Skip to content

Commit

Permalink
Merge branch 'add-topic-queue_uuid' of https://github.com/weni-ai/goflow
Browse files Browse the repository at this point in the history
 into merge/wpp-broadcasts-queue-uuid
  • Loading branch information
paulobernardoaf committed Nov 19, 2024
2 parents 5ef6995 + f3ea7a6 commit e3ba062
Show file tree
Hide file tree
Showing 21 changed files with 87 additions and 29 deletions.
4 changes: 2 additions & 2 deletions assets/references_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func TestReferences(t *testing.T) {
// 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")
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())
assert.Equal(t, uuids.UUID("61602f3e-f603-4c70-8a8f-c477505bf4bf"), topicRef.GenericUUID())
Expand All @@ -136,7 +136,7 @@ func TestReferences(t *testing.T) {
assert.NoError(t, utils.Validate(topicRef))

// topic references must always be concrete
assert.EqualError(t, utils.Validate(assets.NewTopicReference("", "Weather")), "field 'uuid' is required")
assert.EqualError(t, utils.Validate(assets.NewTopicReference("", "Weather", "")), "field 'uuid' is required")

userRef := assets.NewUserReference("[email protected]", "Bob")
assert.Equal(t, "user", userRef.Type())
Expand Down
15 changes: 10 additions & 5 deletions assets/static/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import (

// Topic is a JSON serializable implementation of a topic asset
type Topic struct {
UUID_ assets.TopicUUID `json:"uuid" validate:"required,uuid"`
Name_ string `json:"name"`
UUID_ assets.TopicUUID `json:"uuid" validate:"required,uuid"`
Name_ string `json:"name"`
QueueUUID_ assets.QueueUUID `json:"queue_uuid"`
}

// NewTopic creates a new topic
func NewTopic(uuid assets.TopicUUID, name string) assets.Topic {
func NewTopic(uuid assets.TopicUUID, name string, queueUUID assets.QueueUUID) assets.Topic {
return &Topic{
UUID_: uuid,
Name_: name,
UUID_: uuid,
Name_: name,
QueueUUID_: queueUUID,
}
}

Expand All @@ -23,3 +25,6 @@ func (t *Topic) UUID() assets.TopicUUID { return t.UUID_ }

// Name returns the name of this ticketer
func (t *Topic) Name() string { return t.Name_ }

// Queue returns the queue UUID of this ticketer->wenichats->queue UUID
func (t *Topic) QueueUUID() assets.QueueUUID { return t.QueueUUID_ }
2 changes: 2 additions & 0 deletions assets/static/topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ func TestTopic(t *testing.T) {
topic := static.NewTopic(
assets.TopicUUID("37657cf7-5eab-4286-9cb0-bbf270587bad"),
"Weather",
"1876c846-ea1f-43b4-8ffa-7330772845b6",
)
assert.Equal(t, assets.TopicUUID("37657cf7-5eab-4286-9cb0-bbf270587bad"), topic.UUID())
assert.Equal(t, "Weather", topic.Name())
assert.Equal(t, assets.QueueUUID("1876c846-ea1f-43b4-8ffa-7330772845b6"), topic.QueueUUID())
}
22 changes: 14 additions & 8 deletions assets/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,34 @@ import (
// TopicUUID is the UUID of a topic
type TopicUUID uuids.UUID

// QueueUUID is the UUID of a queue related to wenichats
type QueueUUID string

// Topic categorizes tickets
//
// {
// "uuid": "cd48bd11-08b9-44e3-9778-8e26adf08a7a",
// "name": "Weather"
// }
// {
// "uuid": "cd48bd11-08b9-44e3-9778-8e26adf08a7a",
// "name": "Weather",
// "queue_uuid": "3108d8c2-2a93-4db8-b7c1-d4b1b9c812b3"
// }
//
// @asset topic
type Topic interface {
UUID() TopicUUID
Name() string
QueueUUID() QueueUUID
}

// TopicReference is used to reference a topic
type TopicReference struct {
UUID TopicUUID `json:"uuid" validate:"required,uuid"`
Name string `json:"name"`
UUID TopicUUID `json:"uuid" validate:"required,uuid"`
Name string `json:"name"`
QueueUUID QueueUUID `json:"queue_uuid"`
}

// NewTopicReference creates a new topic reference with the given UUID and name
func NewTopicReference(uuid TopicUUID, name string) *TopicReference {
return &TopicReference{UUID: uuid, Name: name}
func NewTopicReference(uuid TopicUUID, name string, queueUUID QueueUUID) *TopicReference {
return &TopicReference{UUID: uuid, Name: name, QueueUUID: queueUUID}
}

// Type returns the name of the asset type
Expand Down
3 changes: 2 additions & 1 deletion flows/actions/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ 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"),
assets.NewTopicReference("472a7a73-96cb-4736-b567-056d987cc5b4", "Weather", ""),
"Where are my cookies?",
assets.NewUserReference("[email protected]", "Bob McTickets"),
"Ticket",
Expand All @@ -482,6 +482,7 @@ func TestConstructors(t *testing.T) {
},
"topic": {
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"queue_uuid": "",
"name": "Weather"
},
"body": "Where are my cookies?",
Expand Down
3 changes: 2 additions & 1 deletion flows/actions/open_ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const TypeOpenTicket string = "open_ticket"
// },
// "topic": {
// "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
// "name": "Weather"
// "name": "Weather",
// "queue_uuid": ""
// },
// "body": "@input",
// "assignee": {"email": "[email protected]", "name": "Bob McTickets"},
Expand Down
3 changes: 3 additions & 0 deletions flows/actions/testdata/_assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,17 @@
"topics": [
{
"uuid": "0d9a2c56-6fc2-4f27-93c5-a6322e26b740",
"queue_uuid": "",
"name": "General"
},
{
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"queue_uuid": "",
"name": "Weather"
},
{
"uuid": "daa356b6-32af-44f0-9d35-6126d55ec3e9",
"queue_uuid": "",
"name": "Computers"
}
],
Expand Down
19 changes: 19 additions & 0 deletions flows/actions/testdata/open_ticket.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
},
"topic": {
"uuid": "dc61e948-26a1-407e-9739-b73b46400b51",
"queue_uuid": "",
"name": "Deleted"
},
"body": "Where are my cookies?",
Expand Down Expand Up @@ -105,6 +106,7 @@
{
"uuid": "dc61e948-26a1-407e-9739-b73b46400b51",
"name": "Deleted",
"queue_uuid": "",
"type": "topic",
"missing": true
}
Expand All @@ -118,6 +120,7 @@
"dependency": {
"uuid": "dc61e948-26a1-407e-9739-b73b46400b51",
"name": "Deleted",
"queue_uuid": "",
"type": "topic"
}
}
Expand Down Expand Up @@ -173,6 +176,7 @@
},
"topic": {
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"queue_uuid": "",
"name": "Weather"
},
"body": "Last message: @input.text",
Expand Down Expand Up @@ -217,6 +221,7 @@
},
"topic": {
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"queue_uuid": "",
"name": "Weather"
},
"body": "Last message: Hi everybody",
Expand Down Expand Up @@ -287,6 +292,7 @@
},
"topic": {
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"queue_uuid": "",
"name": "Weather"
},
"body": "Last message: Hi everybody",
Expand All @@ -311,6 +317,7 @@
{
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"name": "Weather",
"queue_uuid": "",
"type": "topic"
},
{
Expand Down Expand Up @@ -374,6 +381,7 @@
},
"topic": {
"uuid": "0d9a2c56-6fc2-4f27-93c5-a6322e26b740",
"queue_uuid": "",
"name": "General"
},
"body": "Last message: Hi everybody",
Expand Down Expand Up @@ -440,6 +448,7 @@
},
"topic": {
"uuid": "0d9a2c56-6fc2-4f27-93c5-a6322e26b740",
"queue_uuid": "",
"name": "General"
},
"body": "Last message: Hi everybody",
Expand Down Expand Up @@ -475,6 +484,7 @@
},
"topic": {
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"queue_uuid": "",
"name": "Weather"
},
"body": "Last message: @input.text",
Expand Down Expand Up @@ -518,6 +528,7 @@
},
"topic": {
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"queue_uuid": "",
"name": "Weather"
},
"body": "Last message: Hi everybody",
Expand Down Expand Up @@ -588,6 +599,7 @@
},
"topic": {
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"queue_uuid": "",
"name": "Weather"
},
"body": "Last message: Hi everybody",
Expand All @@ -613,6 +625,7 @@
{
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"name": "Weather",
"queue_uuid": "",
"type": "topic"
}
],
Expand All @@ -633,6 +646,7 @@
},
"topic": {
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"queue_uuid": "",
"name": "Weather"
},
"body": "Last message: @input.text",
Expand Down Expand Up @@ -682,6 +696,7 @@
},
"topic": {
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"queue_uuid": "",
"name": "Weather"
},
"body": "Last message: Hi everybody",
Expand Down Expand Up @@ -748,6 +763,7 @@
},
"topic": {
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"queue_uuid": "",
"name": "Weather"
},
"body": "Last message: Hi everybody",
Expand All @@ -769,6 +785,7 @@
{
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"name": "Weather",
"queue_uuid": "",
"type": "topic"
}
],
Expand Down Expand Up @@ -833,6 +850,7 @@
},
"topic": {
"uuid": "0d9a2c56-6fc2-4f27-93c5-a6322e26b740",
"queue_uuid": "",
"name": "General"
},
"body": "Where are my cookies? ",
Expand Down Expand Up @@ -925,6 +943,7 @@
},
"topic": {
"uuid": "0d9a2c56-6fc2-4f27-93c5-a6322e26b740",
"queue_uuid": "",
"name": "General"
},
"body": "Last message: Hi everybody",
Expand Down
1 change: 1 addition & 0 deletions flows/contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestContact(t *testing.T) {
"topics": [
{
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"queue_uuid": "",
"name": "Weather"
}
]
Expand Down
7 changes: 5 additions & 2 deletions flows/engine/testdata/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,15 @@
},
{
"template": "@(json(contact.tickets))",
"output": "[{\"assignee\":null,\"body\":\"I have a problem\",\"topic\":null,\"uuid\":\"e5f5a9b0-1c08-4e56-8f5c-92e00bc3cf52\"},{\"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\":null,\"body\":\"I have a problem\",\"topic\":null,\"uuid\":\"e5f5a9b0-1c08-4e56-8f5c-92e00bc3cf52\"},{\"assignee\":{\"email\":\"[email protected]\",\"first_name\":\"Bob\",\"name\":\"Bob\"},\"body\":\"What day is it?\",\"topic\":{\"name\":\"Weather\",\"queue_uuid\":\"\",\"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}"
},
{
"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\"},\"body\":\"What day is it?\",\"topic\":{\"name\":\"Weather\",\"queue_uuid\":\"\",\"uuid\":\"472a7a73-96cb-4736-b567-056d987cc5b4\"},\"uuid\":\"78d1fe0d-7e39-461e-81c3-a6a25f15ed69\"}"
},
{
"template": "@(json(contact))",
Expand Down Expand Up @@ -447,6 +447,7 @@
"body": "What day is it?",
"topic": {
"name": "Weather",
"queue_uuid": "",
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4"
},
"uuid": "78d1fe0d-7e39-461e-81c3-a6a25f15ed69"
Expand Down Expand Up @@ -533,6 +534,7 @@
"body": "What day is it?",
"topic": {
"name": "Weather",
"queue_uuid": "",
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4"
},
"uuid": "78d1fe0d-7e39-461e-81c3-a6a25f15ed69"
Expand Down Expand Up @@ -758,6 +760,7 @@
"body": "What day is it?",
"topic": {
"name": "Weather",
"queue_uuid": "",
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4"
},
"uuid": "78d1fe0d-7e39-461e-81c3-a6a25f15ed69"
Expand Down
2 changes: 2 additions & 0 deletions flows/events/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ func TestEventMarshaling(t *testing.T) {
},
"topic": {
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"queue_uuid": "",
"name": "Weather"
},
"uuid": "78d1fe0d-7e39-461e-81c3-a6a25f15ed69"
Expand Down Expand Up @@ -542,6 +543,7 @@ func TestEventMarshaling(t *testing.T) {
},
"topic": {
"uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
"queue_uuid": "",
"name": "Weather"
},
"body": "Where are my cookies?",
Expand Down
1 change: 1 addition & 0 deletions flows/events/ticket_opened.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Ticket struct {
// },
// "topic": {
// "uuid": "add17edf-0b6e-4311-bcd7-a64b2a459157",
// "queue_uuid": "",
// "name": "Weather"
// },
// "body": "Where are my cookies?",
Expand Down
3 changes: 2 additions & 1 deletion flows/inspect/dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestDependencies(t *testing.T) {
flows.NewExtractedReference(node1, action1, nil, envs.NilLanguage, assets.NewLabelReference("31c06b7c-010d-4f91-9590-d3fbdc2fb7ac", "Spam")),
flows.NewExtractedReference(node1, action1, nil, envs.NilLanguage, assets.NewTemplateReference("ff958d30-f50e-48ab-a524-37ed1e9620d9", "Welcome")),
flows.NewExtractedReference(node1, action1, nil, envs.NilLanguage, assets.NewTicketerReference("fb9cab80-4450-4a9d-ba9b-cb8df40dd233", "Support")),
flows.NewExtractedReference(node1, action1, nil, envs.NilLanguage, assets.NewTopicReference("531d3fc7-64f4-4170-927d-b477e8145dd3", "Weather")),
flows.NewExtractedReference(node1, action1, nil, envs.NilLanguage, assets.NewTopicReference("531d3fc7-64f4-4170-927d-b477e8145dd3", "Weather", "")),
flows.NewExtractedReference(node1, action1, nil, envs.NilLanguage, assets.NewUserReference("[email protected]", "Jim")),
flows.NewExtractedReference(node2, nil, router2, envs.NilLanguage, assets.NewGlobalReference("org_name", "Org Name")),
}
Expand Down Expand Up @@ -136,6 +136,7 @@ func TestDependencies(t *testing.T) {
"missing": true,
"name": "Weather",
"type": "topic",
"queue_uuid": "",
"uuid": "531d3fc7-64f4-4170-927d-b477e8145dd3"
},
{
Expand Down
Loading

0 comments on commit e3ba062

Please sign in to comment.