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

fix: handle empty flow data to not be sent as empty object in request #139

Merged
merged 1 commit 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
17 changes: 11 additions & 6 deletions handlers/facebookapp/facebookapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,11 @@ type wacAmountWithOffset struct {
DiscountProgramName string `json:"discount_program_name,omitempty"`
}

type wacFlowActionPayload struct {
Data map[string]interface{} `json:"data,omitempty"`
Screen string `json:"screen"`
}

func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg) (courier.MsgStatus, error) {
// can't do anything without an access token
accessToken := h.Server().Config().WhatsappAdminSystemUserToken
Expand Down Expand Up @@ -1775,9 +1780,9 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
"flow_id": flowMessage.FlowID,
"flow_cta": flowMessage.FlowCTA,
"flow_action": "navigate",
"flow_action_payload": map[string]interface{}{
"screen": flowMessage.FlowScreen,
"data": flowMessage.FlowData,
"flow_action_payload": wacFlowActionPayload{
Screen: flowMessage.FlowScreen,
Data: flowMessage.FlowData,
},
},
},
Expand Down Expand Up @@ -2220,9 +2225,9 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg)
"flow_id": flowMessage.FlowID,
"flow_cta": flowMessage.FlowCTA,
"flow_action": "navigate",
"flow_action_payload": map[string]interface{}{
"screen": flowMessage.FlowScreen,
"data": flowMessage.FlowData,
"flow_action_payload": wacFlowActionPayload{
Screen: flowMessage.FlowScreen,
Data: flowMessage.FlowData,
},
},
},
Expand Down
7 changes: 7 additions & 0 deletions handlers/facebookapp/facebookapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,13 @@ var SendTestCasesWAC = []ChannelSendTestCase{
ResponseBody: `{ "messages": [{"id": "157b5e14568e8"}] }`, ResponseStatus: 201,
RequestBody: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"flow","header":{"type":"text","text":"header text"},"body":{"text":"msg text"},"footer":{"text":"footer text"},"action":{"name":"flow","parameters":{"flow_action":"navigate","flow_action_payload":{"data":{"list":[1,2],"name":"John Doe"},"screen":"WELCOME_SCREEN"},"flow_cta":"Start Flow","flow_id":"29287124123","flow_message_version":"3","flow_token":"547deaf7-7620-4434-95b3-58675999c4b7","mode":"published"}}}}`,
SendPrep: setSendURL},
{Label: "Send Flow Message without flow data",
Metadata: json.RawMessage(`{"flow_message":{"flow_id": "29287124123", "flow_screen": "WELCOME_SCREEN", "flow_cta": "Start Flow", "flow_data": {}, "flow_mode":"published"},"footer":"footer text","header_text":"header text","header_type":"text","interaction_type":"flow_msg","text":"msgs text"}`),
Text: "msg text", URN: "whatsapp:250788123123",
Status: "W", ExternalID: "157b5e14568e8",
ResponseBody: `{ "messages": [{"id": "157b5e14568e8"}] }`, ResponseStatus: 201,
RequestBody: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"flow","header":{"type":"text","text":"header text"},"body":{"text":"msg text"},"footer":{"text":"footer text"},"action":{"name":"flow","parameters":{"flow_action":"navigate","flow_action_payload":{"screen":"WELCOME_SCREEN"},"flow_cta":"Start Flow","flow_id":"29287124123","flow_message_version":"3","flow_token":"338ff339-5663-49ed-8ef6-384876655d1b","mode":"published"}}}}`,
SendPrep: setSendURL},
{Label: "Send Order Details Message",
Metadata: json.RawMessage(`{"order_details_message":{"reference_id":"220788123125","total_amount":18200,"order":{"catalog_id":"14578923723","items":[{"retailer_id":"789236789","name":"item 1","amount":{"offset":100,"value":200},"quantity":2},{"retailer_id":"59016733","name":"item 2","amount":{"offset":100,"value":4000},"quantity":9,"sale_amount":{"offset":100,"value":2000}}],"subtotal":36400,"tax":{"value":500,"description":"tax description"},"shipping":{"value":900,"description":"shipping description"},"discount":{"value":1000,"description":"discount description","program_name":"discount program name"}},"payment_settings":{"type":"digital-goods","payment_link":"https://foo.bar","pix_config":{"key":"pix-key","key_type":"EMAIL","merchant_name":"merchant name","code":"pix-code"}}},"footer":"footer text","header_type":"media","interaction_type":"order_details","text":"msgs text"}`),
Text: "msg text", URN: "whatsapp:250788123123",
Expand Down
Loading