UNPKG

@calculusky/meta-whatsapp-sdk

Version:
104 lines 3.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const base_1 = require("./base"); class MessageAPI extends base_1.BaseAPI { constructor() { super(...arguments); this.commonMethod = "POST"; this.commonEndpoint = "messages"; } bodyBuilder(options) { const body = { messaging_product: "whatsapp", to: options.toNumber, recipient_type: "individual", type: options.type, [options.type]: options.payload, }; if (options.replyMessageId) { body.context = { message_id: options.replyMessageId }; } return body; } async send(requestData) { return await this.client.sendAPIRequest({ method: this.commonMethod, endpoint: this.commonEndpoint, body: JSON.stringify(requestData), }); } async template(options) { const body = this.bodyBuilder({ type: "template", payload: options.body, toNumber: options.recipient, replyMessageId: options.replyMessageId, }); return await this.send(body); } async text(options) { const body = this.bodyBuilder({ type: "text", payload: options.body, toNumber: options.recipient, replyMessageId: options.replyMessageId, }); return await this.send(body); } async image(options) { const body = this.bodyBuilder({ type: "image", payload: options.body, toNumber: options.recipient, replyMessageId: options.replyMessageId, }); return await this.send(body); } async video(options) { const body = this.bodyBuilder({ type: "video", payload: options.body, toNumber: options.recipient, replyMessageId: options.replyMessageId, }); return await this.send(body); } async audio(options) { const body = this.bodyBuilder({ type: "video", payload: options.body, toNumber: options.recipient, replyMessageId: options.replyMessageId, }); return await this.send(body); } async document(options) { const body = this.bodyBuilder({ type: "document", payload: options.body, toNumber: options.recipient, replyMessageId: options.replyMessageId, }); return await this.send(body); } async sticker(options) { const body = this.bodyBuilder({ type: "sticker", payload: options.body, toNumber: options.recipient, replyMessageId: options.replyMessageId, }); return await this.send(body); } async reaction(options) { const body = this.bodyBuilder({ type: "reaction", payload: options.body, toNumber: options.recipient, replyMessageId: options.replyMessageId, }); return await this.send(body); } } exports.default = MessageAPI; //# sourceMappingURL=message.js.map