diff --git a/services/tickets/wenichats/service.go b/services/tickets/wenichats/service.go index 1a7ffdbbb..bbb06bbe3 100644 --- a/services/tickets/wenichats/service.go +++ b/services/tickets/wenichats/service.go @@ -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)