CREATORS/OnecreatorsbotPublic · Bot Template
AIThe bot manages a membership club called CREATORS. Users can apply for membership, view their status, and receive payment instructions. Administrators can approve or reject applications, set subscription prices, configure payment details, and review pending payments. The bot stores data in a database, sends notifications to users and admins, and handles payment receipts via photo or document uploads.
Commercemembershipsubscriptionpaymentsadmincreatortelegram
22 commands1 envUpdated 20d agoCreated Oct 6, 2026
commands/_handle_message.js
javascript · 282 lines
1/**#command2name: /handle_message3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12 13const m = update.message;14 15if (!m || !m.from) {16 return;17}18 19const userId = Number(m.from.id);20const adminId = Number(process.env.ADMIN_ID);21 22const awaitingReceipt = await db.user.get(23 "awaiting_payment_receipt",24 "no",25 { user_id: userId }26);27 28if (awaitingReceipt !== "yes") {29 return;30}31 32if (userId === adminId) {33 return;34}35 36// ذخیره نام و نام کاربری برای پرونده پرداخت37const senderName = [38 m.from.first_name,39 m.from.last_name40].filter(Boolean).join(" ");41 42const senderUsername = m.from.username43 ? "@" + m.from.username44 : "";45 46await db.user.set(47 "profile_name",48 senderName,49 { user_id: userId }50);51 52await db.user.set(53 "profile_username",54 senderUsername,55 { user_id: userId }56);57 58const selectedPlan = await db.user.get(59 "selected_plan",60 "",61 { user_id: userId }62);63 64const planName =65 selectedPlan === "weekly" ? "هفتگی" :66 selectedPlan === "monthly" ? "ماهانه" :67 "نامشخص";68 69const selectedPrice = Number(await db.user.get(70 "selected_plan_price",71 "0",72 { user_id: userId }73));74 75const selectedDuration = Number(await db.user.get(76 "selected_plan_duration",77 "0",78 { user_id: userId }79));80 81// دریافت رسید تصویری82if (m.photo && m.photo.length > 0) {83 const photoId = m.photo[m.photo.length - 1].file_id;84 const photoReceiptId =85 "PAY-" + userId + "-" + Date.now();86 87 await db.user.set(88 "pending_payment_receipt",89 {90 receipt_id: photoReceiptId,91 type: "photo",92 file_id: photoId,93 file_name: "",94 plan: selectedPlan,95 price: selectedPrice,96 duration: selectedDuration,97 submitted_at: new Date().toISOString(),98 text: ""99 },100 { user_id: userId }101 );102 103 await Api.sendPhoto({104 chat_id: adminId,105 photo: photoId,106 caption:107 "📷 رسید تصویری پرداخت\n\n" +108 "🆔 شناسه تلگرام: " + userId + "\n" +109 "👤 نام: " + (senderName || "ثبت نشده") + "\n" +110 "🔹 نام کاربری: " + (senderUsername || "ثبت نشده") + "\n" +111 "👑 طرح انتخابی: " + planName + "\n" +112 "💰 مبلغ ثبتشده: " + selectedPrice.toLocaleString("en-US") + " تومان",113 reply_markup: {114 inline_keyboard: [[115 {116 text: "✅ تأیید پرداخت",117 callback_data: "payapprove_" + userId118 },119 {120 text: "❌ رد پرداخت",121 callback_data: "payreject_" + userId122 }123 ]]124 }125 });126 127 await db.user.set(128 "payment_review_status",129 "pending",130 { user_id: userId }131 );132 133 await Api.sendMessage({134 chat_id: m.chat.id,135 text:136 "✅ عکس رسید ارسال شد و در انتظار بررسی مدیر است.\n\n" +137 "پس از بررسی و تأیید پرداخت، نتیجه به شما اعلام میشود."138 });139 140 await db.user.set(141 "awaiting_payment_receipt",142 "no",143 { user_id: userId }144 );145 146 return;147}148 149// دریافت فایل رسید150if (m.document) {151 const documentReceiptId =152 "PAY-" + userId + "-" + Date.now();153 154 await db.user.set(155 "pending_payment_receipt",156 {157 receipt_id: documentReceiptId,158 type: "document",159 file_id: m.document.file_id,160 file_name: m.document.file_name || "",161 plan: selectedPlan,162 price: selectedPrice,163 duration: selectedDuration,164 submitted_at: new Date().toISOString(),165 text: ""166 },167 { user_id: userId }168 );169 170 await Api.sendDocument({171 chat_id: adminId,172 document: m.document.file_id,173 caption:174 "📄 فایل رسید پرداخت\n\n" +175 "🆔 شناسه تلگرام: " + userId + "\n" +176 "👤 نام: " + (senderName || "ثبت نشده") + "\n" +177 "🔹 نام کاربری: " + (senderUsername || "ثبت نشده") + "\n" +178 "👑 طرح انتخابی: " + planName + "\n" +179 "💰 مبلغ ثبتشده: " + selectedPrice.toLocaleString("en-US") + " تومان\n" +180 "📎 نام فایل: " + (m.document.file_name || "بدون نام"),181 reply_markup: {182 inline_keyboard: [[183 {184 text: "✅ تأیید پرداخت",185 callback_data: "payapprove_" + userId186 },187 {188 text: "❌ رد پرداخت",189 callback_data: "payreject_" + userId190 }191 ]]192 }193 });194 195 await db.user.set(196 "payment_review_status",197 "pending",198 { user_id: userId }199 );200 201 await Api.sendMessage({202 chat_id: m.chat.id,203 text:204 "✅ فایل رسید ارسال شد و در انتظار بررسی مدیر است.\n\n" +205 "پس از بررسی و تأیید پرداخت، نتیجه به شما اعلام میشود."206 });207 208 await db.user.set(209 "awaiting_payment_receipt",210 "no",211 { user_id: userId }212 );213 214 return;215}216 217// دریافت رسید متنی218if (m.text) {219 const textReceiptId =220 "PAY-" + userId + "-" + Date.now();221 222 await db.user.set(223 "pending_payment_receipt",224 {225 receipt_id: textReceiptId,226 type: "text",227 file_id: "",228 file_name: "",229 plan: selectedPlan,230 price: selectedPrice,231 duration: selectedDuration,232 submitted_at: new Date().toISOString(),233 text: m.text234 },235 { user_id: userId }236 );237 238 await Api.sendMessage({239 chat_id: adminId,240 text:241 "📩 پیام متنی رسید پرداخت\n\n" +242 "🆔 شناسه تلگرام: " + userId + "\n" +243 "👤 نام: " + (senderName || "ثبت نشده") + "\n" +244 "🔹 نام کاربری: " + (senderUsername || "ثبت نشده") + "\n" +245 "👑 طرح انتخابی: " + planName + "\n" +246 "💰 مبلغ ثبتشده: " + selectedPrice.toLocaleString("en-US") + " تومان\n\n" +247 "📝 متن ارسالی:\n" + m.text,248 reply_markup: {249 inline_keyboard: [[250 {251 text: "✅ تأیید پرداخت",252 callback_data: "payapprove_" + userId253 },254 {255 text: "❌ رد پرداخت",256 callback_data: "payreject_" + userId257 }258 ]]259 }260 });261 262 await db.user.set(263 "payment_review_status",264 "pending",265 { user_id: userId }266 );267 268 await Api.sendMessage({269 chat_id: m.chat.id,270 text:271 "✅ پیام رسید ارسال شد و در انتظار بررسی مدیر است.\n\n" +272 "پس از بررسی و تأیید پرداخت، نتیجه به شما اعلام میشود."273 });274 275 await db.user.set(276 "awaiting_payment_receipt",277 "no",278 { user_id: userId }279 );280 281 return;282}