Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions message/interactive.go
Original file line number Diff line number Diff line change
@@ -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,
},
},
}
}
20 changes: 16 additions & 4 deletions message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down
Loading