(sock: any, message: any, args: any, context: BotContext)
| 9 | usage: '.pair 92305395XXXX', |
| 10 | |
| 11 | async handler(sock: any, message: any, args: any, context: BotContext) { |
| 12 | const { chatId } = context; |
| 13 | |
| 14 | const forwardInfo = { |
| 15 | forwardingScore: 1, |
| 16 | isForwarded: true, |
| 17 | forwardedNewsletterMessageInfo: { |
| 18 | newsletterJid: '120363319098372999@newsletter', |
| 19 | newsletterName: 'MEGA MD', |
| 20 | serverMessageId: -1 |
| 21 | } |
| 22 | }; |
| 23 | |
| 24 | const query = args.join('').trim(); |
| 25 | if (!query) { |
| 26 | return await sock.sendMessage(chatId, { |
| 27 | text: "❌ *Missing Number*\nExample: .pair 92305395XXXX", |
| 28 | contextInfo: forwardInfo |
| 29 | }, { quoted: message }); |
| 30 | } |
| 31 | |
| 32 | const number = query.replace(/[^0-9]/g, ''); |
| 33 | |
| 34 | if (number.length < 10 || number.length > 15) { |
| 35 | return await sock.sendMessage(chatId, { |
| 36 | text: "❌ *Invalid Format*\nPlease provide the number with country code but without + or spaces.", |
| 37 | contextInfo: forwardInfo |
| 38 | }, { quoted: message }); |
| 39 | } |
| 40 | |
| 41 | await sock.sendMessage(chatId, { |
| 42 | text: "⚡ *Requesting code from server...*", |
| 43 | contextInfo: forwardInfo |
| 44 | }, { quoted: message }); |
| 45 | |
| 46 | try { |
| 47 | const response = await axios.get(`https://mega-pairing.onrender.com/pair?number=${number}`, { |
| 48 | timeout: 60000 |
| 49 | }); |
| 50 | |
| 51 | if (response.data && response.data.code) { |
| 52 | const pairingCode = response.data.code; |
| 53 | |
| 54 | if (pairingCode.includes("Unavailable") || pairingCode.includes("Error")) { |
| 55 | throw new Error("Server is busy"); |
| 56 | } |
| 57 | |
| 58 | const successText = `✅ *MEGA-MD PAIRING CODE*\n\n` + |
| 59 | `Code: *${pairingCode}*\n\n` + |
| 60 | `*How to use:*\n` + |
| 61 | `1. Open WhatsApp Settings\n` + |
| 62 | `2. Tap 'Linked Devices'\n` + |
| 63 | `3. Tap 'Link a Device'\n` + |
| 64 | `4. Select 'Link with phone number instead'\n` + |
| 65 | `5. Enter the code above.`; |
| 66 | |
| 67 | await sock.sendMessage(chatId, { |
| 68 | text: successText, |
nothing calls this directly
no outgoing calls
no test coverage detected