gks18977997/Sally_08_botPublic · Bot Template
AISally_08_bot appears to be a Telegram automation bot. Commands include /ai, /aii. Observed in code: messaging, http.
Utilityutility
2 commands1 envUpdated 1mo agoCreated Sep 25, 2026
commands/_aii.js
javascript · 221 lines
1/**#command2name: /aii3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12const apiKey = process.env.NVIDIA_API_KEY;13 14if (!apiKey) {15 Bot.sendMessage(16 "❌ Configuration Error\n\n" +17 "NVIDIA_API_KEY ENV variable nahi mila.\n" +18 "TeleBotHost ke ENV settings me check karo."19 );20 return;21}22 23// User ne kuch nahi likha24if (!params || !params.trim()) {25 Bot.sendMessage(26 "🧠 AI Chat\n\n" +27 "Use:\n" +28 "/ai hello\n\n" +29 "Example:\n" +30 "/ai Explain Cramer's Rule in simple Hindi"31 );32 return;33}34 35const userPrompt = params.trim();36 37// Apna exact NVIDIA model ID yahan rakho38const modelId = "z-ai/glm-5.3-flash";39 40// Maximum 3 attempts41const maxAttempts = 3;42 43// Har individual request ka timeout44// Free plan par 4000ms safe side par rakha hai.45const requestTimeout = 4000;46 47// Temporary errors par thoda wait48async function sleep(ms) {49 await new Promise(resolve => setTimeout(resolve, ms));50}51 52let lastResponse = null;53 54for (let attempt = 1; attempt <= maxAttempts; attempt++) {55 56 let response;57 58 try {59 60 response = await HTTP.post(61 "https://integrate.api.nvidia.com/v1/chat/completions",62 {63 headers: {64 "Authorization": "Bearer " + apiKey,65 "Content-Type": "application/json",66 "Accept": "application/json"67 },68 69 body: {70 model: modelId,71 72 messages: [73 {74 role: "system",75 content:76 "You are a helpful personal AI assistant. " +77 "Answer clearly, accurately and naturally. " +78 "Use simple Hindi or Hinglish when the user writes in Hindi/Hinglish."79 },80 {81 role: "user",82 content: userPrompt83 }84 ],85 86 temperature: 0.7,87 max_tokens: 1024,88 stream: false89 },90 91 timeout: requestTimeout,92 responseType: "json"93 }94 );95 96 } catch (e) {97 98 Bot.sendMessage(99 "⚠️ Request error\n\n" +100 "AI service se request bhejte waqt unexpected error aaya.\n" +101 "Please thodi der baad try karo."102 );103 104 return;105 }106 107 lastResponse = response;108 109 // ✅ Successful response110 if (response.ok) {111 112 const answer =113 response.data?.choices?.[0]?.message?.content;114 115 if (!answer) {116 Bot.sendMessage(117 "⚠️ AI ne response diya, lekin readable answer nahi mila."118 );119 return;120 }121 122 Bot.sendMessage(answer);123 return;124 }125 126 // Error details127 const status = response.status;128 const errorCode = response.error?.code;129 const errorMessage =130 response.error?.message || "";131 132 // 🔁 Retry-worthy temporary errors133 const isTemporary =134 status === 503 ||135 status === 502 ||136 status === 504 ||137 status === 429 ||138 status === 408 ||139 errorCode === "TIMEOUT";140 141 if (isTemporary && attempt < maxAttempts) {142 143 // Exponential-style small delay:144 // 1st retry -> 500ms145 // 2nd retry -> 1000ms146 const delay = attempt * 500;147 148 await sleep(delay);149 continue;150 }151 152 // ❌ Final error after retries153 if (status === 503) {154 155 Bot.sendMessage(156 "⚠️ NVIDIA AI temporarily unavailable.\n\n" +157 "Maine " + attempt + " attempt kiye, " +158 "lekin NVIDIA service ne 503 diya.\n\n" +159 "Thodi der baad dobara try karo."160 );161 return;162 }163 164 if (status === 429) {165 166 Bot.sendMessage(167 "⏳ NVIDIA API rate limit hit ho gayi.\n\n" +168 "Bahut zyada requests short time me aa gayi hain.\n" +169 "Thodi der baad dobara try karo."170 );171 return;172 }173 174 if (status === 408 || errorCode === "TIMEOUT") {175 176 Bot.sendMessage(177 "⏱️ NVIDIA request timeout ho gayi.\n\n" +178 "AI response time par nahi mila.\n" +179 "Shorter question bhejkar try karo."180 );181 return;182 }183 184 if (status === 401) {185 186 Bot.sendMessage(187 "🔐 NVIDIA API authentication error.\n\n" +188 "API key invalid/expired ho sakti hai.\n" +189 "NVIDIA_API_KEY ENV variable check karo."190 );191 return;192 }193 194 if (status === 403) {195 196 Bot.sendMessage(197 "🚫 NVIDIA API access denied.\n\n" +198 "API key, model access ya account permissions check karo."199 );200 return;201 }202 203 if (status === 404) {204 205 Bot.sendMessage(206 "❌ NVIDIA model/endpoint nahi mila.\n\n" +207 "Sabse pehle model ID check karo:\n" +208 modelId209 );210 return;211 }212 213 // Unknown error214 Bot.sendMessage(215 "❌ NVIDIA API Error\n\n" +216 "Status: " + status + "\n" +217 "Code: " + (errorCode || "unknown") + "\n" +218 "Message: " + (errorMessage || "No details available") +219 "\n\nPlease try again later."220 );221}