UNPKG

@solufy/evolution-sdk

Version:

Unofficial SDK for the Evolution Whatsapp API v2

147 lines (141 loc) 5.21 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/modules/messages/schemas/image.ts var image_exports = {}; __export(image_exports, { BodySchema: () => ImageMessageBodySchema, ImageMessageBodySchema: () => ImageMessageBodySchema, ImageMessageOptionsSchema: () => ImageMessageOptionsSchema, ImageMessageResponseSchema: () => ImageMessageResponseSchema, OptionsSchema: () => ImageMessageOptionsSchema, ResponseSchema: () => ImageMessageResponseSchema }); module.exports = __toCommonJS(image_exports); var import_zod3 = require("zod"); // src/schemas/common.ts var import_libphonenumber_js = require("libphonenumber-js"); var import_zod = require("zod"); var PhoneNumberSchema = import_zod.z.custom((value) => (0, import_libphonenumber_js.isValidPhoneNumber)(value), "Invalid phone number").transform((phoneNumber) => (0, import_libphonenumber_js.parsePhoneNumber)(phoneNumber).number); var JidSchema = import_zod.z.string().endsWith( "@s.whatsapp.net", "Invalid remote JID, should end with @s.whatsapp.net" ); var GroupJidSchema = import_zod.z.string().endsWith( "@g.us", "Invalid group JID, should end with @g.us" ); var GroupInviteCodeSchema = import_zod.z.string().length(22).regex( /^[a-zA-Z0-9]{22}$/, "Invalid group invite code" ); var ApiNumberSchema = import_zod.z.union([ PhoneNumberSchema, JidSchema, GroupJidSchema ]); var mediaSchema = import_zod.z.union([import_zod.z.string().url(), import_zod.z.string().base64()]); // src/types/tags.ts var Jid = (jid) => jid; var MessageId = (id) => id; // src/utils/phone-numer-from-jid.ts var import_libphonenumber_js2 = require("libphonenumber-js"); function phoneNumberFromJid(jid) { return (0, import_libphonenumber_js2.parsePhoneNumber)(`+${jid.split("@")[0]}`).number; } // src/modules/messages/schemas/base.ts var import_zod2 = require("zod"); var BaseMessageOptionsSchema = import_zod2.z.object({ /** * Number (with country code) or JID to receive the message */ number: ApiNumberSchema, /** * Time in milliseconds before sending message */ delay: import_zod2.z.number().optional() }); // src/modules/messages/schemas/image.ts var ImageMessageOptionsSchema = BaseMessageOptionsSchema.extend({ /** * Image URL or file in base64 */ image: mediaSchema, /** * Caption to send with image */ caption: import_zod3.z.string().optional(), /** * Image mimetype */ mimetype: import_zod3.z.string().optional() }); var ImageMessageBodySchema = ImageMessageOptionsSchema.transform( ({ image, ...data }) => ({ ...data, media: image, mediatype: "image" }) ); var ImageMessageResponseSchema = import_zod3.z.object({ key: import_zod3.z.object({ remoteJid: import_zod3.z.string(), id: import_zod3.z.string() }), message: import_zod3.z.object({ imageMessage: import_zod3.z.object({ url: import_zod3.z.string().url(), mimetype: import_zod3.z.string().optional(), fileSha256: import_zod3.z.string().base64(), fileLength: import_zod3.z.coerce.number(), height: import_zod3.z.number(), width: import_zod3.z.number(), mediaKey: import_zod3.z.string().base64(), caption: import_zod3.z.string().optional(), fileEncSha256: import_zod3.z.string().base64(), directPath: import_zod3.z.string(), mediaKeyTimestamp: import_zod3.z.coerce.number().transform((value) => new Date(value)) }) }), messageTimestamp: import_zod3.z.coerce.date() }).transform((data) => ({ receiver: { phoneNumber: phoneNumberFromJid(data.key.remoteJid), jid: Jid(data.key.remoteJid) }, media: { url: data.message.imageMessage.url, caption: data.message.imageMessage.caption, mimetype: data.message.imageMessage.mimetype, length: data.message.imageMessage.fileLength, height: data.message.imageMessage.height, width: data.message.imageMessage.width, sha256: data.message.imageMessage.fileSha256, encryptedSha256: data.message.imageMessage.fileEncSha256, directPath: data.message.imageMessage.directPath, key: data.message.imageMessage.mediaKey, keyTimestamp: data.message.imageMessage.mediaKeyTimestamp }, id: MessageId(data.key.id), timestamp: data.messageTimestamp })); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { BodySchema, ImageMessageBodySchema, ImageMessageOptionsSchema, ImageMessageResponseSchema, OptionsSchema, ResponseSchema }); //# sourceMappingURL=image.js.map