Skip to content

Instantly share code, notes, and snippets.

@mifyow
Created October 25, 2025 11:31
Show Gist options
  • Select an option

  • Save mifyow/3f2a42d29e4e771c5ae15ca6cb913ad8 to your computer and use it in GitHub Desktop.

Select an option

Save mifyow/3f2a42d29e4e771c5ae15ca6cb913ad8 to your computer and use it in GitHub Desktop.
Uploaded via mifMD
import fetch from "node-fetch"
export default {
name: "ocr",
category: "tools",
command: ["ocr", "readtext"],
settings: { owner: false },
run: async (conn, m) => {
try {
const q = m.quoted ? m.quoted : m
const mime =
(q.msg || q).mimetype ||
q.mimetype ||
q.message?.imageMessage?.mimetype
if (!mime || !/image/.test(mime))
return m.reply("⚠️ Kirim atau reply gambar dengan caption *ocr* untuk ekstrak teks.")
await conn.sendMessage(m.chat, { react: { text: "⏳", key: m.key } })
const buffer = await q.download()
const mimeType = /png/.test(mime) ? "image/png" : "image/jpeg"
const imageBase64 = buffer.toString("base64")
const url = "https://staging-ai-image-ocr-266i.frontend.encr.app/api/ocr/process"
const res = await fetch(url, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ imageBase64, mimeType }),
})
if (!res.ok) throw new Error(await res.text())
const json = await res.json()
const text = json.extractedText || "Teks tidak ditemukan."
await m.reply(`📄 *Hasil OCR:*\n\n${text}`)
await conn.sendMessage(m.chat, { react: { text: "✅", key: m.key } })
} catch (err) {
console.error(err)
await m.reply("❌ Gagal melakukan OCR, coba lagi nanti.")
await conn.sendMessage(m.chat, { react: { text: "❌", key: m.key } })
}
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment