Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use parseBacklashes for headerText, footer and ctaMessage #142

Merged
merged 2 commits into from
Oct 23, 2024
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
38 changes: 19 additions & 19 deletions handlers/facebookapp/facebookapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
if msg.Footer() != "" {
interactive.Footer = &struct {
Text string "json:\"text,omitempty\""
}{Text: msg.Footer()}
}{Text: parseBacklashes(msg.Footer())}
}

if msg.HeaderText() != "" {
Expand All @@ -1588,7 +1588,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
Video *wacMTMedia "json:\"video,omitempty\""
Image *wacMTMedia "json:\"image,omitempty\""
Document *wacMTMedia "json:\"document,omitempty\""
}{Type: "text", Text: msg.HeaderText()}
}{Type: "text", Text: parseBacklashes(msg.HeaderText())}
}

btns := make([]wacMTButton, len(qrs))
Expand Down Expand Up @@ -1654,7 +1654,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
if msg.Footer() != "" {
interactive.Footer = &struct {
Text string "json:\"text,omitempty\""
}{Text: msg.Footer()}
}{Text: parseBacklashes(msg.Footer())}
}

if msg.HeaderText() != "" {
Expand All @@ -1664,7 +1664,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
Video *wacMTMedia "json:\"video,omitempty\""
Image *wacMTMedia "json:\"image,omitempty\""
Document *wacMTMedia "json:\"document,omitempty\""
}{Type: "text", Text: msg.HeaderText()}
}{Type: "text", Text: parseBacklashes(msg.HeaderText())}
}
}

Expand Down Expand Up @@ -1728,15 +1728,15 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
}{
Name: "cta_url",
Parameters: map[string]interface{}{
"display_text": ctaMessage.DisplayText,
"display_text": parseBacklashes(ctaMessage.DisplayText),
"url": ctaMessage.URL,
},
},
}
if msg.Footer() != "" {
interactive.Footer = &struct {
Text string "json:\"text,omitempty\""
}{Text: msg.Footer()}
}{Text: parseBacklashes(msg.Footer())}
}

if msg.HeaderText() != "" {
Expand All @@ -1746,7 +1746,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
Video *wacMTMedia "json:\"video,omitempty\""
Image *wacMTMedia "json:\"image,omitempty\""
Document *wacMTMedia "json:\"document,omitempty\""
}{Type: "text", Text: msg.HeaderText()}
}{Type: "text", Text: parseBacklashes(msg.HeaderText())}
}
payload.Interactive = &interactive
}
Expand Down Expand Up @@ -1785,7 +1785,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
if msg.Footer() != "" {
interactive.Footer = &struct {
Text string "json:\"text,omitempty\""
}{Text: msg.Footer()}
}{Text: parseBacklashes(msg.Footer())}
}

if msg.HeaderText() != "" {
Expand All @@ -1795,7 +1795,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
Video *wacMTMedia "json:\"video,omitempty\""
Image *wacMTMedia "json:\"image,omitempty\""
Document *wacMTMedia "json:\"document,omitempty\""
}{Type: "text", Text: msg.HeaderText()}
}{Type: "text", Text: parseBacklashes(msg.HeaderText())}
}
payload.Interactive = &interactive
}
Expand Down Expand Up @@ -1903,7 +1903,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
if msg.Footer() != "" {
interactive.Footer = &struct {
Text string "json:\"text,omitempty\""
}{Text: msg.Footer()}
}{Text: parseBacklashes(msg.Footer())}
}

payload.Interactive = &interactive
Expand Down Expand Up @@ -2075,7 +2075,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
if msg.Footer() != "" {
payload.Interactive.Footer = &struct {
Text string "json:\"text,omitempty\""
}{Text: msg.Footer()}
}{Text: parseBacklashes(msg.Footer())}
}
} else if len(qrs) <= 10 || len(msg.ListMessage().ListItems) > 0 {
interactive := wacInteractive{
Expand Down Expand Up @@ -2114,7 +2114,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
if msg.Footer() != "" {
interactive.Footer = &struct {
Text string "json:\"text,omitempty\""
}{Text: msg.Footer()}
}{Text: parseBacklashes(msg.Footer())}
}
}

Expand Down Expand Up @@ -2172,7 +2172,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
}{
Name: "cta_url",
Parameters: map[string]interface{}{
"display_text": ctaMessage.DisplayText,
"display_text": parseBacklashes(ctaMessage.DisplayText),
"url": ctaMessage.URL,
},
},
Expand All @@ -2181,7 +2181,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
if msg.Footer() != "" {
interactive.Footer = &struct {
Text string "json:\"text,omitempty\""
}{Text: msg.Footer()}
}{Text: parseBacklashes(msg.Footer())}
}

