// code from goatstore // api: https://store.agi.bd const axios = require("axios"); const fs = require("fs"); const path = require("path"); const FormData = require("form-data"); module.exports = { config: { name: "telegraph", aliases: ["tg"], version: "1.0.3", author: "EryXenX", role: 0, shortDescription: "Upload media to Telegraph", longDescription: "Reply to an image under 5MB. Bypass BD IP block", category: "media", guide: "{pn} (reply to a photo)", cooldowns: 5 }, onStart: async function ({ api, event }) { const { threadID, messageID, type, messageReply } = event; if (type!== "message_reply" ||!messageReply ||!messageReply.attachments || messageReply.attachments.length === 0) { return api.sendMessage("Reply to a photo first. Max 5MB", threadID, messageID); } const attachment = messageReply.attachments[0]; if(attachment.type!== "photo" && attachment.type!== "animated_image"){ return api.sendMessage("Only photo and gif supported", threadID, messageID); } if(attachment.size > 5242880){ return api.sendMessage(`File too big. Size: ${(attachment.size/1024/1024).toFixed(2)}MB. Max 5MB`, threadID, messageID); } const cacheDir = path.join(__dirname, "cache"); if (!fs.existsSync(cacheDir)) fs.mkdirSync(cacheDir, { recursive: true }); const filePath = path.join(cacheDir, `tg_${Date.now()}.jpg`); try { api.sendMessage("Uploading to Telegraph...", threadID, messageID); // Step 1: FB theke buffer e namano const res = await axios.get(attachment.url, { responseType: "arraybuffer", headers: { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" } }); fs.writeFileSync(filePath, res.data); // Step 2: Telegraph e upload with headers const form = new FormData(); form.append("file", fs.createReadStream(filePath)); const upload = await axios.post("https://telegra.ph/upload", form, { headers: { ...form.getHeaders(), "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", "Referer": "https://telegra.ph", "Origin": "https://telegra.ph" }, timeout: 30000 }); fs.unlinkSync(filePath); if(upload.data[0].error){ return api.sendMessage("Telegraph Error: " + upload.data[0].error, threadID, messageID); } const link = `https://telegra.ph${upload.data[0].src}`; return api.sendMessage(`Upload Successful\nPermanent Link: ${link}`, threadID, messageID); } catch (err) { console.error("Telegraph Error:", err.message); if (fs.existsSync(filePath)) fs.unlinkSync(filePath); return api.sendMessage("Upload failed. telegra.ph still blocking. Try!catbox for now", threadID, messageID); } } };