(sock, chatId, message)
| 2 | const fetch = require('node-fetch'); |
| 3 | |
| 4 | async function aiCommand(sock, chatId, message) { |
| 5 | try { |
| 6 | const text = message.message?.conversation || message.message?.extendedTextMessage?.text; |
| 7 | |
| 8 | if (!text) { |
| 9 | return await sock.sendMessage(chatId, { |
| 10 | text: "Please provide a question after .gpt or .gemini\n\nExample: .gpt write a basic html code" |
| 11 | }, { |
| 12 | quoted: message |
| 13 | }); |
| 14 | } |
| 15 | |
| 16 | // Get the command and query |
| 17 | const parts = text.split(' '); |
| 18 | const command = parts[0].toLowerCase(); |
| 19 | const query = parts.slice(1).join(' ').trim(); |
| 20 | |
| 21 | if (!query) { |
| 22 | return await sock.sendMessage(chatId, { |
| 23 | text: "Please provide a question after .gpt or .gemini" |
| 24 | }, {quoted:message}); |
| 25 | } |
| 26 | |
| 27 | try { |
| 28 | // Show processing message |
| 29 | await sock.sendMessage(chatId, { |
| 30 | react: { text: '🤖', key: message.key } |
| 31 | }); |
| 32 | |
| 33 | if (command === '.gpt') { |
| 34 | // Call the GPT API |
| 35 | const response = await axios.get(`https://zellapi.autos/ai/chatbot?text=${encodeURIComponent(query)}`); |
| 36 | |
| 37 | if (response.data && response.data.status && response.data.result) { |
| 38 | const answer = response.data.result; |
| 39 | await sock.sendMessage(chatId, { |
| 40 | text: answer |
| 41 | }, { |
| 42 | quoted: message |
| 43 | }); |
| 44 | |
| 45 | } else { |
| 46 | throw new Error('Invalid response from API'); |
| 47 | } |
| 48 | } else if (command === '.gemini') { |
| 49 | const apis = [ |
| 50 | `https://vapis.my.id/api/gemini?q=${encodeURIComponent(query)}`, |
| 51 | `https://api.siputzx.my.id/api/ai/gemini-pro?content=${encodeURIComponent(query)}`, |
| 52 | `https://api.ryzendesu.vip/api/ai/gemini?text=${encodeURIComponent(query)}`, |
| 53 | `https://zellapi.autos/ai/chatbot?text=${encodeURIComponent(query)}`, |
| 54 | `https://api.giftedtech.my.id/api/ai/geminiai?apikey=gifted&q=${encodeURIComponent(query)}`, |
| 55 | `https://api.giftedtech.my.id/api/ai/geminiaipro?apikey=gifted&q=${encodeURIComponent(query)}` |
| 56 | ]; |
| 57 | |
| 58 | for (const api of apis) { |
| 59 | try { |
| 60 | const response = await fetch(api); |
| 61 | const data = await response.json(); |
nothing calls this directly
no outgoing calls
no test coverage detected