Skip to content

Commit

Permalink
Merge branch 'feat/send-project-info-on-ticket-open' of https://githu…
Browse files Browse the repository at this point in the history
  • Loading branch information
paulobernardoaf committed Jan 24, 2025
2 parents 1ac0214 + 290873e commit d935426
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
6 changes: 6 additions & 0 deletions services/tickets/wenichats/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ func (c *Client) GetQueues(params *url.Values) (*QueuesResponse, *httpx.Trace, e
return response, trace, nil
}

type ProjectInfo struct {
ProjectUUID string `json:"uuid,omitempty"`
ProjectName string `json:"name,omitempty"`
}

type RoomRequest struct {
TicketUUID string `json:"ticket_uuid,omitempty"`
QueueUUID string `json:"queue_uuid,omitempty"`
Expand All @@ -157,6 +162,7 @@ type RoomRequest struct {
CallbackURL string `json:"callback_url,omitempty"`
FlowUUID assets.FlowUUID `json:"flow_uuid,omitempty"`
IsAnon bool `json:"is_anon,omitempty"`
ProjectInfo *ProjectInfo `json:"project_info,omitempty"`
}

type Contact struct {
Expand Down
18 changes: 17 additions & 1 deletion services/tickets/wenichats/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,22 @@ func (s *service) Open(session flows.Session, topic *flows.Topic, body string, a
}
}

cx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
ticketer, err := models.LookupTicketerByUUID(cx, db, s.ticketer.UUID())

if err != nil {
logrus.Error(errors.Wrap(err, fmt.Sprintf("failed to lookup ticketer: %s", s.ticketer.UUID())))
return nil, errors.Wrap(err, "failed to lookup ticketer")
}

if ticketer != nil && ticketer.Config("project_uuid") != "" && ticketer.Config("project_name_origin") != "" {
roomData.ProjectInfo = &ProjectInfo{
ProjectUUID: ticketer.Config("project_uuid"),
ProjectName: ticketer.Config("project_name_origin"),
}
}

newRoom, trace, err := s.restClient.CreateRoom(roomData)
if trace != nil {
logHTTP(flows.NewHTTPLog(trace, flows.HTTPStatusFromCode, s.redactor))
Expand Down Expand Up @@ -199,7 +215,7 @@ func (s *service) Open(session flows.Session, topic *flows.Topic, body string, a
startMargin := -time.Second * 1
after = session.Runs()[0].CreatedOn().Add(startMargin)
}
cx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
cx, cancel = context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
msgs, selectErr := models.SelectContactMessages(cx, db, int(contact.ID()), after)
if selectErr != nil {
Expand Down
4 changes: 4 additions & 0 deletions services/tickets/wenichats/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ func TestOpenAndForward(t *testing.T) {
msgTime, _ := time.Parse(time.RFC3339, "2019-10-07T15:21:30Z")
rows.AddRow(464, nil, "eb234953-38e7-491f-8a50-b03056a7d002", "ahoy", msgTime, "I", "H", "V", 1, 0, msgTime, "1026", nil, nil, 3, 1234567, 1, 1, 1)

mock.ExpectQuery("SELECT").WithArgs("1ae96956-4b34-433e-8d1a-f05fe6923d6d").WillReturnRows(
sqlmock.NewRows([]string{"row_to_json"}).AddRow(`{"uuid": "1ae96956-4b34-433e-8d1a-f05fe6923d6d", "id": 1, "name": "WeniChats", "ticketer_type": "wenichats", "config": {"project_uuid": "8a4bae05-993c-4f3b-91b5-80f4e09951f2", "project_name_origin": "Project 1"}}`),
)

after, err := time.Parse("2006-01-02T15:04:05", "2019-10-07T15:21:29")
assert.NoError(t, err)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
POST /v1/external/rooms/ HTTP/1.1
Host: chats-engine.dev.cloud.weni.ai
User-Agent: Go-http-client/1.1
Content-Length: 556
Content-Length: 638
Authorization: Bearer ****************
Content-Type: application/json
Accept-Encoding: gzip

{"ticket_uuid":"e7187099-7d38-4f60-955c-325957214c42","queue_uuid":"5c85fdf7-d54a-49dd-97ed-7e10077a1f6a","sector_uuid":"1a4bae05-993c-4f3b-91b5-80f4e09951f2","contact":{"external_id":"5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f","name":"Ryan Lewis","urn":"tel:+12024561111?channel=57f1078f-88aa-46f4-a59a-948a5739c03d","groups":[{"uuid":"b7cf0d83-f1c9-411c-96fd-c511a4cfa86d","name":"Testers"},{"uuid":"4f1f98fc-27a7-4a69-bbdb-24744ba739a9","name":"Males"}]},"custom_fields":{"country":"brazil","mood":"angry"},"flow_uuid":"50c3706e-fedb-42c0-8eab-dda3335714b7"}
{"ticket_uuid":"e7187099-7d38-4f60-955c-325957214c42","queue_uuid":"5c85fdf7-d54a-49dd-97ed-7e10077a1f6a","sector_uuid":"1a4bae05-993c-4f3b-91b5-80f4e09951f2","contact":{"external_id":"5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f","name":"Ryan Lewis","urn":"tel:+12024561111?channel=57f1078f-88aa-46f4-a59a-948a5739c03d","groups":[{"uuid":"b7cf0d83-f1c9-411c-96fd-c511a4cfa86d","name":"Testers"},{"uuid":"4f1f98fc-27a7-4a69-bbdb-24744ba739a9","name":"Males"}]},"custom_fields":{"country":"brazil","mood":"angry"},"flow_uuid":"50c3706e-fedb-42c0-8eab-dda3335714b7","project_info":{"uuid":"8a4bae05-993c-4f3b-91b5-80f4e09951f2","name":"Project 1"}}

0 comments on commit d935426

Please sign in to comment.