UNPKG

@solufy/evolution-sdk

Version:

Unofficial SDK for the Evolution Whatsapp API v2

145 lines (139 loc) 5.15 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/video.ts var video_exports = {}; __export(video_exports, { BodySchema: () => VideoMessageBodySchema, OptionsSchema: () => VideoMessageOptionsSchema, ResponseSchema: () => VideoMessageResponseSchema, VideoMessageBodySchema: () => VideoMessageBodySchema, VideoMessageOptionsSchema: () => VideoMessageOptionsSchema, VideoMessageResponseSchema: () => VideoMessageResponseSchema }); module.exports = __toCommonJS(video_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/video.ts var VideoMessageOptionsSchema = BaseMessageOptionsSchema.extend({ /** * Video URL or file in base64 */ video: mediaSchema, /** * Caption to send with video */ caption: import_zod3.z.string().optional(), /** * Video mimetype */ mimetype: import_zod3.z.string().optional() }); var VideoMessageBodySchema = VideoMessageOptionsSchema.transform( ({ video, ...data }) => ({ ...data, media: video, mediatype: "video" }) ); var VideoMessageResponseSchema = import_zod3.z.object({ key: import_zod3.z.object({ remoteJid: import_zod3.z.string(), id: import_zod3.z.string() }), message: import_zod3.z.object({ videoMessage: 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(), mediaKey: import_zod3.z.string().base64(), caption: import_zod3.z.string().optional(), gifPlayback: import_zod3.z.boolean(), 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.videoMessage.url, caption: data.message.videoMessage.caption, mimetype: data.message.videoMessage.mimetype, gifPlayback: data.message.videoMessage.gifPlayback, length: data.message.videoMessage.fileLength, sha256: data.message.videoMessage.fileSha256, encryptedSha256: data.message.videoMessage.fileEncSha256, directPath: data.message.videoMessage.directPath, key: data.message.videoMessage.mediaKey, keyTimestamp: data.message.videoMessage.mediaKeyTimestamp }, id: MessageId(data.key.id), timestamp: data.messageTimestamp })); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { BodySchema, OptionsSchema, ResponseSchema, VideoMessageBodySchema, VideoMessageOptionsSchema, VideoMessageResponseSchema }); //# sourceMappingURL=video.js.map