From 6f2aa079cf9223d4b02c6a879731f44e359166f0 Mon Sep 17 00:00:00 2001 From: Rafael Soares Date: Wed, 16 Aug 2023 11:27:06 -0300 Subject: [PATCH] tickets/wenichats: if body is empty or no one custom field in, send all fields on open room --- services/tickets/wenichats/service.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) 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)