Skip to content

Commit

Permalink
msg catalog evaluate search
Browse files Browse the repository at this point in the history
  • Loading branch information
rasoro committed Oct 13, 2023
1 parent bef5a00 commit f8564b2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions flows/actions/send_msg_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ func (a *SendMsgCatalogAction) Execute(run flows.FlowRun, step flows.Step, logMo
return nil
}

evaluatedSearch, err := run.EvaluateTemplate(a.ProductSearch)
if err != nil {
logEvent(events.NewError(err))
}
if evaluatedSearch == "" {
logEvent(events.NewErrorf("search text evaluated to empty string"))
}

evaluatedHeader, evaluatedBody, evaluatedFooter := a.evaluateMessageCatalog(run, nil, a.ProductViewSettings.Header, a.ProductViewSettings.Body, a.ProductViewSettings.Footer, logEvent)

destinations := run.Contact().ResolveDestinations(a.AllURNs)
Expand All @@ -111,17 +119,20 @@ func (a *SendMsgCatalogAction) Execute(run flows.FlowRun, step flows.Step, logMo
channelRef = assets.NewChannelReference(dest.Channel.UUID(), dest.Channel.Name())
}

msg := flows.NewMsgCatalog(dest.URN.URN(), channelRef, evaluatedHeader, evaluatedBody, evaluatedFooter, a.ProductViewSettings.Action, a.ProductSearch, products, a.AutomaticSearch, a.Topic)
msg := flows.NewMsgCatalog(dest.URN.URN(), channelRef, evaluatedHeader, evaluatedBody, evaluatedFooter, a.ProductViewSettings.Action, evaluatedSearch, products, a.AutomaticSearch, a.Topic)
logEvent(events.NewMsgCatalogCreated(msg))
}

// if we couldn't find a destination, create a msg without a URN or channel and it's up to the caller
// to handle that as they want
if len(destinations) == 0 {
msg := flows.NewMsgCatalog(urns.NilURN, nil, evaluatedHeader, evaluatedBody, evaluatedFooter, a.ProductViewSettings.Action, a.ProductSearch, products, a.AutomaticSearch, a.Topic)
msg := flows.NewMsgCatalog(urns.NilURN, nil, evaluatedHeader, evaluatedBody, evaluatedFooter, a.ProductViewSettings.Action, evaluatedSearch, products, a.AutomaticSearch, a.Topic)
logEvent(events.NewMsgCatalogCreated(msg))
}

// TODO: saveResult with CategoryFailure
a.saveResult(run, step, a.ResultName, "SUCCESS RESULT", CategorySuccess, "", "SUCCESS RESULT", nil, logEvent)

return nil
}

Expand Down

0 comments on commit f8564b2

Please sign in to comment.