if msg.HeaderText() != "" {
Expand All @@ -2191,7 +2191,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
Video *wacMTMedia "json:\"video,omitempty\""
Image *wacMTMedia "json:\"image,omitempty\""
Document *wacMTMedia "json:\"document,omitempty\""
}{Type: "text", Text: msg.HeaderText()}
}{Type: "text", Text: parseBacklashes(msg.HeaderText())}
}
payload.Interactive = &interactive
}
Expand Down Expand Up @@ -2230,7 +2230,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
if msg.Footer() != "" {
interactive.Footer = &struct {
Text string "json:\"text,omitempty\""
}{Text: msg.Footer()}
}{Text: parseBacklashes(msg.Footer())}
}

if msg.HeaderText() != "" {
Expand All @@ -2240,7 +2240,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
Video *wacMTMedia "json:\"video,omitempty\""
Image *wacMTMedia "json:\"image,omitempty\""
Document *wacMTMedia "json:\"document,omitempty\""
}{Type: "text", Text: msg.HeaderText()}
}{Type: "text", Text: parseBacklashes(msg.HeaderText())}
}
payload.Interactive = &interactive
}
Expand Down Expand Up @@ -2348,7 +2348,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
if msg.Footer() != "" {
interactive.Footer = &struct {
Text string "json:\"text,omitempty\""
}{Text: msg.Footer()}
}{Text: parseBacklashes(msg.Footer())}
}

if len(msg.Attachments()) > 0 {
Expand Down Expand Up @@ -2472,7 +2472,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
interactive.Footer = &struct {
Text string "json:\"text,omitempty\""
}{
Text: msg.Footer(),
Text: parseBacklashes(msg.Footer()),
}
}

Expand Down
26 changes: 13 additions & 13 deletions handlers/whatsapp/whatsapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ func buildPayloads(msg courier.Msg, h *handler) ([]interface{}, []*courier.Chann
if msg.Footer() != "" {
payload.Interactive.Footer = &struct {
Text string "json:\"text\""
}{Text: msg.Footer()}
}{Text: parseBacklashes(msg.Footer())}
}

if msg.HeaderText() != "" {
Expand All @@ -890,7 +890,7 @@ func buildPayloads(msg courier.Msg, h *handler) ([]interface{}, []*courier.Chann
Video mediaObject "json:\"video,omitempty\""
Image mediaObject "json:\"image,omitempty\""
Document mediaObject "json:\"document,omitempty\""
}{Type: "text", Text: msg.HeaderText()}
}{Type: "text", Text: parseBacklashes(msg.HeaderText())}
}

btns := make([]mtButton, len(qrs))
Expand Down Expand Up @@ -958,7 +958,7 @@ func buildPayloads(msg courier.Msg, h *handler) ([]interface{}, []*courier.Chann
if msg.Footer() != "" {
payload.Interactive.Footer = &struct {
Text string "json:\"text\""
}{Text: msg.Footer()}
}{Text: parseBacklashes(msg.Footer())}
}
}
payload.Interactive.Action.Sections = []mtSection{section}
Expand Down Expand Up @@ -986,14 +986,14 @@ func buildPayloads(msg courier.Msg, h *handler) ([]interface{}, []*courier.Chann
}{
Name: "cta_url",
Parameters: map[string]string{
"display_text": ctaMessage.DisplayText,
"display_text": parseBacklashes(ctaMessage.DisplayText),
"url": ctaMessage.URL,
},
}
if msg.Footer() != "" {
payload.Interactive.Footer = &struct {
Text string "json:\"text\""
}{Text: msg.Footer()}
}{Text: parseBacklashes(msg.Footer())}
}

if msg.HeaderText() != "" {
Expand All @@ -1005,7 +1005,7 @@ func buildPayloads(msg courier.Msg, h *handler) ([]interface{}, []*courier.Chann
Document mediaObject "json:\"document,omitempty\""
}{
Type: "text",
Text: msg.HeaderText(),
Text: parseBacklashes(msg.HeaderText()),
}
}
payloads = append(payloads, payload)
Expand Down Expand Up @@ -1246,7 +1246,7 @@ func buildPayloads(msg courier.Msg, h *handler) ([]interface{}, []*courier.Chann
if msg.Footer() != "" {
payload.Interactive.Footer = &struct {
Text string "json:\"text\""
}{Text: msg.Text()}
}{Text: parseBacklashes(msg.Footer())}
}
payloads = append(payloads, payload)

Expand Down Expand Up @@ -1283,7 +1283,7 @@ func buildPayloads(msg courier.Msg, h *handler) ([]interface{}, []*courier.Chann
if msg.Footer() != "" {
payload.Interactive.Footer = &struct {
Text string "json:\"text\""
}{Text: msg.Text()}
}{Text: parseBacklashes(msg.Footer())}
}
}

