twitter.js 328 B

123456789101112131415
  1. let axios = require('axios');
  2. module.exports = {
  3. matches (url) {
  4. return url.match(/^https?:\/\/(www\.)?twitter\.com\/.+\/status\/\d+/i);
  5. },
  6. async getPreviewData (url) {
  7. try {
  8. let res = await axios.get('https://publish.twitter.com/oembed?url=' + url);
  9. return res.data.html;
  10. } catch (e) {
  11. return null;
  12. }
  13. }
  14. };