UNPKG

whatsthis

Version:

Discover embedable content from URL's

41 lines (33 loc) 987 B
'use strict'; var request = require('request'); /** * Detect if the given URL is an image. * * @param {Result} result Result of message parsing. * @param {Function} next Continuation callback. * @private */ module.exports = function twitter(result, next) { if ( !(result.url.hostname === 'twitter.com' || result.url.hostname === 'mobile.twitter.com') || !/\/[^\/]+\/status\//gi.test(result.url.pathname) ) { return next(); } // // Mobile urls are not accepted by the embed URL so we need to transform the // host name to just twitter.com to generate a proper embed code. // result.url.set('hostname', 'twitter.com'); result.type = 'social'; result.service = 'twitter'; request({ json: true, method: 'GET', url: 'https://api.twitter.com/1/statuses/oembed.json?url='+ result.url.href }, function generedembed(err, res, body) { if (err) return fn(); result.html = body.html; return next(undefined, true); }); };