UNPKG

tgram.js

Version:

Lightweight modern library for telegram bot. use Node.js

30 lines (27 loc) 939 B
import telegramFetch from "../utility/telegram-fetch.js"; import FormData from "form-data"; /** * Kirim dokumen (file_id, URL, atau Buffer) * @param {string} token * @param {number|string} chatId * @param {string|Buffer} document * @param {string} [filename] — hanya untuk Buffer * @param {string} caption - Options */ export async function sendDocument(token, chatId, document, filename = "file.txt", caption) { if (Buffer.isBuffer(document)) { const form = new FormData(); if (caption) form.append("caption", caption) form.append("chat_id", chatId); form.append("document", document, { filename }); return telegramFetch.post(`https://api.telegram.org/bot${token}/sendDocument`, form, { headers: form.getHeaders() }); } // If document URL Or File_Id return telegramFetch.post(`https://api.telegram.org/bot${token}/sendDocument`, { chat_id: chatId, document, caption }); }