(sock: any, message: any, args: any, context: BotContext)
| 8 | usage: '.tinyurl <url>', |
| 9 | |
| 10 | async handler(sock: any, message: any, args: any, context: BotContext) { |
| 11 | const chatId = context.chatId || message.key.remoteJid; |
| 12 | const query = args?.join(' ')?.trim(); |
| 13 | |
| 14 | if (!query) { |
| 15 | return await sock.sendMessage(chatId, { text: '*Please provide a URL to shorten.*\nExample: .tinyurl https://example.com' }, { quoted: message }); |
| 16 | } |
| 17 | |
| 18 | try { |
| 19 | const response = await fetch(`https://tinyurl.com/api-create.php?url=${encodeURIComponent(query)}`); |
| 20 | const shortUrl = await response.text(); |
| 21 | |
| 22 | if (!shortUrl) { |
| 23 | return await sock.sendMessage(chatId, { text: '❌ Error: Could not generate a short URL.' }, { quoted: message }); |
| 24 | } |
| 25 | |
| 26 | const output = |
| 27 | `✨ *YOUR SHORT URL*\n\n` + |
| 28 | `🔗 *Original Link:*\n${query}\n\n` + |
| 29 | `✂️ *Shortened URL:*\n${shortUrl}`; |
| 30 | |
| 31 | await sock.sendMessage(chatId, { text: output }, { quoted: message }); |
| 32 | |
| 33 | } catch(err: any) { |
| 34 | console.error('TinyURL plugin error:', err); |
| 35 | await sock.sendMessage(chatId, { text: '❌ Failed to shorten URL.' }, { quoted: message }); |
| 36 | }} |
| 37 | }; |
| 38 |
nothing calls this directly
no outgoing calls
no test coverage detected