Skip to content

Commit

Permalink
Handle extra fields from ticket body on RocketChat ticketer
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan Lima committed Jul 15, 2020
1 parent fee12aa commit 9ae0a08
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
20 changes: 18 additions & 2 deletions services/tickets/rocketchat/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type VisitorToken string

type Visitor struct {
Token VisitorToken `json:"token"`
Department string `json:"department"`
Name string `json:"name"`
Email string `json:"email"`
Phone string `json:"phone"`
Expand All @@ -98,11 +99,26 @@ type Room struct {
ID string `json:"id"`
}

func (c *Client) CreateRoom(visitor *Visitor) (*Room, *httpx.Trace, error) {
func (c *Client) CreateRoom(visitor *Visitor, extraFields string) (*Room, *httpx.Trace, error) {
payload := struct {
Visitor *Visitor `json:"visitor"`
Visitor *Visitor `json:"visitor"`
SessionStart string `json:"sessionStart"`
Priority string `json:"priority"`
}{Visitor: visitor}

extra := &struct {
SessionStart string `json:"sessionStart"`
Priority string `json:"priority"`
Department string `json:"department"`
CustomFields map[string]string `json:"customFields"`
}{}
if err := jsonx.Unmarshal([]byte(extraFields), extra); err == nil {
payload.Visitor.Department = extra.Department
payload.Visitor.CustomFields = extra.CustomFields
payload.Priority = extra.Priority
payload.SessionStart = extra.SessionStart
}

response := &Room{}

trace, err := c.get("room", payload, response)
Expand Down
2 changes: 1 addition & 1 deletion services/tickets/rocketchat/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *service) Open(session flows.Session, subject, body string, logHTTP flow
Email: email,
Phone: phone,
}
room, trace, err := s.client.CreateRoom(visitor)
room, trace, err := s.client.CreateRoom(visitor, body)
if trace != nil {
logHTTP(flows.NewHTTPLog(trace, flows.HTTPStatusFromCode, s.redactor))
}
Expand Down
2 changes: 1 addition & 1 deletion services/tickets/rocketchat/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func init() {
}

type eventCallbackRequest struct {
Type string `json:"type" validate:"required"`
Type string `json:"type" validate:"required"`
Visitor struct {
Token string `json:"token" validate:"required"`
} `json:"visitor" validate:"required"`
Expand Down

0 comments on commit 9ae0a08

Please sign in to comment.