UNPKG

@solufy/evolution-sdk

Version:

Unofficial SDK for the Evolution Whatsapp API v2

108 lines (102 loc) 2.97 kB
// src/modules/messages/schemas/location.ts import { z as z3 } from "zod"; // src/types/tags.ts var Jid = (jid) => jid; var MessageId = (id) => id; // src/utils/phone-numer-from-jid.ts import { parsePhoneNumber } from "libphonenumber-js"; function phoneNumberFromJid(jid) { return parsePhoneNumber(`+${jid.split("@")[0]}`).number; } // src/modules/messages/schemas/base.ts import { z as z2 } from "zod"; // src/schemas/common.ts import { isValidPhoneNumber, parsePhoneNumber as parsePhoneNumber2 } from "libphonenumber-js"; import { z } from "zod"; var PhoneNumberSchema = z.custom((value) => isValidPhoneNumber(value), "Invalid phone number").transform((phoneNumber) => parsePhoneNumber2(phoneNumber).number); var JidSchema = z.string().endsWith( "@s.whatsapp.net", "Invalid remote JID, should end with @s.whatsapp.net" ); var GroupJidSchema = z.string().endsWith( "@g.us", "Invalid group JID, should end with @g.us" ); var GroupInviteCodeSchema = z.string().length(22).regex( /^[a-zA-Z0-9]{22}$/, "Invalid group invite code" ); var ApiNumberSchema = z.union([ PhoneNumberSchema, JidSchema, GroupJidSchema ]); var mediaSchema = z.union([z.string().url(), z.string().base64()]); // src/modules/messages/schemas/base.ts var BaseMessageOptionsSchema = z2.object({ /** * Number (with country code) or JID to receive the message */ number: ApiNumberSchema, /** * Time in milliseconds before sending message */ delay: z2.number().optional() }); // src/modules/messages/schemas/location.ts var LocationMessageOptionsSchema = BaseMessageOptionsSchema.extend({ /** * Location name */ name: z3.string(), /** * Location address */ address: z3.string(), /** * Location latitude */ latitude: z3.number(), /** * Location longitude */ longitude: z3.number() }); var LocationMessageBodySchema = LocationMessageOptionsSchema; var LocationMessageResponseSchema = z3.object({ key: z3.object({ remoteJid: z3.string(), id: z3.string() }), message: z3.object({ locationMessage: z3.object({ degreesLatitude: z3.number(), degreesLongitude: z3.number(), name: z3.string(), address: z3.string() }) }), messageTimestamp: z3.coerce.date() }).transform((data) => ({ receiver: { phoneNumber: phoneNumberFromJid(data.key.remoteJid), jid: Jid(data.key.remoteJid) }, location: { latitude: data.message.locationMessage.degreesLatitude, longitude: data.message.locationMessage.degreesLongitude, name: data.message.locationMessage.name, address: data.message.locationMessage.address }, id: MessageId(data.key.id), timestamp: data.messageTimestamp })); export { LocationMessageBodySchema as BodySchema, LocationMessageBodySchema, LocationMessageOptionsSchema, LocationMessageResponseSchema, LocationMessageOptionsSchema as OptionsSchema, LocationMessageResponseSchema as ResponseSchema }; //# sourceMappingURL=location.mjs.map