UNPKG

@codebucket/whatsapp

Version:

A reusable WhatsApp Business API client with template and non-template support, webhook handling, pluggable storage, and text sanitization

39 lines (38 loc) 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LogMessageStore = void 0; /** * A MessageStore that simply logs every call. * Useful for dev / debugging / local testing. */ class LogMessageStore { async saveIncomingMessage(accountId, msg) { console.log(`[WhatsApp][${msg.to}] ← incoming message`, { accountId: accountId, id: msg.id, from: msg.from, to: msg.to, timestamp: new Date(msg.timestamp * 1000).toISOString(), text: msg.text?.body ?? null, raw: msg }); } async saveOutgoingMessage(accountId, opts, response) { console.log(`[WhatsApp][${opts.senderPhoneNumber}] → outgoing message`, { accountId: accountId, from: opts.senderPhoneNumber, to: opts.to, payload: opts.messagePayload, response }); } async saveMessageStatus(accountId, status) { console.log(`[WhatsApp][${accountId}] ✔ status update`, { messageId: status.id, status: status.status, timestamp: new Date(status.timestamp * 1000).toISOString(), raw: status }); } } exports.LogMessageStore = LogMessageStore;