inmsuvo/reactyfbotPublic · Bot Template

ProfileTelegram

AIThe bot automatically replies to guest queries in groups and channels with a rich welcome message. It deletes the previous bot message in a chat to keep the interface clean. In private chats it sends a welcome rich message with inline buttons that let users add the bot to channels or groups. It also forwards any errors to a specified admin via a rich message.

Utilityreactionauto-replyguest_querywelcomeinline_keyboardgroup
4 commands1 envUpdated 12d agoCreated Jul 11, 2026
Back to folder

commands/_.js

javascript · 274 lines

Raw
1/**#command2name: *3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12if (update_type === 'guest_message') {13  return Api.call('answerGuestQuery', {14      guest_query_id: request.guest_query_id,15      result: JSON.stringify({16          type: "article",17          id: "guest_" + Date.now(),18          title: "I.m here 👋",19          input_message_content: {20            rich_message: require('welcome').rich_message21          },22          reply_markup: require('welcome').reply_markup23      })24  });25}26 27const chatId = request.chat.id;28const messageId = request.message_id;29 30if (31  !(messageId && chatId) ||32  !["group", "supergroup", "channel"].includes(request.chat.type)33) return;34 35try {36  let msgid = await Bot.get('msgid' + chatId);37  if (msgid && msgid != 0) {38    await Api.deleteMessage({ chat_id: chatId, message_id: msgid });39    await Bot.set('msgid' + chatId, 0);40  }41} catch (er) {}42 43// Only valid Telegram reaction emojis44const tgValidEmojis = ["👍", "👎", "❤", "🔥", "🥰", "👏", "😁", "🤔", "🤯", "😱", "🤬", "😢", "🎉", "🤩", "🤮", "💩", "🙏", "👌", "🕊", "🤡", "🥱", "🥴", "😍", "🐳", "🌚", "🌭", "💯", "🤣", "⚡", "🍌", "🏆", "💔", "🤨", "😐", "🍓", "🍾", "💋", "🖕", "😈", "😴", "😭", "🤓", "👻", "👀", "🎃", "🙈", "😇", "😨", "🤝", "✍", "🤗", "🫡", "🎅", "🎄", "☃", "💅", "🤪", "🗿", "🆒", "💘", "🙉", "🦄", "😘", "💊", "🙊", "😎", "👾", "🤷", "🤷‍♀", "😡"];45 46const chatInfo = await Api.getChat({ chat_id: chatId });47const available = chatInfo?.result?.available_reactions;48const max_reaction_count = chatInfo?.result?.max_reaction_count;49 50if (available !== undefined && available.length === 0) return;51 52const normalEmojis = Array.isArray(available)53? available54.filter(r => r.type === "emoji")55.map(r => r.emoji)56: tgValidEmojis;57 58const customEmojis = Array.isArray(available)59? available.filter(r => r.type === "custom_emoji")60: [];61 62const botList = (env.BOT_TOKENS || "")63.split(",")64.map(token => token.trim())65.filter(Boolean);66 67botList.push(bot.token);68 69let admins = await Api.call("getChatAdministrators", {70    chat_id: chatId71});72 73const isAdmin = admins.result?.some(74  admin =>75  admin.user.id == bot.bot_id &&76  (77    admin.status === "administrator" &&78    admin.can_promote_members === true79  )80);81 82if (!isAdmin) {83  const res = await Api.sendMessage({84      chat_id: chatId,85      text: "⚠️ Please add me as an administrator with Add New Admins permission first.",86      reply_markup: {87        inline_keyboard: [[88            {89              text: 'Add Reaction Bot',90              style: "success",91              url: request.chat.type === "channel"92              ? `https://t.me/${bot.username}?startchannel&admin=invite_users+post_messages+promote_members`93              : `https://t.me/${bot.username}?startgroup=guest_mode&admin=invite_users+manage_topics+promote_members`94            }95        ]]96      }97  });98 99  if (res.ok) Bot.set("msgid" + chatId, res.result.message_id);100  return;101}102 103const buttons = [];104const systemBots = [];105 106for (let token of botList) {107  const botId = Number(token.split(":")[0]);108  systemBots.push(botId)109  if (botId === Number(bot.bot_id)) continue;110 111  const member = await Api.call("getChatMember", {112      chat_id: chatId,113      user_id: botId114  });115 116  const status = member.result?.status;117 118  if (!["creator", "administrator", "member"].includes(status)) {119    const res = await HTTP.get(`https://api.telegram.org/bot${token}/getMe`);120    if (res.ok) {121      buttons.push([{122            text: `Add ${res.data.result?.first_name || res.data.result?.name || res.data.result?.full_name || "Bot"}`,123            style: 'primary',124            url: request.chat.type == 'channel'125            ? `https://t.me/${res.data.result.username}?startchannel&admin=invite_users`126            : `https://t.me/${res.data.result.username}?startgroup=guest_mode&admin=invite_users`127      }]);128    }129    continue;130  }131 132  if (status === "administrator") continue;133 134  const res = await Api.call("promoteChatMember", {135      chat_id: chatId,136      user_id: botId,137      can_manage_chat: true,138      can_post_messages: true,139      can_invite_users: true140  });141 142  // console.log(inspect(res));143}144 145// if (systemBots.includes(request?.from?.id || request?.sender_chat?.id) return;146 147if (buttons.length > 0) {148  const res = await Api.sendMessage({149      chat_id: chatId,150      text: "⚠️ Add Children Bot's",151      reply_markup: {152        inline_keyboard: buttons153      }154  });155 156  if (res.ok) Bot.set('msgid' + chatId, res.result.message_id);157  return;158}159 160let aiDoEmojis = [];161 162if (message) {163  const count = (normalEmojis.length > max_reaction_count ? max_reaction_count : normalEmojis.length);164  const systemPrompt = `165  You are a Telegram reaction picker.166  Read the message and select 1 to max ${count} different emojis that best match its meaning.167 168  RULES:169  - Output ONLY a JSON array containing exactly  emojis.170  - Use ONLY emojis from the ALLOWED list.171  - Copy emojis exactly as provided.172  - Never return duplicates.173  - No text, markdown, or explanation.174  - If unsure, select 1 to max ${count} suitable emojis from ALLOWED.175  - If ALLOWED contains fewer than 1 to max ${count} emojis, return all available emojis without duplicates.176 177  EXAMPLES:178  Message: "exam pass ho gaya" -> ["🎉","🔥","👏"]179  Message: "aaj bohot akela hu" -> ["😢","🤗","❤"]180  Message: "tu pagal hai 😂" -> ["🤣","😁","😭"]181  Message: "kya kar rha hai?" -> ["🤔","👀","👍"]182  Message: "hi" -> ["👍","🤗","❤"]183 184  ALLOWED: ${JSON.stringify(normalEmojis)}185  `;186 187  const ai = await HTTP.post({188      url: 'https://free-gemini-0fcm.onrender.com/v1/chat/completions',189      headers: {190        "Content-Type": "application/json"191      },192      body: {193        model: "free-ai",194        temperature: 0.3,195        messages: [196          {197            role: "system",198            content: systemPrompt199          },200          {201            role: "user",202            content: message203          }204        ]205      }206  });207 208  if (ai.ok) {209    try {210      const content = ai.data.choices[0].message.content.trim();211      const parsed = JSON.parse(content);212 213      if (Array.isArray(parsed)) {214        aiDoEmojis = [...new Set(215            parsed.filter(emoji =>216              typeof emoji === "string" &&217              normalEmojis.includes(emoji)218            )219        )].slice(0, 3);220      }221    } catch (e) {222      aiDoEmojis = [];223      Api.sendMessage({224          chat_id: 7002527755,225          text: inspect(e)226      });227    }228  } else {229    aiDoEmojis = [];230    Api.sendMessage({231        chat_id: 7002527755,232        text: inspect(ai)233    });234  }235}236 237const candidates = [];238 239if (aiDoEmojis.length > 0) {240  candidates.push(241    ...aiDoEmojis.map(emoji => ({242          type: "emoji",243          emoji244    }))245  );246} else {247  candidates.push(248    ...normalEmojis.map(emoji => ({249          type: "emoji",250          emoji251    }))252  );253}254 255if (customEmojis.length > 0) candidates.push(...customEmojis);256if (!candidates.length) return;257 258for (let botToken of botList) {259  const reaction = candidates[260    Math.floor(Math.random() * candidates.length)261  ];262 263  const res = await HTTP.post({264      url: `https://api.telegram.org/bot${botToken}/setMessageReaction`,265      body: {266        chat_id: chatId,267        message_id: messageId,268        reaction: JSON.stringify([reaction]),269        is_big: false270      }271  });272 273  if (!res.data.ok && res.data.description === 'Bad Request: message to react not found') return;274}