"use strict"; /* * This file is part of WPPConnect. * * WPPConnect is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * WPPConnect is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with WPPConnect. If not, see . */ Object.defineProperty(exports, "__esModule", { value: true }); exports.StatusLayer = void 0; const labels_layer_1 = require("./labels.layer"); const helpers_1 = require("../helpers"); class StatusLayer extends labels_layer_1.LabelsLayer { constructor(page, session, options) { super(page, session, options); this.page = page; } /** * Send a image message to status stories * @category Status * * @example * ```javascript * client.sendImageStatus('data:image/jpeg;base64,'); * ``` * * @example * ```javascript * // Send with caption * client.sendImageStatus('data:image/jpeg;base64,', { caption: 'example test' } ); * ``` * @param pathOrBase64 Path or base 64 image */ async sendImageStatus(pathOrBase64, options) { let base64 = ''; if (pathOrBase64.startsWith('data:')) { base64 = pathOrBase64; } else { let fileContent = await (0, helpers_1.downloadFileToBase64)(pathOrBase64, [ 'image/gif', 'image/png', 'image/jpg', 'image/jpeg', 'image/webp', ]); if (!fileContent) { fileContent = await (0, helpers_1.fileToBase64)(pathOrBase64); } if (fileContent) { base64 = fileContent; } } if (!base64) { const error = new Error('Empty or invalid file or base64'); Object.assign(error, { code: 'empty_file', }); throw error; } const mimeInfo = (0, helpers_1.base64MimeType)(base64); if (!mimeInfo || !mimeInfo.includes('image')) { const error = new Error('Not an image, allowed formats png, jpeg and webp'); Object.assign(error, { code: 'invalid_image', }); throw error; } return await (0, helpers_1.evaluateAndReturn)(this.page, ({ base64, options }) => { WPP.status.sendImageStatus(base64, options); }, { base64, options }); } /** * Send a video message to status stories * @category Status * * @example * ```javascript * client.sendVideoStatus('data:video/mp4;base64,'); * ``` * @example * ```javascript * // Send with caption * client.sendVideoStatus('data:video/mp4;base64,', { caption: 'example test' } ); * ``` * @param pathOrBase64 Path or base 64 image */ async sendVideoStatus(pathOrBase64, options) { let base64 = ''; if (pathOrBase64.startsWith('data:')) { base64 = pathOrBase64; } else { let fileContent = await (0, helpers_1.downloadFileToBase64)(pathOrBase64); if (!fileContent) { fileContent = await (0, helpers_1.fileToBase64)(pathOrBase64); } if (fileContent) { base64 = fileContent; } } if (!base64) { const error = new Error('Empty or invalid file or base64'); Object.assign(error, { code: 'empty_file', }); throw error; } return await (0, helpers_1.evaluateAndReturn)(this.page, ({ base64, options }) => { WPP.status.sendVideoStatus(base64, options); }, { base64, options }); } /** * Send a text to status stories * @category Status * * @example * ```javascript * client.sendTextStatus(`Bootstrap primary color: #0275d8`, { backgroundColor: '#0275d8', font: 2}); * ``` * @param pathOrBase64 Path or base 64 image */ async sendTextStatus(text, options) { return await (0, helpers_1.evaluateAndReturn)(this.page, ({ text, options }) => { WPP.status.sendTextStatus(text, options); }, { text, options }); } /** * Mark status as read/seen * @category Status * * @example * ```javascript * client.sendReadStatus('[phone_number]@c.us', 'false_status@broadcast_3A169E0FD4BC6E92212F_[]@c.us'); * ``` * @param chatId Chat ID of contact * @param statusId ID of status msg */ async sendReadStatus(chatId, statusId) { return await (0, helpers_1.evaluateAndReturn)(this.page, ({ chatId, statusId }) => { WPP.status.sendReadStatus(chatId, statusId); }, { chatId, statusId }); } } exports.StatusLayer = StatusLayer;