(sock, chatId, message)
| 3 | const path = require('path'); |
| 4 | |
| 5 | async function facebookCommand(sock, chatId, message) { |
| 6 | try { |
| 7 | const text = message.message?.conversation || message.message?.extendedTextMessage?.text; |
| 8 | const url = text.split(' ').slice(1).join(' ').trim(); |
| 9 | |
| 10 | if (!url) { |
| 11 | return await sock.sendMessage(chatId, { |
| 12 | text: "Please provide a Facebook video URL.\nExample: .fb https://www.facebook.com/..." |
| 13 | }, { quoted: message }); |
| 14 | } |
| 15 | |
| 16 | // Validate Facebook URL |
| 17 | if (!url.includes('facebook.com')) { |
| 18 | return await sock.sendMessage(chatId, { |
| 19 | text: "That is not a Facebook link." |
| 20 | }, { quoted: message }); |
| 21 | } |
| 22 | |
| 23 | // Send loading reaction |
| 24 | await sock.sendMessage(chatId, { |
| 25 | react: { text: '🔄', key: message.key } |
| 26 | }); |
| 27 | |
| 28 | // Resolve share/short URLs to their final destination first |
| 29 | let resolvedUrl = url; |
| 30 | try { |
| 31 | const res = await axios.get(url, { timeout: 20000, maxRedirects: 10, headers: { 'User-Agent': 'Mozilla/5.0' } }); |
| 32 | const possible = res?.request?.res?.responseUrl; |
| 33 | if (possible && typeof possible === 'string') { |
| 34 | resolvedUrl = possible; |
| 35 | } |
| 36 | } catch { |
| 37 | // ignore resolution errors; use original url |
| 38 | } |
| 39 | |
| 40 | // Use Hanggts API |
| 41 | async function fetchFromApi(u) { |
| 42 | const apiUrl = `https://api.hanggts.xyz/download/facebook?url=${encodeURIComponent(u)}`; |
| 43 | |
| 44 | try { |
| 45 | const response = await axios.get(apiUrl, { |
| 46 | timeout: 20000, |
| 47 | headers: { |
| 48 | 'accept': '*/*', |
| 49 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36' |
| 50 | }, |
| 51 | maxRedirects: 5, |
| 52 | validateStatus: s => s >= 200 && s < 500 |
| 53 | }); |
| 54 | |
| 55 | if (response.data) { |
| 56 | // Accept response if status is true, or if response has data/result/url fields |
| 57 | if (response.data.status === true || |
| 58 | response.data.result || |
| 59 | response.data.data || |
| 60 | response.data.url || |
| 61 | response.data.download || |
| 62 | response.data.video) { |
nothing calls this directly
no test coverage detected