Expand All @@ -1309,7 +1309,7 @@ func buildPayloads(msg courier.Msg, h *handler) ([]interface{}, []*courier.Chann
payload.Interactive.Type = "cta_url"
payload.Interactive.Body = struct {
Text string "json:\"text\""
}{msg.Text()}
}{parseBacklashes(msg.Text())}
payload.Interactive.Action = &struct {
Button string "json:\"button,omitempty\""
Sections []mtSection "json:\"sections,omitempty\""
Expand All @@ -1321,15 +1321,15 @@ func buildPayloads(msg courier.Msg, h *handler) ([]interface{}, []*courier.Chann
}{
Name: "cta_url",
Parameters: map[string]string{
"display_text": ctaMessage.DisplayText,
"display_text": parseBacklashes(ctaMessage.DisplayText),
"url": ctaMessage.URL,
},
}

if msg.Footer() != "" {
payload.Interactive.Footer = &struct {
Text string "json:\"text\""
}{Text: msg.Footer()}
}{Text: parseBacklashes(msg.Footer())}
}

if msg.HeaderText() != "" {
Expand All @@ -1341,7 +1341,7 @@ func buildPayloads(msg courier.Msg, h *handler) ([]interface{}, []*courier.Chann
Document mediaObject "json:\"document,omitempty\""
}{
Type: "text",
Text: msg.HeaderText(),
Text: parseBacklashes(msg.HeaderText()),
}
}
payloads = append(payloads, payload)
Expand Down Expand Up @@ -1431,7 +1431,7 @@ func buildPayloads(msg courier.Msg, h *handler) ([]interface{}, []*courier.Chann
payload.Interactive.Footer = &struct {
Text string "json:\"text\""
}{
Text: msg.Footer(),
Text: parseBacklashes(msg.Footer()),
}
}

Expand Down
4 changes: 2 additions & 2 deletions handlers/whatsapp/whatsapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ var defaultSendTestCases = []ChannelSendTestCase{
Text: "Interactive Button Msg", URN: "whatsapp:250788123123", QuickReplies: []string{"BUTTON1"}, Attachments: []string{"video/mp4:https://foo.bar/video.mp4"},
Status: "W", ExternalID: "157b5e14568e8",
ResponseBody: `{ "messages": [{"id": "157b5e14568e8"}] }`, ResponseStatus: 201,
RequestBody: `{"to":"250788123123","type":"interactive","interactive":{"type":"button","header":{"type":"video","video":{"link":"https://foo.bar/video.mp4"},"image":{},"document":{}},"body":{"text":"Interactive Button Msg"},"footer":{"text":"Interactive Button Msg"},"action":{"buttons":[{"type":"reply","reply":{"id":"0","title":"BUTTON1"}}]}}}`,
RequestBody: `{"to":"250788123123","type":"interactive","interactive":{"type":"button","header":{"type":"video","video":{"link":"https://foo.bar/video.mp4"},"image":{},"document":{}},"body":{"text":"Interactive Button Msg"},"footer":{"text":"footer is here!"},"action":{"buttons":[{"type":"reply","reply":{"id":"0","title":"BUTTON1"}}]}}}`,
SendPrep: setSendURL},
{Label: "Media Message Template Send - Image",
Text: "Media Message Msg", URN: "whatsapp:250788123123",
Expand Down Expand Up @@ -884,7 +884,7 @@ var defaultSendTestCases = []ChannelSendTestCase{
Text: "Interactive Button Msg", URN: "whatsapp:250788123123", QuickReplies: []string{"BUTTON1"}, Attachments: []string{"application/pdf:https://foo.bar/document.pdf"},
Status: "W", ExternalID: "157b5e14568e8",
ResponseBody: `{ "messages": [{"id": "157b5e14568e8"}] }`, ResponseStatus: 201,
RequestBody: `{"to":"250788123123","type":"interactive","interactive":{"type":"button","header":{"type":"document","video":{},"image":{},"document":{"link":"https://foo.bar/document.pdf","filename":"document.pdf"}},"body":{"text":"Interactive Button Msg"},"footer":{"text":"Interactive Button Msg"},"action":{"buttons":[{"type":"reply","reply":{"id":"0","title":"BUTTON1"}}]}}}`,
RequestBody: `{"to":"250788123123","type":"interactive","interactive":{"type":"button","header":{"type":"document","video":{},"image":{},"document":{"link":"https://foo.bar/document.pdf","filename":"document.pdf"}},"body":{"text":"Interactive Button Msg"},"footer":{"text":"footer is here!"},"action":{"buttons":[{"type":"reply","reply":{"id":"0","title":"BUTTON1"}}]}}}`,
SendPrep: setSendURL},
}

Expand Down
Loading