adityajat/SaarvamAI_botPublic · Bot Template

ProfileTelegram

AISarvam AI is a multi‑purpose Telegram bot that lets users ask questions, get explanations, convert text to speech, and translate messages using the Sarvam AI API. It also offers group administration commands such as warn, mute, ban, pin, delete, and announcements, and can clear personal or group AI memory. The bot uses the TeleBotHost TBL framework with Bot, Api, db, and HTTP calls, and provides inline keyboards for language and voice selection.

Ai Assistantaivoicetranslatemoderationadminsarvam
34 commands4 envUpdated 15d agoCreated Sep 14, 2026
Back to folder

commands/_ask.js

javascript · 72 lines

Raw
1/**#command2name: /ask3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12let key = process.env.SARVAM_API_KEY;13 14if (!key) {15  Api.sendMessage({16    text: "❌ SARVAM_API_KEY was not found."17  });18  return;19}20 21if (!params || !params.trim()) {22  Api.sendMessage({23    text: "Please ask me something.\n\nExample:\n/ask What is democracy?"24  });25  return;26}27 28let res = await HTTP.post("https://api.sarvam.ai/v1/chat/completions", {29  headers: {30    "api-subscription-key": key31  },32  body: {33    model: "sarvam-105b",34    messages: [35      {36        role: "user",37        content: params.trim()38      }39    ],40    max_tokens: 500,41    reasoning_effort: null42  },43  responseType: "json",44  timeout: 1400045});46 47if (!res.ok) {48  Api.sendMessage({49    text: "❌ Sarvam API error: " + res.status50  });51  return;52}53 54let answer = res.data.choices[0].message.content;55 56if (!answer || !answer.trim()) {57  Api.sendMessage({58    text: "❌ Sarvam returned an empty response."59  });60  return;61}62 63/* Remove Markdown formatting */64answer = answer65  .replace(/\*\*/g, "")66  .replace(/\*/g, "")67  .replace(/__/g, "")68  .replace(/`/g, "");69 70Api.sendMessage({71  text: answer.trim()72});