Skip to content

Commit

Permalink
Order components in template and fix max length for D3C
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Mar 15, 2024
1 parent 9ba8161 commit d55ff29
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion handlers/dialog360/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (

var (
// max for the body
maxMsgLength = 1000
maxMsgLength = 4096
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion handlers/dialog360/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
},
},
ExpectedRequests: []ExpectedRequest{{
Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"template","template":{"name":"revive_issue","language":{"policy":"deterministic","code":"en_US"},"components":[{"type":"body","sub_type":"","index":"","parameters":[{"type":"text","text":"Chef"},{"type":"text","text":"tomorrow"}]}]}}`,
Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"template","template":{"name":"revive_issue","language":{"policy":"deterministic","code":"en_US"},"components":[{"type":"body","parameters":[{"type":"text","text":"Chef"},{"type":"text","text":"tomorrow"}]}]}}`,
}},
ExpectedExtIDs: []string{"157b5e14568e8"},
},
Expand Down
4 changes: 2 additions & 2 deletions handlers/meta/whataspp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ var whatsappOutgoingTests = []OutgoingTestCase{
},
},
ExpectedRequests: []ExpectedRequest{{
Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"template","template":{"name":"revive_issue","language":{"policy":"deterministic","code":"en_US"},"components":[{"type":"body","sub_type":"","index":"","parameters":[{"type":"text","text":"Chef"},{"type":"text","text":"tomorrow"}]}]}}`,
Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"template","template":{"name":"revive_issue","language":{"policy":"deterministic","code":"en_US"},"components":[{"type":"body","parameters":[{"type":"text","text":"Chef"},{"type":"text","text":"tomorrow"}]}]}}`,
}},
ExpectedExtIDs: []string{"157b5e14568e8"},
},
Expand Down Expand Up @@ -456,7 +456,7 @@ var whatsappOutgoingTests = []OutgoingTestCase{
},
},
ExpectedRequests: []ExpectedRequest{{
Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"template","template":{"name":"revive_issue","language":{"policy":"deterministic","code":"en_US"},"components":[{"type":"body","sub_type":"","index":"","parameters":[{"type":"text","text":"Ryan Lewis"},{"type":"text","text":"niño"}]},{"type":"button","sub_type":"quick_reply","index":"0","parameters":[{"type":"payload","payload":"Sip"}]},{"type":"button","sub_type":"quick_reply","index":"1","parameters":[{"type":"text","text":"id00231"}]}]}}`,
Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"template","template":{"name":"revive_issue","language":{"policy":"deterministic","code":"en_US"},"components":[{"type":"body","parameters":[{"type":"text","text":"Ryan Lewis"},{"type":"text","text":"niño"}]},{"type":"button","sub_type":"quick_reply","index":"0","parameters":[{"type":"payload","payload":"Sip"}]},{"type":"button","sub_type":"quick_reply","index":"1","parameters":[{"type":"text","text":"id00231"}]}]}}`,
}},
ExpectedExtIDs: []string{"157b5e14568e8"},
},
Expand Down
4 changes: 2 additions & 2 deletions handlers/meta/whatsapp/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ type Param struct {

type Component struct {
Type string `json:"type"`
SubType string `json:"sub_type"`
Index string `json:"index"`
SubType string `json:"sub_type,omitempty"`
Index string `json:"index,omitempty"`
Params []*Param `json:"parameters"`
}

Expand Down
4 changes: 4 additions & 0 deletions handlers/meta/whatsapp/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,9 @@ func GetTemplatePayload(templating MsgTemplating) *Template {

}

sort.SliceStable(template.Components, func(i, j int) bool {
return template.Components[i].Index < template.Components[j].Index
})

return template
}

0 comments on commit d55ff29

Please sign in to comment.