Skip to content

Commit

Permalink
tickets/wenichats: if body is empty or no one custom field in, send a…
Browse files Browse the repository at this point in the history
…ll fields on open room
  • Loading branch information
rasoro committed Aug 16, 2023
1 parent 36a9bdf commit 151bcff
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions services/tickets/wenichats/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,19 @@ func (s *service) Open(session flows.Session, topic *flows.Topic, body string, a
roomData.FlowUUID = session.Runs()[0].Flow().UUID()
roomData.Contact.Groups = groups

// if body is empty send contact fields to customfields or if body is not empty send fields defined in body
if len(body) == 0 {
// if body is not configured with custom fields properly, send all fields from contact
extra := &struct {
CustomFields map[string]interface{} `json:"custom_fields,omitempty"`
}{}
err := jsonx.Unmarshal([]byte(body), extra)
if err == nil && len(extra.CustomFields) > 0 {
roomData.CustomFields = extra.CustomFields
} else {
for k, v := range contact.Fields() {
if v != nil {
roomData.CustomFields[k] = v.Text.Render()
}
}
} else {
extra := &struct {
CustomFields map[string]interface{} `json:"custom_fields,omitempty"`
}{}
err := jsonx.Unmarshal([]byte(body), extra)
if err == nil {
roomData.CustomFields = extra.CustomFields
}
}

newRoom, trace, err := s.restClient.CreateRoom(roomData)
Expand Down

0 comments on commit 151bcff

Please sign in to comment.