Schmavery / facebook-chat-api

Unofficial Facebook Chat API for Nodejs
MIT License
1.93k stars 596 forks source link

Add support for Spotify extensible attachments #558

Open heysanil opened 6 years ago

heysanil commented 6 years ago

Adding a Spotify link to the url field of a message breaks things — results in a message sent with a link preview that doesn't work (clicking it will either do nothing or send you to Facebook.com).

Nov 20 19:25:43 clubschat node[20809]: Error: unrecognized attach_file `{"extensible_attachment":{"legacy_attachment_id":"502977120101126","story_attachment":{"description":{"text":"7/11, a song by Beyoncé on Spotify"},"media":{"animated_image":null,"image":{"uri":"https://external-ort2-1.xx.fbcdn.net/safe_image.php?d=AQDTuJJ4oiWmF_eN&w=960&h=960&url=https%3A%2F%2Fi.scdn.co%2Fimage%2F98be8968e1c29e6ef80831c5867733d2e687b508&_nc_hash=AQAY0sWVDsanbJBC","height":640,"width":640},"playable_duration_in_ms":0,"is_playable":false,"playable_url":null},"source":{"text":"open.spotify.com"},"style_list":["share","fallback"],"title_with_entities":{"text":"7/11"},"properties":[{"key":"width","value":{"text":"640"}},{"key":"height","value":{"text":"640"}}],"url":"https://l.facebook.com/l.php?u=https%3A%2F%2Fopen.spotify.com%2Ftrack%2F02M6vucOvmRfMxTXDUwRXu&h=ATMA6jiqtVRDelLYyrqy3trYQkMgLNOQm2q4KEqXywYNoPNajx46mBpqa07J3D0oTErP0wNOyXmbx8J9Dn2UXV01yD-Y0hn5Jf_no3a5dQpG4VXSsu-ar3zgC2tO&s=1&enc=AZNPxsoZmrVbWnSsH9KHX-Suq8cBq_Cw1vD56MRF4hgvuIq-m4rKD4x5Yekgs0YYG628IoJvYhSSmDiAfYr-lnQY6-A32tOICZvzxk86NB7yzQ","deduplication_key":"eaf0d2f143aaef124963f812bc85cce9","action_links":[],"messaging_attribution":null,"messenger_call_to_actions":[],"target":{"__typename":"ExternalUrl"},"subattachments":[]}}}`
Nov 20 19:25:43 clubschat node[20809]:     at _formatAttachment (<PATH>/node_modules/facebook-chat-api/utils.js:354:13)
Nov 20 19:25:43 clubschat node[20809]:     at attachments.map.v (<PATH>/node_modules/facebook-chat-api/utils.js:386:55)
Nov 20 19:25:43 clubschat node[20809]:     at Array.map (native)
Nov 20 19:25:43 clubschat node[20809]:     at Object.formatDeltaMessage (<PATH>/node_modules/facebook-chat-api/utils.js:386:46)
Nov 20 19:25:43 clubschat node[20809]:     at resolveAttachmentUrl (<PATH>/node_modules/facebook-chat-api/src/listen.js:159:40)
Nov 20 19:25:43 clubschat node[20809]:     at resolveAttachmentUrl (<PATH>/node_modules/facebook-chat-api/src/listen.js:168:30)
Nov 20 19:25:43 clubschat node[20809]:     at parsePackets (<PATH>/node_modules/facebook-chat-api/src/listen.js:171:19)
Nov 20 19:25:43 clubschat node[20809]:     at Array.forEach (native)
Nov 20 19:25:43 clubschat node[20809]:     at <PATH>/node_modules/facebook-chat-api/src/listen.js:109:12
Nov 20 19:25:43 clubschat node[20809]:     at tryCatcher (<PATH>/node_modules/bluebird/js/main/util.js:26:23)
Nov 20 19:25:43 clubschat node[20809]:     at Promise._settlePromiseFromHandler (<PATH>/node_modules/bluebird/js/main/promise.js:510:31)
Nov 20 19:25:43 clubschat node[20809]:     at Promise._settlePromiseAt (<PATH>/node_modules/bluebird/js/main/promise.js:584:18)
Nov 20 19:25:43 clubschat node[20809]:     at Promise._settlePromises (<PATH>/node_modules/bluebird/js/main/promise.js:700:14)
Nov 20 19:25:43 clubschat node[20809]:     at Async._drainQueue (<PATH>/node_modules/bluebird/js/main/async.js:123:16)
Nov 20 19:25:43 clubschat node[20809]:     at Async._drainQueues (<PATH>/node_modules/bluebird/js/main/async.js:133:10)
Nov 20 19:25:43 clubschat node[20809]:     at Immediate.Async.drainQueues (<PATH>/node_modules/bluebird/js/main/async.js:15:14)
heysanil commented 6 years ago

Pretty-printed attachment:

{
    "extensible_attachment": {
        "legacy_attachment_id": "502977120101126",
        "story_attachment": {
            "description": {
                "text": "7/11, a song by Beyoncé on Spotify"
            },
            "media": {
                "animated_image": null,
                "image": {
                    "uri": "https://external-ort2-1.xx.fbcdn.net/safe_image.php?d=AQDTuJJ4oiWmF_eN&w=960&h=960&url=https%3A%2F%2Fi.scdn.co%2Fimage%2F98be8968e1c29e6ef80831c5867733d2e687b508&_nc_hash=AQAY0sWVDsanbJBC",
                    "height": 640,
                    "width": 640
                },
                "playable_duration_in_ms": 0,
                "is_playable": false,
                "playable_url": null
            },
            "source": {
                "text": "open.spotify.com"
            },
            "style_list": [
                "share",
                "fallback"
            ],
            "title_with_entities": {
                "text": "7/11"
            },
            "properties": [
                {
                    "key": "width",
                    "value": {
                        "text": "640"
                    }
                },
                {
                    "key": "height",
                    "value": {
                        "text": "640"
                    }
                }
            ],
            "url": "https://l.facebook.com/l.php?u=https%3A%2F%2Fopen.spotify.com%2Ftrack%2F02M6vucOvmRfMxTXDUwRXu&h=ATMA6jiqtVRDelLYyrqy3trYQkMgLNOQm2q4KEqXywYNoPNajx46mBpqa07J3D0oTErP0wNOyXmbx8J9Dn2UXV01yD-Y0hn5Jf_no3a5dQpG4VXSsu-ar3zgC2tO&s=1&enc=AZNPxsoZmrVbWnSsH9KHX-Suq8cBq_Cw1vD56MRF4hgvuIq-m4rKD4x5Yekgs0YYG628IoJvYhSSmDiAfYr-lnQY6-A32tOICZvzxk86NB7yzQ",
            "deduplication_key": "eaf0d2f143aaef124963f812bc85cce9",
            "action_links": [],
            "messaging_attribution": null,
            "messenger_call_to_actions": [],
            "target": {
                "__typename": "ExternalUrl"
            },
            "subattachments": []
        }
    }
}
heysanil commented 6 years ago

The actual link/preview sent: