Skip to content

Commit

Permalink
Merge pull request #178 from weni-ai/feat/-vtex-hide-unavaliable
Browse files Browse the repository at this point in the history
Use hideUnavailable for product search
  • Loading branch information
Robi9 authored Oct 25, 2024
2 parents 6103560 + d8fe875 commit c39a1b9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
10 changes: 6 additions & 4 deletions core/models/org_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,19 @@ 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"`
HideUnavailable bool `json:"hide_unavailable"`
}
}

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) HideUnavailable() bool { return c.c.HideUnavailable }

type OrgContextService interface {
flows.OrgContextService
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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 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=
Expand Down
29 changes: 21 additions & 8 deletions services/external/weni/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func (s *service) Call(session flows.Session, params assets.MsgCatalogParam, log
}

hasVtexAds := params.HasVtexAds
hideUnavailableItems := params.HideUnavailable
productRetailerIDS := []string{}
productRetailerIDMap := make(map[string]struct{})
var productEntries []flows.ProductEntry
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -354,13 +355,13 @@ 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
}
}
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
Expand Down Expand Up @@ -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{}

Expand All @@ -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])
Expand Down Expand Up @@ -534,13 +541,19 @@ func VtexIntelligentSearch(searchUrl string, productSearch string) ([]string, []
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 {
Expand Down

0 comments on commit c39a1b9

Please sign in to comment.