soumyadeep/ReactItBotPublic · Bot Template

A Telegram bot that automatically replies to keywords with text or media in groups. Easy to set up and perfect for FAQs, community management, and automated responses.

ProfileTelegram
8 commands0 envUpdated 7h agoCreated Jun 7, 2026
Back to folder

commands/_.js

javascript · 206 lines

Raw
1/**#command2name: *3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12if (!msg) return;13if (!message) return;14if (chat.type == "private") return;15 16// ignore commands17if (message.startsWith("/")) return;18 19// ignore bots20if (user.is_bot) return;21 22let filters = Bot.get("filters_" + chat.id);23 24if (!filters) return;25 26let text = message27  .toLowerCase()28  .trim()29  .replace(/\s+/g, " ");30 31let matchedKey = null;32let filter = null;33 34// exact match first35if (filters[text]) {36  matchedKey = text;37  filter = filters[text];38}39 40// keyword match41if (!filter) {42 43  let keys = Object.keys(filters)44    .sort((a, b) => b.length - a.length);45 46  for (let key of keys) {47 48    let escaped = key.replace(49      /[.*+?^${}()|[\]\\]/g,50      "\\$&"51    );52 53    let regex = new RegExp(54      "(^|\\s|\\W)" +55      escaped +56      "(\\s|\\W|$)",57      "i"58    );59 60    if (regex.test(text)) {61      matchedKey = key;62      filter = filters[key];63      break;64    }65 66  }67 68}69 70if (!filter) return;71 72// cooldown per chat per keyword73let cdKey =74  "filter_cd_" +75  chat.id +76  "_" +77  matchedKey;78 79let lastRun = Bot.get(cdKey) || 0;80 81if (Date.now() - lastRun < 3000) {82  return;83}84 85Bot.set(cdKey, Date.now(), "number");86 87let textData = filter.text || filter.caption || "";88 89textData = textData90  .replace(/\{first_name\}/gi, user.first_name || "")91  .replace(/\{last_name\}/gi, user.last_name || "")92  .replace(93    /\{full_name\}/gi,94    ((user.first_name || "") + " " + (user.last_name || "")).trim()95  )96  .replace(97    /\{username\}/gi,98    user.username ? "@" + user.username : "N/A"99  )100  .replace(101    /\{mention\}/gi,102    user.username103      ? "@" + user.username104      : (user.first_name || "User")105  )106  .replace(/\{user_id\}/gi, String(user.id))107 108  .replace(/\{chat_id\}/gi, String(chat.id))109  .replace(/\{chat_title\}/gi, chat.title || "")110  .replace(/\{chat_type\}/gi, chat.type || "")111 112  .replace(/\{message\}/gi, message || "")113 114  .replace(/\{bot_name\}/gi, bot.name || "")115  .replace(/\{bot_id\}/gi, String(bot.bot_id || ""))116 117  .replace(/\{date\}/gi, new Date().toLocaleDateString())118  .replace(/\{time\}/gi, new Date().toLocaleTimeString());119 120let common = {121  chat_id: chat.id,122  reply_to_message_id: msg.message_id123};124 125switch (filter.type) {126 127  case "text":128 129    Api.sendMessage({130      ...common,131      text: textData,132      disable_web_page_preview: true133    });134 135    break;136 137  case "photo":138 139    Api.sendPhoto({140      ...common,141      photo: filter.file_id,142      caption: textData143    });144 145    break;146 147  case "video":148 149    Api.sendVideo({150      ...common,151      video: filter.file_id,152      caption: textData153    });154 155    break;156 157  case "document":158 159    Api.sendDocument({160      ...common,161      document: filter.file_id,162      caption: textData163    });164 165    break;166 167  case "audio":168 169    Api.sendAudio({170      ...common,171      audio: filter.file_id,172      caption: textData173    });174 175    break;176 177  case "voice":178 179    Api.sendVoice({180      ...common,181      voice: filter.file_id182    });183 184    break;185 186  case "sticker":187 188    Api.sendSticker({189      ...common,190      sticker: filter.file_id191    });192 193    break;194 195  case "animation":196 197    Api.sendAnimation({198      ...common,199      animation: filter.file_id,200      caption: textData201    });202 203    break;204 205}206