(sock: any, message: any, args: any, context: BotContext)
| 9 | usage: '.viewonce (reply to a view-once media)', |
| 10 | |
| 11 | async handler(sock: any, message: any, args: any, context: BotContext) { |
| 12 | const chatId = context.chatId || message.key.remoteJid; |
| 13 | |
| 14 | try { |
| 15 | const quoted = message.message?.extendedTextMessage?.contextInfo?.quotedMessage; |
| 16 | const quotedImage = quoted?.imageMessage; |
| 17 | const quotedVideo = quoted?.videoMessage; |
| 18 | |
| 19 | if (quotedImage && quotedImage.viewOnce) { |
| 20 | const stream = await downloadContentFromMessage(quotedImage, 'image'); |
| 21 | let buffer = Buffer.from([]); |
| 22 | for await (const chunk of stream) buffer = Buffer.concat([buffer, chunk]); |
| 23 | await sock.sendMessage(chatId, { |
| 24 | image: buffer, |
| 25 | fileName: 'media.jpg', |
| 26 | caption: quotedImage.caption || '' |
| 27 | }, { quoted: message }); |
| 28 | } |
| 29 | else if (quotedVideo && quotedVideo.viewOnce) { |
| 30 | const stream = await downloadContentFromMessage(quotedVideo, 'video'); |
| 31 | let buffer = Buffer.from([]); |
| 32 | for await (const chunk of stream) buffer = Buffer.concat([buffer, chunk]); |
| 33 | await sock.sendMessage(chatId, { |
| 34 | video: buffer, |
| 35 | fileName: 'media.mp4', |
| 36 | caption: quotedVideo.caption || '' |
| 37 | }, { quoted: message }); |
| 38 | } |
| 39 | else { |
| 40 | await sock.sendMessage(chatId, { |
| 41 | text: '*Please reply to a view-once image or video.*' |
| 42 | }, { quoted: message }); |
| 43 | } |
| 44 | |
| 45 | } catch(error: any) { |
| 46 | console.error('Error in viewonceCommand:', error); |
| 47 | await sock.sendMessage(chatId, { |
| 48 | text: '❌ Failed to retrieve the view-once media. Please try again later.' |
| 49 | }, { quoted: message }); |
| 50 | } |
| 51 | } |
| 52 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected