Skip to content

Commit

Permalink
msg catalog, add product search att
Browse files Browse the repository at this point in the history
  • Loading branch information
rasoro committed Oct 10, 2023
1 parent a5ecf1c commit fedf03a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
8 changes: 5 additions & 3 deletions flows/actions/send_msg_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type SendMsgCatalogAction struct {
type createMsgCatalogAction struct {
Products []map[string]string `json:"products"`
AutomaticSearch bool `json:"automaticProductSearch"`
ProductSearch string `json:"productSearch"`
ProductViewSettings ProductViewSettings `json:"productViewSettings"`
}

Expand All @@ -66,7 +67,7 @@ type ProductViewSettings struct {
}

// NewSendMsgCatalog creates a new send msg catalog action
func NewSendMsgCatalog(uuid flows.ActionUUID, header, body, footer, action string, products []map[string]string, automaticSearch, allURNs bool) *SendMsgCatalogAction {
func NewSendMsgCatalog(uuid flows.ActionUUID, header, body, footer, action, productSearch string, products []map[string]string, automaticSearch, allURNs bool) *SendMsgCatalogAction {
return &SendMsgCatalogAction{
baseAction: newBaseAction(TypeSendMsgCatalog, uuid),
createMsgCatalogAction: createMsgCatalogAction{
Expand All @@ -78,6 +79,7 @@ func NewSendMsgCatalog(uuid flows.ActionUUID, header, body, footer, action strin
},
Products: products,
AutomaticSearch: automaticSearch,
ProductSearch: productSearch,
},
AllURNs: allURNs,
}
Expand Down Expand Up @@ -109,14 +111,14 @@ 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, products, a.ProductViewSettings.Action, a.AutomaticSearch, a.Topic)
msg := flows.NewMsgCatalog(dest.URN.URN(), channelRef, evaluatedHeader, evaluatedBody, evaluatedFooter, a.ProductViewSettings.Action, a.ProductSearch, 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, products, a.ProductViewSettings.Action, a.AutomaticSearch, a.Topic)
msg := flows.NewMsgCatalog(urns.NilURN, nil, evaluatedHeader, evaluatedBody, evaluatedFooter, a.ProductViewSettings.Action, a.ProductSearch, products, a.AutomaticSearch, a.Topic)
logEvent(events.NewMsgCatalogCreated(msg))
}

Expand Down
4 changes: 4 additions & 0 deletions flows/actions/testdata/send_msg_catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"action": {
"type": "send_msg_catalog",
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"productSearch": "",
"productViewSettings":{
"header": "header",
"body": "body",
Expand All @@ -21,6 +22,7 @@
"action": {
"type": "send_msg_catalog",
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"productSearch": "",
"productViewSettings":{
"header": "header",
"body": "body",
Expand Down Expand Up @@ -69,6 +71,7 @@
"action": {
"type": "send_msg_catalog",
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"productSearch": "",
"productViewSettings": {
"header": "header text @(xxxxx)",
"body": "Hi there @(1 / 0)",
Expand Down Expand Up @@ -124,6 +127,7 @@
"action": {
"type": "send_msg_catalog",
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"productSearch": "",
"productViewSettings": {
"header": "Hi there",
"body": "@(\"\")",
Expand Down
6 changes: 3 additions & 3 deletions flows/inspect/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ func TestTemplatePaths(t *testing.T) {
"$.nodes[*].actions[@.type=\"send_msg\"].quick_replies[*]",
"$.nodes[*].actions[@.type=\"send_msg\"].templating.variables[*]",
"$.nodes[*].actions[@.type=\"send_msg\"].text",
"$.nodes[*].actions[@.type=\"send_msg_catalog\"].body",
"$.nodes[*].actions[@.type=\"send_msg_catalog\"].footer",
"$.nodes[*].actions[@.type=\"send_msg_catalog\"].header",
"$.nodes[*].actions[@.type=\"send_msg_catalog\"].productViewSettings.body",
"$.nodes[*].actions[@.type=\"send_msg_catalog\"].productViewSettings.footer",
"$.nodes[*].actions[@.type=\"send_msg_catalog\"].productViewSettings.header",
"$.nodes[*].actions[@.type=\"send_msg_catalog\"].templating.variables[*]",
"$.nodes[*].actions[@.type=\"set_contact_field\"].value",
"$.nodes[*].actions[@.type=\"set_contact_language\"].language",
Expand Down
36 changes: 20 additions & 16 deletions flows/msg_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,32 @@ import (
type MsgCatalog struct {
BaseMsg

Header_ string `json:"header,omitempty"`
Body_ string `json:"body,omitempty"`
Footer_ string `json:"footer,omitempty"`
Products_ []string `json:"products,omitempty"`
Action_ string `json:"action,omitempty"`
Topic_ MsgTopic `json:"topic,omitempty"`
Smart_ bool `json:"smart"`
TextLanguage envs.Language `json:"text_language,omitempty"`
Header_ string `json:"header,omitempty"`
Body_ string `json:"body,omitempty"`
Footer_ string `json:"footer,omitempty"`
Products_ []string `json:"products,omitempty"`
Action_ string `json:"action,omitempty"`
Topic_ MsgTopic `json:"topic,omitempty"`
Smart_ bool `json:"smart"`
ProductSearch_ string `json:"product_search,omitempty"`
TextLanguage envs.Language `json:"text_language,omitempty"`
}

func NewMsgCatalog(urn urns.URN, channel *assets.ChannelReference, header string, body string, footer string, products []string, action string, smart bool, topic MsgTopic) *MsgCatalog {
func NewMsgCatalog(urn urns.URN, channel *assets.ChannelReference, header, body, footer, action, productSearch string, products []string, smart bool, topic MsgTopic) *MsgCatalog {
return &MsgCatalog{
BaseMsg: BaseMsg{
UUID_: MsgUUID(uuids.New()),
URN_: urn,
Channel_: channel,
},
Header_: header,
Body_: body,
Footer_: footer,
Products_: products,
Action_: action,
Smart_: smart,
Topic_: topic,
Header_: header,
Body_: body,
Footer_: footer,
Products_: products,
Action_: action,
Smart_: smart,
ProductSearch_: productSearch,
Topic_: topic,
}
}

Expand All @@ -50,3 +52,5 @@ func (m *MsgCatalog) Topic() MsgTopic { return m.Topic_ }
func (m *MsgCatalog) Action() string { return m.Action_ }

func (m *MsgCatalog) Smart() bool { return m.Smart_ }

func (m *MsgCatalog) ProductSearch() string { return m.ProductSearch_ }
7 changes: 5 additions & 2 deletions flows/msg_catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ func TestCatalogMsg(t *testing.T) {
"Header text",
"Body text",
"Footer text",
"View Products",
"",
[]string{
"524580ca-406d-491b-b97e-b07113e322db",
"ee48c9ed-6e52-4a76-8e7b-70c5046c559a",
},
"View Products",
false,
flows.MsgTopic("none"),
)
Expand Down Expand Up @@ -65,8 +66,9 @@ func TestCatalogMsgSmart(t *testing.T) {
"Header text",
"Body text",
"Footer text",
[]string{},
"View Products",
"product search text",
[]string{},
true,
flows.MsgTopic("none"),
)
Expand All @@ -83,6 +85,7 @@ func TestCatalogMsgSmart(t *testing.T) {
},
"footer": "Footer text",
"header": "Header text",
"product_search": "product search text",
"smart": true,
"text": "",
"topic": "none",
Expand Down

0 comments on commit fedf03a

Please sign in to comment.