@covenants/sdk
v3.2.0
Published
Official SDK for Covenant API — dynamic typed client, Baileys bot wrapper, and utilities
Downloads
178
Maintainers
Readme
@covenants/sdk
Official SDK for Covenant API — typed API client, full WhatsApp bot wrapper (Baileys), and 110+ utility functions.
Install
npm install @covenants/sdkNode.js >= 18 required. ESM (
"type": "module"di package.json).
Sub-path Exports
| Import | Isi |
|---|---|
| @covenants/sdk | Semua exports |
| @covenants/sdk/api | CovenantClient — typed REST API client |
| @covenants/sdk/bot | CovenantBot, createPlugin, initSDK, getCooldown |
| @covenants/sdk/utils | fmt, math, arr, obj, validate, str, color, time, Cooldown, RateLimiter, EventBus |
Quick Start — API Client
import { CovenantClient } from "@covenants/sdk";
const client = new CovenantClient({ apiKey: process.env.COVENANT_API_KEY });
// Download TikTok
const video = await client.downloader.tiktok({ url, hd: true });
// Generate gambar AI
const img = await client.canvas.brat({ text: "very demure", emojiStyle: "apple" });
// Screenshot web
const ss = await client.tools.ssweb({ url: "https://github.com", darkMode: true });
// Statistik API key
const stats = await client.profile();
console.log(stats.usage.remaining); // sisa creditsQuick Start — WhatsApp Bot (Baileys)
Setup
import { CovenantBot, initSDK, createPlugin } from "@covenants/sdk/bot";
// 1. Init SDK
initSDK({ apiKey: process.env.COVENANT_API_KEY });
// 2. Buat bot
const bot = new CovenantBot({
dbPath: "/data.db",
pairingNumber: "628123456789",
verbose: false,
});
// 3. Handle events
bot.on("pairing", (code) => console.log("Pairing code:", code));
bot.on("ready", (conn) => console.log("Bot siap!"));
bot.on("message", (msg, conn) => {
// handle pesan masuk
});
// 4. Start
await bot.start();CovenantBot — Methods
Kirim Pesan
// Teks
await bot.sendText(jid, "Halo!");
// Gambar (URL, Buffer, atau path)
await bot.sendImage(jid, "https://...", { caption: "Foto keren" });
// Video
await bot.sendVideo(jid, buffer, { caption: "Video", quoted: msg });
// Audio / Voice note
await bot.sendAudio(jid, audioBuffer, { ptt: true });
// Dokumen
await bot.sendDocument(jid, pdfBuffer, "laporan.pdf", "application/pdf");
// Stiker
await bot.sendSticker(jid, stickerBuffer);
// Lokasi
await bot.sendLocation(jid, -6.2088, 106.8456, { name: "Jakarta" });
// Kontak
await bot.sendContact(jid, [{ fullName: "Budi", phoneNumber: "628123456789" }]);
// Poll
await bot.sendPoll(jid, "Pilih warna?", ["Merah", "Biru", "Hijau"]);
// React ke pesan
await bot.sendReaction(jid, msg.key, "❤️");
// Hapus react
await bot.removeReaction(jid, msg.key);Aksi Pesan
// Hapus pesan (untuk semua)
await bot.deleteMessage(jid, msg.key);
// Edit pesan
await bot.editMessage(jid, msg.key, "Teks baru");
// Pin pesan
await bot.pinMessage(jid, msg.key);
// Tandai sudah dibaca
await bot.readMessages([msg.key]);
// Update presence (typing, recording)
await bot.sendPresence(jid, "composing");
// Forward pesan
await bot.forwardMessage(targetJid, msg);
// Download media dari pesan
const buffer = await bot.downloadMedia(msg);Manajemen Grup
// Buat grup
const { id } = await bot.createGroup("Nama Grup", ["[email protected]"]);
// Update nama & deskripsi
await bot.updateGroupSubject(jid, "Nama Baru");
await bot.updateGroupDescription(jid, "Deskripsi grup");
// Tambah/keluarkan member
await bot.addGroupParticipants(jid, ["[email protected]"]);
await bot.removeGroupParticipants(jid, ["[email protected]"]);
// Promote/demote admin
await bot.promoteGroupParticipants(jid, ["[email protected]"]);
await bot.demoteGroupParticipants(jid, ["[email protected]"]);
// Pengaturan grup
await bot.updateGroupSetting(jid, "announcement"); // only admins send
await bot.updateGroupSetting(jid, "not_announcement"); // semua bisa send
// Keluar grup
await bot.leaveGroup(jid);
// Metadata & invite link
const meta = await bot.getGroupMetadata(jid);
const link = await bot.getGroupInviteLink(jid);
await bot.revokeGroupInviteLink(jid);
await bot.joinGroupViaLink("https://chat.whatsapp.com/XXX");Profil & Akun
// Ambil foto profil
const url = await bot.getProfilePicture(jid, true); // true = high-res
// Update profil bot
await bot.updateProfilePicture(imageBuffer);
await bot.updateProfileName("Nama Bot");
await bot.updateStatus("Bot siap 24/7");
// Fetch status user lain
const status = await bot.fetchStatus(jid);
// Block/unblock
await bot.updateBlockStatus(jid, true);Manajemen Chat
await bot.archiveChat(jid, true);
await bot.muteChat(jid, Date.now() + 8 * 3600 * 1000); // mute 8 jam
await bot.markChatRead(jid, true);
await bot.deleteChat(jid);Helper Statis
// Format nomor ke JID
CovenantBot.toJid("628123456789") // "[email protected]"
CovenantBot.toJid("1234567890", true) // "[email protected]" (grup)
// Extract nomor dari JID
CovenantBot.fromJid("[email protected]") // "628xxx"
// Cek apakah grup
CovenantBot.isGroup("[email protected]") // true
CovenantBot.isGroup("[email protected]") // falseEvents
bot.on("init", (conn) => {}); // socket dibuat
bot.on("connecting", () => {}); // sedang konek
bot.on("ready", (conn) => {}); // terhubung & siap
bot.on("pairing", (code) => {}); // pairing code
bot.on("message", (msg, conn) => {}); // pesan masuk baru
bot.on("message-delete", (key) => {}); // pesan dihapus
bot.on("message-reaction",(reaction) => {}); // pesan di-react
bot.on("presence", (jid, update) => {}); // update typing/online
bot.on("group-update", (update) => {}); // update grup
bot.on("reconnect", (conn, reason) => {}); // reconnect
bot.on("logout", () => {}); // logged out
bot.on("bad-session", () => {}); // session rusak
bot.on("error", (err) => {}); // error
bot.on("close", () => {}); // bot berhenticreatePlugin (Yuki-js Integration)
import { createPlugin, getCooldown } from "@covenants/sdk/bot";
export default createPlugin({
cmd: ["cuaca"],
tags: ["public"],
usePrefix: true,
exec: async (m, { api, fmt, text: txt }) => {
const cd = getCooldown("cuaca", 10_000);
const wait = cd.touch(m.sender);
if (wait > 0) return m.reply(`⏳ Tunggu ${Math.ceil(wait / 1000)}s lagi.`);
const city = txt || "Jakarta";
const data = await api.weather.current({ city });
m.reply(`🌤 *${data.location.city}*\n${data.temperature.celsius}°C — ${data.condition.description}`);
},
});Utility Functions (110+)
import { fmt, math, arr, obj, validate, str, color, time } from "@covenants/sdk";
fmt.bytes(1536) // "1.5 KB"
fmt.currency(25000) // "Rp 25.000"
math.clamp(15, 0, 10) // 10
arr.chunk([1,2,3,4,5], 2) // [[1,2],[3,4],[5]]
validate.isEmail("[email protected]") // true
str.slug("Hello World!") // "hello-world"
color.isDark("#0a0a0a") // true
time.addDays(new Date(), 7) // date + 7 hariLinks
- Docs: covenant.sbs/sdk
- Dashboard: app.covenant.sbs
- Register: app.covenant.sbs/register (1000 credits gratis)
MIT License — Built by Covenant Team
