@solufy/evolution-sdk
Version:
Unofficial SDK for the Evolution Whatsapp API v2
137 lines (130 loc) • 4.56 kB
JavaScript
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/location.ts
var location_exports = {};
__export(location_exports, {
BodySchema: () => LocationMessageBodySchema,
LocationMessageBodySchema: () => LocationMessageBodySchema,
LocationMessageOptionsSchema: () => LocationMessageOptionsSchema,
LocationMessageResponseSchema: () => LocationMessageResponseSchema,
OptionsSchema: () => LocationMessageOptionsSchema,
ResponseSchema: () => LocationMessageResponseSchema
});
module.exports = __toCommonJS(location_exports);
var import_zod3 = require("zod");
// src/types/tags.ts
var Jid = (jid) => jid;
var MessageId = (id) => id;
// src/utils/phone-numer-from-jid.ts
var import_libphonenumber_js = require("libphonenumber-js");
function phoneNumberFromJid(jid) {
return (0, import_libphonenumber_js.parsePhoneNumber)(`+${jid.split("@")[0]}`).number;
}
// src/modules/messages/schemas/base.ts
var import_zod2 = require("zod");
// src/schemas/common.ts
var import_libphonenumber_js2 = require("libphonenumber-js");
var import_zod = require("zod");
var PhoneNumberSchema = import_zod.z.custom((value) => (0, import_libphonenumber_js2.isValidPhoneNumber)(value), "Invalid phone number").transform((phoneNumber) => (0, import_libphonenumber_js2.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/modules/messages/schemas/base.ts
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/location.ts
var LocationMessageOptionsSchema = BaseMessageOptionsSchema.extend({
/**
* Location name
*/
name: import_zod3.z.string(),
/**
* Location address
*/
address: import_zod3.z.string(),
/**
* Location latitude
*/
latitude: import_zod3.z.number(),
/**
* Location longitude
*/
longitude: import_zod3.z.number()
});
var LocationMessageBodySchema = LocationMessageOptionsSchema;
var LocationMessageResponseSchema = import_zod3.z.object({
key: import_zod3.z.object({
remoteJid: import_zod3.z.string(),
id: import_zod3.z.string()
}),
message: import_zod3.z.object({
locationMessage: import_zod3.z.object({
degreesLatitude: import_zod3.z.number(),
degreesLongitude: import_zod3.z.number(),
name: import_zod3.z.string(),
address: import_zod3.z.string()
})
}),
messageTimestamp: import_zod3.z.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
}));
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
BodySchema,
LocationMessageBodySchema,
LocationMessageOptionsSchema,
LocationMessageResponseSchema,
OptionsSchema,
ResponseSchema
});
//# sourceMappingURL=location.js.map