(sock: any, message: any, args: any, context: BotContext)
| 17 | usage: '.fb <facebook video link>', |
| 18 | |
| 19 | async handler(sock: any, message: any, args: any, context: BotContext) { |
| 20 | const chatId = context.chatId || message.key.remoteJid; |
| 21 | const url = |
| 22 | args.join(' ') || |
| 23 | message.message?.conversation || |
| 24 | message.message?.extendedTextMessage?.text; |
| 25 | |
| 26 | try { |
| 27 | if (!url) { |
| 28 | return await sock.sendMessage(chatId, { text: '📘 *Facebook Downloader*\n\nUsage:\n.fb <facebook video link>' }, { quoted: message }); |
| 29 | } |
| 30 | |
| 31 | if (!/facebook\.com|fb\.watch/i.test(url)) { |
| 32 | return await sock.sendMessage( |
| 33 | chatId, |
| 34 | { text: '❌ Invalid Facebook link.\nPlease send a valid Facebook video URL.' }, |
| 35 | { quoted: message } |
| 36 | ); |
| 37 | } |
| 38 | |
| 39 | await sock.sendMessage(chatId, { |
| 40 | react: { text: '🔄', key: message.key } |
| 41 | }); |
| 42 | |
| 43 | const apiUrl = `https://gtech-api-xtp1.onrender.com/api/download/fb?url=${encodeURIComponent( |
| 44 | url |
| 45 | )}&apikey=APIKEY`; |
| 46 | |
| 47 | const res = await axios.get(apiUrl, AXIOS_DEFAULTS); |
| 48 | |
| 49 | const videos = res?.data?.data?.data; |
| 50 | if (!res?.data?.status || !Array.isArray(videos) || !videos.length) { |
| 51 | throw new Error('No downloadable video found'); |
| 52 | } |
| 53 | |
| 54 | const sorted = videos.sort((a, b) => { |
| 55 | const qa = parseInt(a.resolution, 10) || 0; |
| 56 | const qb = parseInt(b.resolution, 10) || 0; |
| 57 | return qb - qa; |
| 58 | }); |
| 59 | |
| 60 | const selected = sorted[0]; |
| 61 | const videoUrl = selected.url.startsWith('http') |
| 62 | ? selected.url |
| 63 | : `https://gtech-api-xtp1.onrender.com${selected.url}`; |
| 64 | |
| 65 | const caption = `📘 *Facebook Downloader* |
| 66 | 🎞 Quality: *${selected.resolution || 'Unknown'}* |
| 67 | |
| 68 | > *_Downloaded by MEGA-MD_*`; |
| 69 | |
| 70 | await sock.sendMessage(chatId, { video: { url: videoUrl }, mimetype: 'video/mp4', caption }, { quoted: message }); |
| 71 | |
| 72 | } catch(err: any) { |
| 73 | console.error('Facebook downloader error:', err); |
| 74 | await sock.sendMessage( |
| 75 | chatId, |
| 76 | { text: '❌ Failed to download Facebook video. Please try again later.' }, |
nothing calls this directly
no outgoing calls
no test coverage detected