diff --git a/handlers/facebookapp/facebookapp.go b/handlers/facebookapp/facebookapp.go index f9c1705b8..cbb6769b9 100644 --- a/handlers/facebookapp/facebookapp.go +++ b/handlers/facebookapp/facebookapp.go @@ -266,11 +266,21 @@ func (h *handler) receiveEvent(ctx context.Context, channel courier.Channel, w h sender = msg.Sender.ID } + var urn urns.URN + // create our URN - urn, err := urns.NewFacebookURN(sender) - if err != nil { - return nil, handlers.WriteAndLogRequestError(ctx, h, channel, w, r, err) + if payload.Object == "instagram" { + urn, err = urns.NewInstagramURN(sender) + if err != nil { + return nil, handlers.WriteAndLogRequestError(ctx, h, channel, w, r, err) + } + } else { + urn, err = urns.NewFacebookURN(sender) + if err != nil { + return nil, handlers.WriteAndLogRequestError(ctx, h, channel, w, r, err) + } } + if msg.OptIn != nil { // this is an opt in, if we have a user_ref, use that as our URN (this is a checkbox plugin) // TODO: diff --git a/handlers/facebookapp/facebookapp_test.go b/handlers/facebookapp/facebookapp_test.go index 95b06189a..7b75f97af 100644 --- a/handlers/facebookapp/facebookapp_test.go +++ b/handlers/facebookapp/facebookapp_test.go @@ -729,25 +729,25 @@ var testCasesFBA = []ChannelHandleTestCase{ } var testCasesIG = []ChannelHandleTestCase{ {Label: "Receive Message", URL: "/c/ig/receive", Data: helloMsgIG, Status: 200, Response: "Handled", NoQueueErrorCheck: true, NoInvalidChannelCheck: true, - Text: Sp("Hello World"), URN: Sp("facebook:5678"), ExternalID: Sp("external_id"), Date: Tp(time.Date(2016, 4, 7, 1, 11, 27, 970000000, time.UTC)), + Text: Sp("Hello World"), URN: Sp("instagram:5678"), ExternalID: Sp("external_id"), Date: Tp(time.Date(2016, 4, 7, 1, 11, 27, 970000000, time.UTC)), PrepRequest: addValidSignature}, {Label: "Receive Invalid Signature", URL: "/c/ig/receive", Data: helloMsgIG, Status: 400, Response: "invalid request signature", PrepRequest: addInvalidSignature}, {Label: "No Duplicate Receive Message", URL: "/c/ig/receive", Data: duplicateMsgIG, Status: 200, Response: "Handled", - Text: Sp("Hello World"), URN: Sp("facebook:5678"), ExternalID: Sp("external_id"), Date: Tp(time.Date(2016, 4, 7, 1, 11, 27, 970000000, time.UTC)), + Text: Sp("Hello World"), URN: Sp("instagram:5678"), ExternalID: Sp("external_id"), Date: Tp(time.Date(2016, 4, 7, 1, 11, 27, 970000000, time.UTC)), PrepRequest: addValidSignature}, {Label: "Receive Attachment", URL: "/c/ig/receive", Data: attachmentIG, Status: 200, Response: "Handled", - Text: Sp(""), Attachments: []string{"https://image-url/foo.png"}, URN: Sp("facebook:5678"), ExternalID: Sp("external_id"), Date: Tp(time.Date(2016, 4, 7, 1, 11, 27, 970000000, time.UTC)), + Text: Sp(""), Attachments: []string{"https://image-url/foo.png"}, URN: Sp("instagram:5678"), ExternalID: Sp("external_id"), Date: Tp(time.Date(2016, 4, 7, 1, 11, 27, 970000000, time.UTC)), PrepRequest: addValidSignature}, {Label: "Receive Like Heart", URL: "/c/ig/receive", Data: like_heart, Status: 200, Response: "Handled", - Text: Sp(""), URN: Sp("facebook:5678"), ExternalID: Sp("external_id"), Date: Tp(time.Date(2016, 4, 7, 1, 11, 27, 970000000, time.UTC)), + Text: Sp(""), URN: Sp("instagram:5678"), ExternalID: Sp("external_id"), Date: Tp(time.Date(2016, 4, 7, 1, 11, 27, 970000000, time.UTC)), PrepRequest: addValidSignature}, {Label: "Receive Icebreaker Get Started", URL: "/c/ig/receive", Data: icebreakerGetStarted, Status: 200, Response: "Handled", - URN: Sp("facebook:5678"), Date: Tp(time.Date(2016, 4, 7, 1, 11, 27, 970000000, time.UTC)), ChannelEvent: Sp(courier.NewConversation), + URN: Sp("instagram:5678"), Date: Tp(time.Date(2016, 4, 7, 1, 11, 27, 970000000, time.UTC)), ChannelEvent: Sp(courier.NewConversation), ChannelEventExtra: map[string]interface{}{"title": "icebreaker question", "payload": "get_started"}, PrepRequest: addValidSignature}, @@ -758,7 +758,7 @@ var testCasesIG = []ChannelHandleTestCase{ {Label: "No Messaging Entries", URL: "/c/ig/receive", Data: noMessagingEntriesIG, Status: 200, Response: "Handled", PrepRequest: addValidSignature}, {Label: "Unknown Messaging Entry", URL: "/c/ig/receive", Data: unkownMessagingEntryIG, Status: 200, Response: "Handled", PrepRequest: addValidSignature}, {Label: "Not JSON", URL: "/c/ig/receive", Data: notJSON, Status: 400, Response: "Error", PrepRequest: addValidSignature}, - {Label: "Invalid URN", URL: "/c/ig/receive", Data: invalidURNIG, Status: 400, Response: "invalid facebook id", PrepRequest: addValidSignature}, + {Label: "Invalid URN", URL: "/c/ig/receive", Data: invalidURNIG, Status: 400, Response: "invalid instagram id", PrepRequest: addValidSignature}, {Label: "Story Mention", URL: "/c/ig/receive", Data: storyMentionIG, Status: 200, Response: `ignoring story_mention`, PrepRequest: addValidSignature}, } @@ -952,63 +952,63 @@ var SendTestCasesFBA = []ChannelSendTestCase{ var SendTestCasesIG = []ChannelSendTestCase{ {Label: "Plain Send", - Text: "Simple Message", URN: "facebook:12345", + Text: "Simple Message", URN: "instagram:12345", Status: "W", ExternalID: "mid.133", ResponseBody: `{"message_id": "mid.133"}`, ResponseStatus: 200, RequestBody: `{"messaging_type":"UPDATE","recipient":{"id":"12345"},"message":{"text":"Simple Message"}}`, SendPrep: setSendURL}, {Label: "Plain Response", - Text: "Simple Message", URN: "facebook:12345", + Text: "Simple Message", URN: "instagram:12345", Status: "W", ExternalID: "mid.133", ResponseToExternalID: "23526", ResponseBody: `{"message_id": "mid.133"}`, ResponseStatus: 200, RequestBody: `{"messaging_type":"RESPONSE","recipient":{"id":"12345"},"message":{"text":"Simple Message"}}`, SendPrep: setSendURL}, {Label: "Quick Reply", - Text: "Are you happy?", URN: "facebook:12345", QuickReplies: []string{"Yes", "No"}, + Text: "Are you happy?", URN: "instagram:12345", QuickReplies: []string{"Yes", "No"}, Status: "W", ExternalID: "mid.133", ResponseBody: `{"message_id": "mid.133"}`, ResponseStatus: 200, RequestBody: `{"messaging_type":"UPDATE","recipient":{"id":"12345"},"message":{"text":"Are you happy?","quick_replies":[{"title":"Yes","payload":"Yes","content_type":"text"},{"title":"No","payload":"No","content_type":"text"}]}}`, SendPrep: setSendURL}, {Label: "Long Message", Text: "This is a long message which spans more than one part, what will actually be sent in the end if we exceed the max length?", - URN: "facebook:12345", QuickReplies: []string{"Yes", "No"}, Topic: "agent", + URN: "instagram:12345", QuickReplies: []string{"Yes", "No"}, Topic: "agent", Status: "W", ExternalID: "mid.133", ResponseBody: `{"message_id": "mid.133"}`, ResponseStatus: 200, RequestBody: `{"messaging_type":"MESSAGE_TAG","tag":"HUMAN_AGENT","recipient":{"id":"12345"},"message":{"text":"we exceed the max length?","quick_replies":[{"title":"Yes","payload":"Yes","content_type":"text"},{"title":"No","payload":"No","content_type":"text"}]}}`, SendPrep: setSendURL}, {Label: "Send Photo", - URN: "facebook:12345", Attachments: []string{"image/jpeg:https://foo.bar/image.jpg"}, + URN: "instagram:12345", Attachments: []string{"image/jpeg:https://foo.bar/image.jpg"}, Status: "W", ExternalID: "mid.133", ResponseBody: `{"message_id": "mid.133"}`, ResponseStatus: 200, RequestBody: `{"messaging_type":"UPDATE","recipient":{"id":"12345"},"message":{"attachment":{"type":"image","payload":{"url":"https://foo.bar/image.jpg","is_reusable":true}}}}`, SendPrep: setSendURL}, {Label: "Send caption and photo with Quick Reply", Text: "This is some text.", - URN: "facebook:12345", Attachments: []string{"image/jpeg:https://foo.bar/image.jpg"}, + URN: "instagram:12345", Attachments: []string{"image/jpeg:https://foo.bar/image.jpg"}, QuickReplies: []string{"Yes", "No"}, Status: "W", ExternalID: "mid.133", ResponseBody: `{"message_id": "mid.133"}`, ResponseStatus: 200, RequestBody: `{"messaging_type":"UPDATE","recipient":{"id":"12345"},"message":{"text":"This is some text.","quick_replies":[{"title":"Yes","payload":"Yes","content_type":"text"},{"title":"No","payload":"No","content_type":"text"}]}}`, SendPrep: setSendURL}, {Label: "Tag Human Agent", - Text: "Simple Message", URN: "facebook:12345", + Text: "Simple Message", URN: "instagram:12345", Status: "W", ExternalID: "mid.133", Topic: "agent", ResponseBody: `{"message_id": "mid.133"}`, ResponseStatus: 200, RequestBody: `{"messaging_type":"MESSAGE_TAG","tag":"HUMAN_AGENT","recipient":{"id":"12345"},"message":{"text":"Simple Message"}}`, SendPrep: setSendURL}, {Label: "Send Document", - URN: "facebook:12345", Attachments: []string{"application/pdf:https://foo.bar/document.pdf"}, + URN: "instagram:12345", Attachments: []string{"application/pdf:https://foo.bar/document.pdf"}, Status: "W", ExternalID: "mid.133", ResponseBody: `{"message_id": "mid.133"}`, ResponseStatus: 200, RequestBody: `{"messaging_type":"UPDATE","recipient":{"id":"12345"},"message":{"attachment":{"type":"file","payload":{"url":"https://foo.bar/document.pdf","is_reusable":true}}}}`, SendPrep: setSendURL}, {Label: "ID Error", - Text: "ID Error", URN: "facebook:12345", + Text: "ID Error", URN: "instagram:12345", Status: "E", ResponseBody: `{ "is_error": true }`, ResponseStatus: 200, SendPrep: setSendURL}, {Label: "Error", - Text: "Error", URN: "facebook:12345", + Text: "Error", URN: "instagram:12345", Status: "E", ResponseBody: `{ "is_error": true }`, ResponseStatus: 403, SendPrep: setSendURL},