We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/loglux/whatsapp-mcp-stream'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
import { webcrypto } from "crypto";
import fs from "fs";
import pino from "pino";
import makeWASocket, {
Browsers,
fetchLatestBaileysVersion,
useMultiFileAuthState,
} from "baileys";
export class BaileysClient {
private sock: any | null = null;
private sessionDir: string;
constructor(sessionDir: string) {
this.sessionDir = sessionDir;
if (!(globalThis as any).crypto) {
(globalThis as any).crypto = webcrypto;
}
}
async initialize(getMessage?: (key: any) => Promise<any> | any): Promise<void> {
fs.mkdirSync(this.sessionDir, { recursive: true });
const { state, saveCreds } = await useMultiFileAuthState(this.sessionDir);
const { version } = await fetchLatestBaileysVersion();
const logLevel = process.env.BAILEYS_LOG_LEVEL || "silent";
const logger = (pino as unknown as (opts: any) => any)({ level: logLevel });
this.sock = makeWASocket({
version,
auth: state,
printQRInTerminal: false,
logger,
syncFullHistory: true,
browser: Browsers.macOS("Desktop"),
getMessage: async (key: any) => (getMessage ? await getMessage(key) : undefined),
});
this.sock.ev.on("creds.update", saveCreds);
}
getSocket(): any {
if (!this.sock) {
throw new Error("WhatsApp socket not initialized");
}
return this.sock;
}
getSocketOptional(): any | null {
return this.sock;
}
async destroy(): Promise<void> {
if (!this.sock) return;
try {
this.sock.end(new Error("Client destroyed"));
} catch (_error) {
// ignore
}
this.sock = null;
}
}