UNPKG

@codebucket/whatsapp

Version:

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

24 lines (23 loc) 982 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CompositeMessageStore = void 0; /** * A MessageStore that writes to multiple underlying stores in parallel. */ class CompositeMessageStore { constructor(stores) { this.stores = stores; } async saveIncomingMessage(accountId, msg) { await Promise.all(this.stores.map(s => s.saveIncomingMessage(accountId, msg))); } async saveOutgoingMessage(accountId, opts, response) { await Promise.all(this.stores.map(s => s.saveOutgoingMessage(accountId, opts, response))); } async saveMessageStatus(accountId, status) { // filter down to only those stores that implement saveMessageStatus const storesWithStatus = this.stores.filter((s) => typeof s.saveMessageStatus === 'function'); await Promise.all(storesWithStatus.map(s => s.saveMessageStatus(accountId, status))); } } exports.CompositeMessageStore = CompositeMessageStore;