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