diff --git a/handlers/facebookapp/facebookapp.go b/handlers/facebookapp/facebookapp.go index 2d357d1c6..6bc6373d7 100644 --- a/handlers/facebookapp/facebookapp.go +++ b/handlers/facebookapp/facebookapp.go @@ -215,6 +215,10 @@ type moPayload struct { ID string `json:"id"` Title string `json:"title"` } `json:"list_reply,omitempty"` + NFMReply struct { + Name string `json:"name,omitempty"` + ResponseJSON string `json:"response_json"` + } `json:"nfm_reply"` } `json:"interactive,omitempty"` Contacts []struct { Name struct { @@ -588,6 +592,16 @@ func (h *handler) processCloudWhatsAppPayload(ctx context.Context, channel couri event.WithMetadata(metadata) } + if msg.Interactive.Type == "nfm_reply" { + nfmReply := map[string]interface{}{"nfm_reply": msg.Interactive.NFMReply} + nfmReplyJSON, err := json.Marshal(nfmReply) + if err != nil { + courier.LogRequestError(r, channel, err) + } + metadata := json.RawMessage(nfmReplyJSON) + event.WithMetadata(metadata) + } + if mediaURL != "" { event.WithAttachment(mediaURL) } diff --git a/handlers/facebookapp/facebookapp_test.go b/handlers/facebookapp/facebookapp_test.go index b4171d0ba..2839bd59d 100644 --- a/handlers/facebookapp/facebookapp_test.go +++ b/handlers/facebookapp/facebookapp_test.go @@ -321,7 +321,14 @@ var testCasesWAC = []ChannelHandleTestCase{ }, }), PrepRequest: addValidSignatureWAC}, - + {Label: "Receive NFM Reply WAC", URL: wacReceiveURL, Data: string(courier.ReadFile("./testdata/wac/flowWAC.json")), Status: 200, Response: "Handled", NoQueueErrorCheck: true, NoInvalidChannelCheck: true, + URN: Sp("whatsapp:5678"), ExternalID: Sp("external_id"), Date: Tp(time.Date(2016, 1, 30, 1, 57, 9, 0, time.UTC)), Metadata: Jp(map[string]interface{}{ + "nfm_reply": map[string]interface{}{ + "name": "Flow Wpp", + "response_json": "{\"flow_token\": \"\", \"optional_param1\": \"\", \"optional_param2\": \"\"}", + }, + }), + PrepRequest: addValidSignatureWAC}, {Label: "Receive Valid Document Message", URL: wacReceiveURL, Data: string(courier.ReadFile("./testdata/wac/documentWAC.json")), Status: 200, Response: "Handled", NoQueueErrorCheck: true, NoInvalidChannelCheck: true, Text: Sp("80skaraokesonglistartist"), URN: Sp("whatsapp:5678"), ExternalID: Sp("external_id"), Attachment: Sp("https://foo.bar/attachmentURL_Document"), Date: Tp(time.Date(2016, 1, 30, 1, 57, 9, 0, time.UTC)), PrepRequest: addValidSignatureWAC}, diff --git a/handlers/facebookapp/testdata/wac/flowWAC.json b/handlers/facebookapp/testdata/wac/flowWAC.json new file mode 100644 index 000000000..37f205ba2 --- /dev/null +++ b/handlers/facebookapp/testdata/wac/flowWAC.json @@ -0,0 +1,43 @@ +{ + "object": "whatsapp_business_account", + "entry": [ + { + "id": "8856996819413533", + "changes": [ + { + "value": { + "messaging_product": "whatsapp", + "metadata": { + "display_phone_number": "+250 788 123 200", + "phone_number_id": "12345" + }, + "contacts": [ + { + "profile": { + "name": "Kerry Fisher" + }, + "wa_id": "5678" + } + ], + "messages": [ + { + "from": "5678", + "id": "external_id", + "timestamp": "1454119029", + "type": "interactive", + "interactive": { + "type": "nfm_reply", + "nfm_reply": { + "name": "Flow Wpp", + "response_json": "{\"flow_token\": \"\", \"optional_param1\": \"\", \"optional_param2\": \"\"}" + } + } + } + ] + }, + "field": "messages" + } + ] + } + ] + } \ No newline at end of file