UNPKG

@solufy/evolution-sdk

Version:

Unofficial SDK for the Evolution Whatsapp API v2

145 lines (139 loc) 5.25 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/voice.ts var voice_exports = {}; __export(voice_exports, { BodySchema: () => VoiceMessageBodySchema, OptionsSchema: () => VoiceMessageOptionsSchema, ResponseSchema: () => VoiceMessageResponseSchema, VoiceMessageBodySchema: () => VoiceMessageBodySchema, VoiceMessageOptionsSchema: () => VoiceMessageOptionsSchema, VoiceMessageResponseSchema: () => VoiceMessageResponseSchema }); module.exports = __toCommonJS(voice_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/voice.ts var VoiceMessageOptionsSchema = BaseMessageOptionsSchema.extend({ /** * Audio URL or file in base64 */ audio: mediaSchema, /** * Encode audio into WhatsApp default format (allows audio to be sped up) * @default true */ encoding: import_zod3.z.boolean().optional().default(true) }); var VoiceMessageBodySchema = VoiceMessageOptionsSchema; var VoiceMessageResponseSchema = import_zod3.z.object({ key: import_zod3.z.object({ remoteJid: import_zod3.z.string(), id: import_zod3.z.string() }), message: import_zod3.z.object({ audioMessage: import_zod3.z.object({ url: import_zod3.z.string().url(), mimetype: import_zod3.z.string(), fileSha256: import_zod3.z.string().base64(), fileLength: import_zod3.z.coerce.number(), seconds: import_zod3.z.number(), ptt: import_zod3.z.boolean().optional(), mediaKey: import_zod3.z.string().base64(), fileEncSha256: import_zod3.z.string().base64(), directPath: import_zod3.z.string(), mediaKeyTimestamp: import_zod3.z.coerce.number().transform((value) => new Date(value)), waveform: import_zod3.z.string().base64().nullish() }) }), messageTimestamp: import_zod3.z.coerce.date() }).transform((data) => ({ receiver: { phoneNumber: phoneNumberFromJid(data.key.remoteJid), jid: Jid(data.key.remoteJid) }, media: { url: data.message.audioMessage.url, mimetype: data.message.audioMessage.mimetype, length: data.message.audioMessage.fileLength, durationInSeconds: data.message.audioMessage.seconds, sha256: data.message.audioMessage.fileSha256, encryptedSha256: data.message.audioMessage.fileEncSha256, directPath: data.message.audioMessage.directPath, /** * Indicates whether the audio message is a push-to-talk (PTT) message */ isPtt: data.message.audioMessage.ptt, key: data.message.audioMessage.mediaKey, keyTimestamp: data.message.audioMessage.mediaKeyTimestamp, waveform: data.message.audioMessage.waveform }, messageId: MessageId(data.key.id), timestamp: data.messageTimestamp })); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { BodySchema, OptionsSchema, ResponseSchema, VoiceMessageBodySchema, VoiceMessageOptionsSchema, VoiceMessageResponseSchema }); //# sourceMappingURL=voice.js.map