From abb20824892cb7f5e55ad631b354e6d9c84231ad Mon Sep 17 00:00:00 2001 From: Robi9 Date: Thu, 24 Oct 2024 13:43:27 -0300 Subject: [PATCH 1/4] Use hideUnavailable for product search --- go.mod | 2 +- go.sum | 4 ++-- services/external/weni/service.go | 17 ++++++++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 8de332496..b3dd12504 100644 --- a/go.mod +++ b/go.mod @@ -79,4 +79,4 @@ go 1.17 replace github.com/nyaruka/gocommon => github.com/Ilhasoft/gocommon v1.16.2-weni -replace github.com/nyaruka/goflow => github.com/weni-ai/goflow v1.4.2 +replace github.com/nyaruka/goflow => github.com/weni-ai/goflow v1.5.0-staging diff --git a/go.sum b/go.sum index bf3226d77..51e6f1317 100644 --- a/go.sum +++ b/go.sum @@ -329,8 +329,8 @@ github.com/tj/assert v0.0.0-20171129193455-018094318fb0/go.mod h1:mZ9/Rh9oLWpLLD github.com/tj/go-elastic v0.0.0-20171221160941-36157cbbebc2/go.mod h1:WjeM0Oo1eNAjXGDx2yma7uG2XoyRZTq1uv3M/o7imD0= github.com/tj/go-kinesis v0.0.0-20171128231115-08b17f58cb1b/go.mod h1:/yhzCV0xPfx6jb1bBgRFjl5lytqVqZXEaeqWP8lTEao= github.com/tj/go-spin v1.1.0/go.mod h1:Mg1mzmePZm4dva8Qz60H2lHwmJ2loum4VIrLgVnKwh4= -github.com/weni-ai/goflow v1.4.2 h1:71RT6uMq5jZzRMlbbb6JaVs8hMaSrSQwu448i58QJJg= -github.com/weni-ai/goflow v1.4.2/go.mod h1:o0xaVWP9qNcauBSlcNLa79Fm2oCPV+BDpheFRa/D40c= +github.com/weni-ai/goflow v1.5.0-staging h1:FvK7jnbZEv7TvTeBI1np28KaQ+0p7uq2J3Ee741Ag7s= +github.com/weni-ai/goflow v1.5.0-staging/go.mod h1:o0xaVWP9qNcauBSlcNLa79Fm2oCPV+BDpheFRa/D40c= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/services/external/weni/service.go b/services/external/weni/service.go index d07e220d4..c2060c2ea 100644 --- a/services/external/weni/service.go +++ b/services/external/weni/service.go @@ -104,6 +104,7 @@ func (s *service) Call(session flows.Session, params assets.MsgCatalogParam, log } hasVtexAds := params.HasVtexAds + hideUnavailableItems := params.HideUnavaliable productRetailerIDS := []string{} productRetailerIDMap := make(map[string]struct{}) var productEntries []flows.ProductEntry @@ -142,7 +143,7 @@ func (s *service) Call(session flows.Session, params assets.MsgCatalogParam, log searchResult, trace, err = GetProductListFromSentenX(product, catalog.FacebookCatalogID(), searchThreshold, s.rtConfig) callResult.Traces = append(callResult.Traces, trace) } else if params.SearchType == "vtex" { - searchResult, searchResultSponsored, traces, err = GetProductListFromVtex(product, params.SearchUrl, params.ApiType, catalog.FacebookCatalogID(), s.rtConfig, hasVtexAds) + searchResult, searchResultSponsored, traces, err = GetProductListFromVtex(product, params.SearchUrl, params.ApiType, catalog.FacebookCatalogID(), s.rtConfig, hasVtexAds, hideUnavailableItems) callResult.Traces = append(callResult.Traces, traces...) allProducts = append(allProducts, searchResult...) if searchResult == nil { @@ -342,7 +343,7 @@ func GetProductListFromChatGPT(ctx context.Context, rtConfig *runtime.Config, co return products["products"], trace, nil } -func GetProductListFromVtex(productSearch string, searchUrl string, apiType string, catalog string, rt *runtime.Config, hasVtexAds bool) ([]string, string, []*httpx.Trace, error) { +func GetProductListFromVtex(productSearch string, searchUrl string, apiType string, catalog string, rt *runtime.Config, hasVtexAds bool, hideUnavailableItems bool) ([]string, string, []*httpx.Trace, error) { var result []string var traces []*httpx.Trace var err error @@ -354,7 +355,7 @@ func GetProductListFromVtex(productSearch string, searchUrl string, apiType stri return nil, productSponsored, traces, err } } else if apiType == "intelligent" { - result, traces, err = VtexIntelligentSearch(searchUrl, productSearch) + result, traces, err = VtexIntelligentSearch(searchUrl, productSearch, hideUnavailableItems) if err != nil { return nil, productSponsored, traces, err } @@ -466,7 +467,7 @@ func VtexLegacySearch(searchUrl string, productSearch string) ([]string, []*http return allItems, traces, nil } -func VtexIntelligentSearch(searchUrl string, productSearch string) ([]string, []*httpx.Trace, error) { +func VtexIntelligentSearch(searchUrl string, productSearch string, hideUnavailableItems bool) ([]string, []*httpx.Trace, error) { traces := []*httpx.Trace{} @@ -483,7 +484,13 @@ func VtexIntelligentSearch(searchUrl string, productSearch string) ([]string, [] query := url.Values{} query.Add("query", productSearch) - query.Add("hideUnavailableItems", "true") + + hideUnavailable := "true" + if !hideUnavailableItems { + hideUnavailable = "false" + } + + query.Add("hideUnavailableItems", hideUnavailable) for key, value := range queryParams { query.Add(key, value[0]) From 9ec9ab38d985e265df3110eae5918e71e4166c58 Mon Sep 17 00:00:00 2001 From: Robi9 Date: Thu, 24 Oct 2024 13:51:34 -0300 Subject: [PATCH 2/4] Add HideUnavailable in OrgContext --- core/models/org_context.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/models/org_context.go b/core/models/org_context.go index 43b1f903c..b8a667e52 100644 --- a/core/models/org_context.go +++ b/core/models/org_context.go @@ -45,10 +45,11 @@ func orgContextServiceFactory(c *runtime.Config) engine.OrgContextServiceFactory type OrgContext struct { c struct { - OrgContext string `json:"context"` - ChannelUUID assets.ChannelUUID `json:"channel_uuid"` - ProjectUUID uuids.UUID `json:"project_uuid"` - HasVtexAds bool `json:"vtex_ads"` + OrgContext string `json:"context"` + ChannelUUID assets.ChannelUUID `json:"channel_uuid"` + ProjectUUID uuids.UUID `json:"project_uuid"` + HasVtexAds bool `json:"vtex_ads"` + HideUnavaliable bool `json:"hide_unavailable"` } } @@ -56,6 +57,7 @@ func (c *OrgContext) Context() string { return c.c.OrgContext } func (c *OrgContext) ChannelUUID() assets.ChannelUUID { return c.c.ChannelUUID } func (c *OrgContext) ProjectUUID() uuids.UUID { return c.c.ProjectUUID } func (c *OrgContext) HasVtexAds() bool { return c.c.HasVtexAds } +func (c *OrgContext) HideUnavaliable() bool { return c.c.HideUnavaliable } type OrgContextService interface { flows.OrgContextService From 2d580eb257a226efc4c598b1db340e222b5ee30a Mon Sep 17 00:00:00 2001 From: Robi9 Date: Thu, 24 Oct 2024 14:53:39 -0300 Subject: [PATCH 3/4] Use hideUnavailable for sponsored products --- services/external/weni/service.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/services/external/weni/service.go b/services/external/weni/service.go index c2060c2ea..b2a67957b 100644 --- a/services/external/weni/service.go +++ b/services/external/weni/service.go @@ -361,7 +361,7 @@ func GetProductListFromVtex(productSearch string, searchUrl string, apiType stri } } if hasVtexAds { - resultSponsored, tracesAds, err := VtexSponsoredSearch(searchUrl, productSearch) + resultSponsored, tracesAds, err := VtexSponsoredSearch(searchUrl, productSearch, hideUnavailableItems) traces = append(traces, tracesAds...) if err != nil { return nil, productSponsored, traces, err @@ -541,13 +541,19 @@ func VtexIntelligentSearch(searchUrl string, productSearch string, hideUnavailab return allItems, traces, nil } -func VtexSponsoredSearch(searchUrl string, productSearch string) ([]string, []*httpx.Trace, error) { +func VtexSponsoredSearch(searchUrl string, productSearch string, hideUnavailableItems bool) ([]string, []*httpx.Trace, error) { traces := []*httpx.Trace{} query := url.Values{} query.Add("query", productSearch) query.Add("locale", "pt-BR") - query.Add("hideUnavailableItems", "true") + + hideUnavailable := "true" + if !hideUnavailableItems { + hideUnavailable = "false" + } + + query.Add("hideUnavailableItems", hideUnavailable) parsedURL, err := url.Parse(searchUrl) if err != nil { From d8fe875e37c8a0e0ac10229b3b8aebed5d7edef6 Mon Sep 17 00:00:00 2001 From: Robi9 Date: Fri, 25 Oct 2024 17:55:47 -0300 Subject: [PATCH 4/4] update goflow to v1.5.0 --- core/models/org_context.go | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- services/external/weni/service.go | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/models/org_context.go b/core/models/org_context.go index b8a667e52..1fb5dad66 100644 --- a/core/models/org_context.go +++ b/core/models/org_context.go @@ -49,7 +49,7 @@ type OrgContext struct { ChannelUUID assets.ChannelUUID `json:"channel_uuid"` ProjectUUID uuids.UUID `json:"project_uuid"` HasVtexAds bool `json:"vtex_ads"` - HideUnavaliable bool `json:"hide_unavailable"` + HideUnavailable bool `json:"hide_unavailable"` } } @@ -57,7 +57,7 @@ func (c *OrgContext) Context() string { return c.c.OrgContext } func (c *OrgContext) ChannelUUID() assets.ChannelUUID { return c.c.ChannelUUID } func (c *OrgContext) ProjectUUID() uuids.UUID { return c.c.ProjectUUID } func (c *OrgContext) HasVtexAds() bool { return c.c.HasVtexAds } -func (c *OrgContext) HideUnavaliable() bool { return c.c.HideUnavaliable } +func (c *OrgContext) HideUnavailable() bool { return c.c.HideUnavailable } type OrgContextService interface { flows.OrgContextService diff --git a/go.mod b/go.mod index b3dd12504..2add9bd8e 100644 --- a/go.mod +++ b/go.mod @@ -79,4 +79,4 @@ go 1.17 replace github.com/nyaruka/gocommon => github.com/Ilhasoft/gocommon v1.16.2-weni -replace github.com/nyaruka/goflow => github.com/weni-ai/goflow v1.5.0-staging +replace github.com/nyaruka/goflow => github.com/weni-ai/goflow v1.5.0 diff --git a/go.sum b/go.sum index 51e6f1317..4bd126c19 100644 --- a/go.sum +++ b/go.sum @@ -329,8 +329,8 @@ github.com/tj/assert v0.0.0-20171129193455-018094318fb0/go.mod h1:mZ9/Rh9oLWpLLD github.com/tj/go-elastic v0.0.0-20171221160941-36157cbbebc2/go.mod h1:WjeM0Oo1eNAjXGDx2yma7uG2XoyRZTq1uv3M/o7imD0= github.com/tj/go-kinesis v0.0.0-20171128231115-08b17f58cb1b/go.mod h1:/yhzCV0xPfx6jb1bBgRFjl5lytqVqZXEaeqWP8lTEao= github.com/tj/go-spin v1.1.0/go.mod h1:Mg1mzmePZm4dva8Qz60H2lHwmJ2loum4VIrLgVnKwh4= -github.com/weni-ai/goflow v1.5.0-staging h1:FvK7jnbZEv7TvTeBI1np28KaQ+0p7uq2J3Ee741Ag7s= -github.com/weni-ai/goflow v1.5.0-staging/go.mod h1:o0xaVWP9qNcauBSlcNLa79Fm2oCPV+BDpheFRa/D40c= +github.com/weni-ai/goflow v1.5.0 h1:g2tfooIVKdTEGlS/QRqChb0ftRCL1MNf2GkJ/JelztY= +github.com/weni-ai/goflow v1.5.0/go.mod h1:o0xaVWP9qNcauBSlcNLa79Fm2oCPV+BDpheFRa/D40c= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/services/external/weni/service.go b/services/external/weni/service.go index b2a67957b..f68d294fd 100644 --- a/services/external/weni/service.go +++ b/services/external/weni/service.go @@ -104,7 +104,7 @@ func (s *service) Call(session flows.Session, params assets.MsgCatalogParam, log } hasVtexAds := params.HasVtexAds - hideUnavailableItems := params.HideUnavaliable + hideUnavailableItems := params.HideUnavailable productRetailerIDS := []string{} productRetailerIDMap := make(map[string]struct{}) var productEntries []flows.ProductEntry