diff --git a/message/interactive.go b/message/interactive.go new file mode 100644 index 0000000..01c42f3 --- /dev/null +++ b/message/interactive.go @@ -0,0 +1,32 @@ +package message + +type InteractiveReplyButtonsOpts struct { + Header InteractiveHeader + Body string + Buttons []Reply +} + +func NewInteractiveReplyButtons(to string, opts InteractiveReplyButtonsOpts) Envelope { + buttons := make([]Button, len(opts.Buttons)) + for i, b := range opts.Buttons { + buttons[i] = Button{ + Type: "reply", + Reply: b, + } + } + + return Envelope{ + MessagingProduct: "whatsapp", + RecipientType: "individual", + To: to, + Type: "interactive", + Interactive: &Interactive{ + Header: opts.Header, + Body: TextObject{Text: opts.Body}, + Type: "button", + Action: Action{ + Buttons: &buttons, + }, + }, + } +} diff --git a/message/message.go b/message/message.go index a246da2..3d42a92 100644 --- a/message/message.go +++ b/message/message.go @@ -53,8 +53,19 @@ type InteractiveHeader struct { } type Action struct { - Name string `json:"name"` - Parameters Parameters `json:"parameters"` + Name *string `json:"name"` + Parameters *Parameters `json:"parameters,omitempty"` + Buttons *[]Button `json:"buttons,omitempty"` +} + +type Button struct { + Type string `json:"type"` + Reply Reply `json:"reply"` +} + +type Reply struct { + ID string `json:"id"` + Title string `json:"title"` } type Parameters struct { @@ -125,6 +136,7 @@ func NewImageLink(to string, opts NewImageLinkOpts) Envelope { } func NewInteractiveFlow(to string, opts NewFlowOpts) Envelope { + flow := "flow" return Envelope{ MessagingProduct: "whatsapp", RecipientType: "individual", @@ -136,8 +148,8 @@ func NewInteractiveFlow(to string, opts NewFlowOpts) Envelope { Body: opts.Body, Footer: opts.Footer, Action: Action{ - Name: "flow", - Parameters: Parameters{ + Name: &flow, + Parameters: &Parameters{ Mode: opts.FlowMode, FlowMessageVersion: "3", FlowToken: opts.FlowToken,