From 7871d2182bee3eab5fb1e0ade83a42cd9620597e Mon Sep 17 00:00:00 2001 From: Paulo Bernardo Date: Wed, 27 Nov 2024 14:01:47 -0300 Subject: [PATCH] feat: add button component to wpp message --- flows/actions/send_wpp_message.go | 4 ++-- flows/msg_wpp.go | 15 ++++++++++++++- flows/msg_wpp_test.go | 1 + 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/flows/actions/send_wpp_message.go b/flows/actions/send_wpp_message.go index eeae20fb0..1fb416587 100644 --- a/flows/actions/send_wpp_message.go +++ b/flows/actions/send_wpp_message.go @@ -285,14 +285,14 @@ func (a *SendWppMsgAction) Execute(run flows.FlowRun, step flows.Step, logModifi channelRef = assets.NewChannelReference(dest.Channel.UUID(), dest.Channel.Name()) } - msg := flows.NewMsgWppOut(dest.URN.URN(), channelRef, a.InteractionType, a.HeaderType, evaluatedHeaderText, evaluatedText, evaluatedFooter, ctaMessage, listMessage, flowMessage, orderDetailsMessage, evaluatedAttachments, evaluatedReplyMessage, nil, a.Topic) + msg := flows.NewMsgWppOut(dest.URN.URN(), channelRef, a.InteractionType, a.HeaderType, evaluatedHeaderText, evaluatedText, evaluatedFooter, ctaMessage, listMessage, flowMessage, orderDetailsMessage, evaluatedAttachments, evaluatedReplyMessage, nil, nil, a.Topic) logEvent(events.NewMsgWppCreated(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.NewMsgWppOut(urns.NilURN, nil, a.InteractionType, a.HeaderType, evaluatedHeaderText, evaluatedText, evaluatedFooter, ctaMessage, listMessage, flowMessage, orderDetailsMessage, evaluatedAttachments, evaluatedReplyMessage, nil, flows.NilMsgTopic) + msg := flows.NewMsgWppOut(urns.NilURN, nil, a.InteractionType, a.HeaderType, evaluatedHeaderText, evaluatedText, evaluatedFooter, ctaMessage, listMessage, flowMessage, orderDetailsMessage, evaluatedAttachments, evaluatedReplyMessage, nil, nil, flows.NilMsgTopic) logEvent(events.NewMsgWppCreated(msg)) } diff --git a/flows/msg_wpp.go b/flows/msg_wpp.go index 053821048..18193ca58 100644 --- a/flows/msg_wpp.go +++ b/flows/msg_wpp.go @@ -24,8 +24,18 @@ type MsgWppOut struct { FlowMessage_ FlowMessage `json:"flow_message,omitempty"` OrderDetailsMessage_ OrderDetailsMessage `json:"order_details_message,omitempty"` Templating_ *MsgTemplating `json:"templating,omitempty"` + Buttons_ []ButtonComponent `json:"buttons,omitempty"` } +type ButtonComponent struct { + SubType string `json:"sub_type"` + Parameters []ButtonParam `json:"parameters"` +} + +type ButtonParam struct { + Type string `json:"type"` + Text string `json:"text"` +} type ListMessage struct { ButtonText string `json:"button_text,omitempty"` ListItems []ListItems `json:"list_items,omitempty"` @@ -126,7 +136,7 @@ type MessageOrderAmountWithOffset struct { Offset int `json:"offset"` } -func NewMsgWppOut(urn urns.URN, channel *assets.ChannelReference, interactionType, headerType, headerText, text, footer string, ctaMessage CTAMessage, listMessage ListMessage, flowMessage FlowMessage, orderDetailsMessage OrderDetailsMessage, attachments []utils.Attachment, replyButtons []string, templating *MsgTemplating, topic MsgTopic) *MsgWppOut { +func NewMsgWppOut(urn urns.URN, channel *assets.ChannelReference, interactionType, headerType, headerText, text, footer string, ctaMessage CTAMessage, listMessage ListMessage, flowMessage FlowMessage, orderDetailsMessage OrderDetailsMessage, attachments []utils.Attachment, replyButtons []string, buttons []ButtonComponent, templating *MsgTemplating, topic MsgTopic) *MsgWppOut { return &MsgWppOut{ BaseMsg: BaseMsg{ UUID_: MsgUUID(uuids.New()), @@ -146,6 +156,7 @@ func NewMsgWppOut(urn urns.URN, channel *assets.ChannelReference, interactionTyp FlowMessage_: flowMessage, OrderDetailsMessage_: orderDetailsMessage, Templating_: templating, + Buttons_: buttons, } } @@ -174,3 +185,5 @@ func (m *MsgWppOut) FlowMessage() FlowMessage { return m.FlowMessage_ } func (m *MsgWppOut) OrderDetailsMessage() OrderDetailsMessage { return m.OrderDetailsMessage_ } func (m *MsgWppOut) Templating() *MsgTemplating { return m.Templating_ } + +func (m *MsgWppOut) Buttons() []ButtonComponent { return m.Buttons_ } diff --git a/flows/msg_wpp_test.go b/flows/msg_wpp_test.go index 431a04512..18cf7d6d1 100644 --- a/flows/msg_wpp_test.go +++ b/flows/msg_wpp_test.go @@ -35,6 +35,7 @@ func TestMsgWppOut(t *testing.T) { }, nil, nil, + nil, flows.MsgTopicAgent, )