Skip to content

Commit

Permalink
Merge pull request #157 from weni-ai/feat/wpp-handler-tests
Browse files Browse the repository at this point in the history
Feat: Add more WhatsApp handler tests
  • Loading branch information
paulobernardoaf authored Dec 12, 2024
2 parents 6c1a970 + 083fdbd commit d874137
Show file tree
Hide file tree
Showing 2 changed files with 285 additions and 16 deletions.
10 changes: 5 additions & 5 deletions handlers/facebookapp/facebookapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1626,13 +1626,13 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)

} else {
if i < (len(msgParts) + len(msg.Attachments()) - 1) {
payload.Type = "text"
if strings.Contains(msgParts[i-len(msg.Attachments())], "https://") || strings.Contains(msgParts[i-len(msg.Attachments())], "http://") {
text := wacText{}
text.PreviewURL = true
text.Body = msgParts[i-len(msg.Attachments())]
payload.Text = &text
} else {
payload.Type = "text"
payload.Text = &wacText{Body: msgParts[i-len(msg.Attachments())]}
}
} else {
Expand Down Expand Up @@ -1973,7 +1973,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
payload.Document = &media
}
//end
} else {
} else { // have attachment
if len(qrs) > 0 || len(msg.ListMessage().ListItems) > 0 {
payload.Type = "interactive"
// We can use buttons
Expand Down Expand Up @@ -2140,7 +2140,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
} else {
return nil, fmt.Errorf("too many quick replies WAC supports only up to 10 quick replies")
}
} else if msg.InteractionType() == "location" {
} else if msg.InteractionType() == "location" { // Unreachable due to else if sending only the attachment
interactive := wacInteractive[map[string]any]{Type: "location_request_message", Body: struct {
Text string "json:\"text\""
}{Text: msgParts[i-len(msg.Attachments())]}, Action: &struct {
Expand All @@ -2154,7 +2154,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
}{Name: "send_location"}}

payload.Interactive = &interactive
} else if msg.InteractionType() == "cta_url" {
} else if msg.InteractionType() == "cta_url" { // Unreachable due to else if sending only the attachment
if ctaMessage := msg.CTAMessage(); ctaMessage != nil {
interactive := wacInteractive[map[string]any]{
Type: "cta_url",
Expand Down Expand Up @@ -2195,7 +2195,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
}
payload.Interactive = &interactive
}
} else if msg.InteractionType() == "flow_msg" {
} else if msg.InteractionType() == "flow_msg" { // Unreachable due to else if sending only the attachment
if flowMessage := msg.FlowMessage(); flowMessage != nil {
interactive := wacInteractive[map[string]any]{
Type: "flow",
Expand Down
Loading

0 comments on commit d874137

Please sign in to comment.