Skip to content

Commit

Permalink
Remove hack for get department and custom fields on RocketChat tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
koallann committed Oct 23, 2020
1 parent 7befdac commit 8c046d1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 24 deletions.
7 changes: 2 additions & 5 deletions services/tickets/rocketchat/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,14 @@ func (c *Client) post(endpoint string, payload interface{}, response interface{}
type Visitor struct {
Token string `json:"token"`
ContactUUID string `json:"contactUUID,omitempty"`
Department string `json:"department,omitempty"`
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
Phone string `json:"phone,omitempty"`
CustomFields map[string]string `json:"customFields,omitempty"`
}

type Room struct {
Visitor Visitor `json:"visitor"`
TicketID string `json:"ticketID"`
SessionStart string `json:"sessionStart,omitempty"`
Visitor Visitor `json:"visitor"`
TicketID string `json:"ticketID"`
}

// CreateRoom creates a new room and returns the ID
Expand Down
6 changes: 2 additions & 4 deletions services/tickets/rocketchat/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestCreateRoom(t *testing.T) {
httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
baseURL + "/room": {
httpx.MockConnectionError,
httpx.NewMockResponse(400, nil, `{ "error": "Could not find a department for name: kitchen" }`),
httpx.NewMockResponse(400, nil, `{ "error": "There's no agents online" }`),
httpx.NewMockResponse(201, nil, `{ "id": "uiF7ybjsv7PSJGSw6" }`),
},
}))
Expand All @@ -29,20 +29,18 @@ func TestCreateRoom(t *testing.T) {
Visitor: rocketchat.Visitor{
Token: "1234",
ContactUUID: "88ff1e41-c1f8-4637-af8e-d56acbde9171",
Department: "kitchen",
Name: "Bob",
Email: "bob@acme.com",
Phone: "+16055741111",
},
TicketID: "88ff1e41-c1f8-4637-af8e-d56acbde9171",
SessionStart: "2020-08-03T13:42:53.388037-04:00",
}

_, _, err := client.CreateRoom(room)
assert.EqualError(t, err, "unable to connect to server")

_, _, err = client.CreateRoom(room)
assert.EqualError(t, err, "Could not find a department for name: kitchen")
assert.EqualError(t, err, "There's no agents online")

id, trace, err := client.CreateRoom(room)
assert.NoError(t, err)
Expand Down
13 changes: 0 additions & 13 deletions services/tickets/rocketchat/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rocketchat

import (
"github.com/nyaruka/gocommon/httpx"
"github.com/nyaruka/gocommon/jsonx"
"github.com/nyaruka/gocommon/urns"
"github.com/nyaruka/gocommon/uuids"
"github.com/nyaruka/goflow/flows"
Expand All @@ -11,7 +10,6 @@ import (
"github.com/pkg/errors"
"net/http"
"strconv"
"time"
)

const (
Expand Down Expand Up @@ -81,17 +79,6 @@ func (s *service) Open(session flows.Session, subject, body string, logHTTP flow
},
TicketID: string(ticketUUID),
}
room.SessionStart = session.Runs()[0].CreatedOn().Add(-time.Minute).Format(time.RFC3339)

// to fully support the RocketChat ticketer, look up extra fields from ticket body for now
extra := &struct {
Department string `json:"department"`
CustomFields map[string]string `json:"customFields"`
}{}
if err := jsonx.Unmarshal([]byte(body), extra); err == nil {
room.Visitor.Department = extra.Department
room.Visitor.CustomFields = extra.CustomFields
}

roomID, trace, err := s.client.CreateRoom(room)
if trace != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
GET /api/apps/public/684202ed-1461-4983-9ea7-fde74b15026c/room HTTP/1.1
Host: my.rocket.chat
User-Agent: Go-http-client/1.1
Content-Length: 237
Content-Length: 199
Authorization: Token ****************
Content-Type: application/json
Accept-Encoding: gzip

{"visitor":{"token":"1234567","contactUUID":"5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f","name":"Ryan Lewis","email":"foo@bar.com","phone":"+12024561111"},"ticketID":"59d74b86-3e2f-4a93-aece-b05d2fdcde0c","sessionStart":"2019-10-07T15:20:30Z"}
{"visitor":{"token":"1234567","contactUUID":"5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f","name":"Ryan Lewis","email":"foo@bar.com","phone":"+12024561111"},"ticketID":"59d74b86-3e2f-4a93-aece-b05d2fdcde0c"}

0 comments on commit 8c046d1

Please sign in to comment.