@solufy/evolution-sdk
Version:
Unofficial SDK for the Evolution Whatsapp API v2
1 lines • 69.1 kB
Source Map (JSON)
{"version":3,"sources":["../src/api/errors.ts","../src/api/service.ts","../src/api/routes.ts","../src/modules/chats/schemas/check.ts","../src/schemas/common.ts","../src/types/tags.ts","../src/modules/chats/schemas/find-all.ts","../src/utils/phone-numer-from-jid.ts","../src/modules/chats/schemas/presence.ts","../src/modules/chats/index.ts","../src/modules/groups/index.ts","../src/modules/groups/schemas/find-all.ts","../src/modules/groups/schemas/common.ts","../src/modules/groups/schemas/find-by-invite-code.ts","../src/modules/groups/schemas/find-by-jid.ts","../src/modules/messages/schemas/audio.ts","../src/modules/messages/schemas/base.ts","../src/modules/messages/schemas/contact.ts","../src/modules/messages/schemas/document.ts","../src/modules/messages/schemas/image.ts","../src/modules/messages/schemas/location.ts","../src/modules/messages/schemas/sticker.ts","../src/modules/messages/schemas/text.ts","../src/modules/messages/schemas/video.ts","../src/modules/messages/schemas/voice.ts","../src/modules/messages/index.ts","../src/schemas/client.ts","../src/index.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport class EvolutionApiError extends Error {\n\tconstructor(message: string, cause?: unknown) {\n\t\tconst error = getErrorMessage(cause);\n\n\t\tsuper(message, error ? undefined : { cause });\n\n\t\tthis.name = EvolutionApiError.name;\n\t\tthis.message = error ?? message;\n\t}\n}\n\nconst ErrorMessages = [\n\tErrorMessage(\n\t\tz.object({\n\t\t\tmessage: z.array(\n\t\t\t\tz.object({\n\t\t\t\t\texists: z.literal(false),\n\t\t\t\t\tjid: z.string(),\n\t\t\t\t\tnumber: z.string(),\n\t\t\t\t}),\n\t\t\t),\n\t\t}),\n\t\t\"Provided number is not a valid WhatsApp number\",\n\t),\n\tErrorMessage(\n\t\tz.object({\n\t\t\tmessage: z.array(z.string().includes(\"Media upload failed on all hosts\")),\n\t\t}),\n\t\t\"Media upload failed on all hosts\",\n\t),\n\tErrorMessage(\n\t\tz.object({\n\t\t\tmessage: z.array(z.string().includes(\"AxiosError\")),\n\t\t}),\n\t\t(response) => response.message[0],\n\t),\n\tErrorMessage(\n\t\tz.object({\n\t\t\tmessage: z.array(z.string().includes(\"No session\")),\n\t\t}),\n\t\t\"No session found, try restarting your instance\",\n\t),\n\tErrorMessage(\n\t\tz.object({\n\t\t\tmessage: z.array(z.string().includes(\"AggregateError\")),\n\t\t}),\n\t\t\"AggregateError\",\n\t),\n];\n\nfunction getErrorMessage(response: unknown) {\n\tconst error = ErrorMessages.find(\n\t\t(message) => message.schema.safeParse(response).success,\n\t);\n\n\treturn error\n\t\t? typeof error.message === \"string\"\n\t\t\t? error.message\n\t\t\t: // biome-ignore lint/suspicious/noExplicitAny: Generic\n\t\t\t\terror.message(response as any)\n\t\t: undefined;\n}\n\nfunction ErrorMessage<T extends z.ZodType>(\n\tschema: T,\n\tmessage: string | ((data: z.infer<T>) => string),\n) {\n\treturn { schema, message };\n}\n","import type { ClientOptions } from \"@/schemas/client\";\nimport type { APIRequestInit } from \"@/types/api\";\n\nimport { EvolutionApiError } from \"./errors\";\n\nexport class ApiService {\n\tconstructor(private readonly options: ClientOptions) {}\n\n\tasync get<T>(path: string, options: Omit<APIRequestInit, \"method\"> = {}) {\n\t\treturn this.request<T>(path, { ...options, method: \"GET\" });\n\t}\n\n\tasync post<T>(path: string, options: Omit<APIRequestInit, \"method\"> = {}) {\n\t\treturn this.request<T>(path, { ...options, method: \"POST\" });\n\t}\n\n\tasync put<T>(path: string, options: Omit<APIRequestInit, \"method\"> = {}) {\n\t\treturn this.request<T>(path, { ...options, method: \"PUT\" });\n\t}\n\n\tasync patch<T>(path: string, options: Omit<APIRequestInit, \"method\"> = {}) {\n\t\treturn this.request<T>(path, { ...options, method: \"PATCH\" });\n\t}\n\n\tasync delete<T>(path: string, options: Omit<APIRequestInit, \"method\"> = {}) {\n\t\treturn this.request<T>(path, { ...options, method: \"DELETE\" });\n\t}\n\n\tasync request<T = unknown>(\n\t\tpath: string,\n\t\toptions: APIRequestInit = {},\n\t): Promise<T> {\n\t\tconst { init, params } = this.makeInit(options);\n\t\tconst url = new URL(\n\t\t\t`/${path}/${this.options.instance}/?${params}`,\n\t\t\tthis.options.serverUrl,\n\t\t);\n\n\t\tconst response = await fetch(url, init);\n\t\tconst data = await response.json();\n\n\t\tif (!response.ok || \"error\" in data) {\n\t\t\tthrow new EvolutionApiError(\n\t\t\t\t`${this.options.instance} ${data.error || \"Unknown Error\"}`,\n\t\t\t\tdata.response,\n\t\t\t);\n\t\t}\n\n\t\treturn data;\n\t}\n\n\tprivate makeInit(options: APIRequestInit) {\n\t\tconst { params: _, headers, body, ...rest } = options;\n\n\t\tconst paramsInit =\n\t\t\toptions.params &&\n\t\t\tObject.entries(options.params)\n\t\t\t\t.filter(([, value]) => Boolean(value))\n\t\t\t\t.map(([key, value]) => [key, String(value)]);\n\t\tconst params = new URLSearchParams(paramsInit);\n\n\t\tconst init: RequestInit & { headers: Record<string, string> } = {\n\t\t\t...rest,\n\t\t\theaders: { ...(headers || {}), apikey: this.options.token },\n\t\t};\n\n\t\tif (body) {\n\t\t\tinit.headers[\"Content-Type\"] =\n\t\t\t\tbody instanceof FormData ? \"multipart/form-data\" : \"application/json\";\n\t\t\tinit.body = body instanceof FormData ? body : JSON.stringify(body);\n\t\t}\n\n\t\treturn { init, params };\n\t}\n}\n","export const Routes = {\n\tMessage: {\n\t\tSendText: \"message/sendText\",\n\t\tSendMedia: \"message/sendMedia\",\n\t\tSendVoice: \"message/sendWhatsAppAudio\",\n\t\tSendSticker: \"message/sendSticker\",\n\t\tSendLocation: \"message/sendLocation\",\n\t\tSendContact: \"message/sendContact\",\n\t\tSendPoll: \"message/sendPoll\",\n\t},\n\tChats: {\n\t\tCheck: \"chat/whatsappNumbers\",\n\t\tFindAll: \"chat/findChats\",\n\t\tSendPresence: \"chat/sendPresence\",\n\t},\n\tGroups: {\n\t\tFindAll: \"group/fetchAllGroups\",\n\t\tFindByJid: \"group/findGroupInfos\",\n\t\tFindByInviteCode: \"group/inviteInfo\",\n\t},\n};\n","import { parsePhoneNumber } from \"libphonenumber-js\";\nimport { z } from \"zod\";\n\nimport { PhoneNumberSchema } from \"@/schemas/common\";\nimport { Jid } from \"@/types/tags\";\n\nexport const CheckOptionsSchema = z.array(PhoneNumberSchema);\n\nexport const CheckBodySchema = CheckOptionsSchema.transform((data) => ({\n\tnumbers: Array.isArray(data) ? data : [data],\n}));\n\nexport const CheckResponseSchema = z\n\t.array(\n\t\tz.object({\n\t\t\texists: z.boolean(),\n\t\t\tjid: z.string(),\n\t\t\tnumber: z.string(),\n\t\t}),\n\t)\n\t.transform((numbers) =>\n\t\tnumbers.map((number) => ({\n\t\t\texists: number.exists,\n\t\t\tjid: Jid(number.jid),\n\t\t\tnumber: parsePhoneNumber(number.number).number,\n\t\t})),\n\t);\n\nexport type CheckOptions = z.infer<typeof CheckOptionsSchema>;\nexport type CheckResponse = z.infer<typeof CheckResponseSchema>;\n\nexport {\n\tCheckBodySchema as BodySchema,\n\tCheckOptionsSchema as OptionsSchema,\n\tCheckResponseSchema as ResponseSchema,\n};\n","import { isValidPhoneNumber, parsePhoneNumber } from \"libphonenumber-js\";\nimport { z } from \"zod\";\n\nimport type { GroupInviteCode, GroupJid, Jid } from \"@/types/tags\";\n\nexport const PhoneNumberSchema = z\n\t.custom<string>((value) => isValidPhoneNumber(value), \"Invalid phone number\")\n\t.transform<string>((phoneNumber) => parsePhoneNumber(phoneNumber).number);\n\nexport const JidSchema = z\n\t.string()\n\t.endsWith(\n\t\t\"@s.whatsapp.net\",\n\t\t\"Invalid remote JID, should end with @s.whatsapp.net\",\n\t) as z.ZodType<Jid>;\n\nexport const GroupJidSchema = z\n\t.string()\n\t.endsWith(\n\t\t\"@g.us\",\n\t\t\"Invalid group JID, should end with @g.us\",\n\t) as z.ZodType<GroupJid>;\n\nexport const GroupInviteCodeSchema = z\n\t.string()\n\t.length(22)\n\t.regex(\n\t\t/^[a-zA-Z0-9]{22}$/,\n\t\t\"Invalid group invite code\",\n\t) as unknown as z.ZodType<GroupInviteCode>;\n\nexport const ApiNumberSchema = z.union([\n\tPhoneNumberSchema,\n\tJidSchema,\n\tGroupJidSchema,\n]);\n\nexport const mediaSchema = z.union([z.string().url(), z.string().base64()]);\n","export type Jid = `${string}@s.whatsapp.net`;\nexport const Jid = (jid: string) => jid as Jid;\n\nexport type GroupJid = `${string}@g.us`;\nexport const GroupJid = (jid: string) => jid as GroupJid;\n\nexport type GroupInviteCode = string & { __tag: \"GroupInviteCode\" };\nexport const GroupInviteCode = (code: string) => code as GroupInviteCode;\n\nexport type MessageId = string & { __tag: \"MessageId\" };\nexport const MessageId = (id: string) => id as MessageId;\n\nexport type ChatId = string & { __tag: \"ChatId\" };\nexport const ChatId = (id: string) => id as ChatId;\n","import { z } from \"zod\";\n\nimport { ChatId, GroupJid, Jid } from \"@/types/tags\";\nimport { phoneNumberFromJid } from \"@/utils/phone-numer-from-jid\";\n\nexport const FindAllChatsResponseSchema = z\n\t.array(\n\t\tz.object({\n\t\t\tid: z.string(),\n\t\t\tremoteJid: z.string(),\n\t\t\tname: z.string().nullish(),\n\t\t\tlabels: z.array(z.string()).nullish(),\n\t\t\tcreatedAt: z.coerce.date(),\n\t\t\tupdatedAt: z.coerce.date(),\n\t\t\tpushName: z.string().nullish(),\n\t\t\tprofilePicUrl: z.string().url().nullish(),\n\t\t}),\n\t)\n\t.transform((chats) =>\n\t\tchats.map((chat) => ({\n\t\t\tid: ChatId(chat.id),\n\t\t\tjid: chat.remoteJid.endsWith(\"@g.us\")\n\t\t\t\t? GroupJid(chat.remoteJid)\n\t\t\t\t: Jid(chat.remoteJid),\n\t\t\tphoneNumber: phoneNumberFromJid(chat.remoteJid),\n\t\t\tname: chat.name || undefined,\n\t\t\tlabels: chat.labels || undefined,\n\t\t\tcreatedAt: chat.createdAt,\n\t\t\tupdatedAt: chat.updatedAt,\n\t\t\tpushName: chat.pushName || undefined,\n\t\t\tpictureUrl: chat.profilePicUrl || undefined,\n\t\t})),\n\t);\n\nexport type FindAllChatsResponse = z.infer<typeof FindAllChatsResponseSchema>;\n\nexport { FindAllChatsResponseSchema as ResponseSchema };\n","import { parsePhoneNumber } from \"libphonenumber-js\";\n\n/**\n * Get phone number from JID\n * @param jid - JID (remote JID)\n */\nexport function phoneNumberFromJid(jid: string) {\n\treturn parsePhoneNumber(`+${jid.split(\"@\")[0]}`).number;\n}\n","import { z } from \"zod\";\n\nimport { ApiNumberSchema } from \"@/schemas/common\";\n\nexport const PresenceOptionsSchema = z.object({\n\t/**\n\t * Chat number or JID to receve the presence\n\t */\n\tnumber: ApiNumberSchema,\n\t/**\n\t * Duration of the presence in millisseconds\n\t */\n\tduration: z.number(),\n\t/**\n\t * Presence state\n\t * - `composing`: typing a message\n\t * - `recording`: recording an audio\n\t */\n\tpresence: z.enum([\"composing\", \"recording\"]),\n\t/**\n\t * Whether to wait until the presence is finished (duration)\n\t */\n\twaitUntilFinish: z.boolean().optional(),\n});\n\nexport const PresenceBodySchema = PresenceOptionsSchema.transform(\n\t({ waitUntilFinish, duration, ...data }) => ({ ...data, delay: duration }),\n);\n\nexport type PresenceOptions = z.infer<typeof PresenceOptionsSchema>;\n\nexport {\n\tPresenceBodySchema as BodySchema,\n\tPresenceOptionsSchema as OptionsSchema,\n};\n","import { Routes } from \"@/api/routes\";\nimport type { ApiService } from \"@/api/service\";\n\nimport * as Check from \"./schemas/check\";\nimport * as FindAll from \"./schemas/find-all\";\nimport * as Presence from \"./schemas/presence\";\n\nexport class ChatsModule {\n\tconstructor(private readonly api: ApiService) {}\n\n\t/**\n\t * Checks if a number has WhatsApp\n\t * @param numbers - Number(s) (with country code) to check\n\t */\n\tasync check(\n\t\t...numbers: Check.CheckOptions | Check.CheckOptions[]\n\t): Promise<Check.CheckResponse> {\n\t\tconst body = Check.CheckBodySchema.parse(numbers.flat());\n\t\tconst response = await this.api.post(Routes.Chats.Check, { body });\n\n\t\treturn Check.CheckResponseSchema.parse(response);\n\t}\n\n\t/**\n\t * Gets all chats\n\t */\n\tasync findAll(): Promise<FindAll.FindAllChatsResponse> {\n\t\tconst response = await this.api.post(Routes.Chats.FindAll);\n\n\t\treturn FindAll.ResponseSchema.parse(response);\n\t}\n\n\t/**\n\t * Sends a presence to a certain chat\n\t * @param options - Presence options\n\t */\n\tasync sendPresence(options: Presence.PresenceOptions) {\n\t\tconst body = Presence.BodySchema.parse(options);\n\n\t\tif (options.waitUntilFinish) {\n\t\t\tawait this.api.post(Routes.Chats.SendPresence, { body });\n\t\t} else {\n\t\t\tthis.api.post(Routes.Chats.SendPresence, { body });\n\t\t}\n\t}\n}\n","import { z } from \"zod\";\n\nimport { Routes } from \"@/api/routes\";\nimport type { ApiService } from \"@/api/service\";\nimport { GroupInviteCodeSchema, GroupJidSchema } from \"@/schemas/common\";\nimport type { GroupInviteCode, GroupJid } from \"@/types/tags\";\n\nimport * as FindAll from \"./schemas/find-all\";\nimport * as FindByInviteCode from \"./schemas/find-by-invite-code\";\nimport * as FindByJid from \"./schemas/find-by-jid\";\n\nexport class GroupsModule {\n\tconstructor(private readonly api: ApiService) {}\n\n\t/**\n\t * Gets all groups\n\t * @param getParticipants - Whether to get participants\n\t */\n\tasync findAll(getParticipants: false): Promise<FindAll.FindAllGroupsResponse>;\n\tasync findAll(\n\t\tgetParticipants: true,\n\t): Promise<FindAll.FindAllGroupsWithParticipantsResponse>;\n\tasync findAll(\n\t\tgetParticipants = false,\n\t): Promise<\n\t\t| FindAll.FindAllGroupsResponse\n\t\t| FindAll.FindAllGroupsWithParticipantsResponse\n\t> {\n\t\tconst response = await this.api.get(Routes.Groups.FindAll, {\n\t\t\tparams: { getParticipants: z.boolean().parse(getParticipants) },\n\t\t});\n\n\t\tif (getParticipants) {\n\t\t\treturn FindAll.ResponseWithParticipantsSchema.parse(response);\n\t\t}\n\t\treturn FindAll.ResponseSchema.parse(response);\n\t}\n\n\t/**\n\t * Gets a group by invite code\n\t * @param inviteCode - The group invite code (not the URL)\n\t */\n\tasync findByInviteCode(\n\t\tinviteCode: string | GroupInviteCode,\n\t): Promise<FindByInviteCode.FindGroupByInviteCodeResponse> {\n\t\tconst response = await this.api.get(Routes.Groups.FindByInviteCode, {\n\t\t\tparams: { inviteCode: GroupInviteCodeSchema.parse(inviteCode) },\n\t\t});\n\n\t\treturn FindByInviteCode.ResponseSchema.parse(response);\n\t}\n\n\t/**\n\t * Gets a group by JID\n\t * @param groupJid - The group JID terminated with \\@g.us\n\t */\n\tasync findByJid(\n\t\tgroupJid: string | GroupJid,\n\t): Promise<FindByJid.FindGroupByJidResponse> {\n\t\tconst response = await this.api.get(Routes.Groups.FindByJid, {\n\t\t\tparams: { groupJid: GroupJidSchema.parse(groupJid) },\n\t\t});\n\n\t\treturn FindByJid.ResponseSchema.parse(response);\n\t}\n}\n","import { z } from \"zod\";\n\nimport {\n\tGroupResponseSchema,\n\tGroupResponseSchemaTransform,\n\tGroupWithParticipantsResponseSchema,\n\tGroupWithParticipantsResponseSchemaTransform,\n} from \"./common\";\n\nexport const FindAllGroupsResponseSchema = z\n\t.array(GroupResponseSchema)\n\t.transform((groups) =>\n\t\tgroups.map((group) => GroupResponseSchemaTransform(group)),\n\t);\n\nexport const FindAllGroupsWithParticipantsResponseSchema = z\n\t.array(GroupWithParticipantsResponseSchema)\n\t.transform((groups) =>\n\t\tgroups.map((group) => GroupWithParticipantsResponseSchemaTransform(group)),\n\t);\n\nexport type FindAllGroupsResponse = z.infer<typeof FindAllGroupsResponseSchema>;\nexport type FindAllGroupsWithParticipantsResponse = z.infer<\n\ttypeof FindAllGroupsWithParticipantsResponseSchema\n>;\n\nexport {\n\tFindAllGroupsResponseSchema as ResponseSchema,\n\tFindAllGroupsWithParticipantsResponseSchema as ResponseWithParticipantsSchema,\n};\n","import { z } from \"zod\";\n\nimport { GroupJid, Jid } from \"@/types/tags\";\nimport { phoneNumberFromJid } from \"@/utils/phone-numer-from-jid\";\n\nexport const GroupResponseSchema = z.object({\n\tid: z.string(),\n\tsubject: z.string(),\n\tsubjectOwner: z.string(),\n\tsubjectTime: z.coerce.date(),\n\tpictureUrl: z.string().url().nullish(),\n\tsize: z.number(),\n\tcreation: z.coerce.date(),\n\towner: z.string(),\n\trestrict: z.boolean(),\n\tannounce: z.boolean(),\n});\n\nexport const ParticipantResponseSchema = z.object({\n\tid: z.string(),\n\tadmin: z.enum([\"admin\", \"superadmin\"]).nullish(),\n});\n\nexport const GroupWithParticipantsResponseSchema = GroupResponseSchema.extend({\n\tparticipants: z.array(ParticipantResponseSchema),\n});\n\nexport const GroupResponseSchemaTransform = (\n\tgroup: z.infer<typeof GroupResponseSchema>,\n) => ({\n\tjid: GroupJid(group.id),\n\tname: group.subject,\n\tpictureUrl: group.pictureUrl || undefined,\n\tsize: group.size,\n\tsubject: {\n\t\towner: Jid(group.subjectOwner),\n\t\ttime: group.subjectTime,\n\t},\n\towner: {\n\t\tjid: Jid(group.owner),\n\t\tphoneNumber: phoneNumberFromJid(group.owner),\n\t},\n\tcreatedAt: group.creation,\n\trestrict: group.restrict,\n\tannounce: group.announce,\n});\n\nexport const ParticipantResponseSchemaTransform = (\n\tparticipant: z.infer<typeof ParticipantResponseSchema>,\n) => ({\n\tid: participant.id,\n\trole: participant.admin || (\"member\" as const),\n});\n\nexport const GroupWithParticipantsResponseSchemaTransform = (\n\tgroup: z.infer<typeof GroupWithParticipantsResponseSchema>,\n) => ({\n\t...GroupResponseSchemaTransform(group),\n\tparticipants: group.participants.map(ParticipantResponseSchemaTransform),\n});\n\nexport type GroupResponse = z.infer<typeof GroupResponseSchema>;\nexport type ParticipantResponse = z.infer<typeof ParticipantResponseSchema>;\nexport type GroupWithParticipantsResponse = z.infer<\n\ttypeof GroupWithParticipantsResponseSchema\n>;\n","import { z } from \"zod\";\n\nimport {\n\tGroupWithParticipantsResponseSchema,\n\tGroupWithParticipantsResponseSchemaTransform,\n} from \"./common\";\n\nexport const FindGroupByInviteCodeResponseSchema =\n\tGroupWithParticipantsResponseSchema.extend({\n\t\tisCommunity: z.boolean(),\n\t\tisCommunityAnnounce: z.boolean(),\n\t\tjoinApprovalMode: z.boolean(),\n\t\tmemberAddMode: z.boolean(),\n\t})\n\t\t.omit({ pictureUrl: true })\n\t\t.transform((group) => ({\n\t\t\t...GroupWithParticipantsResponseSchemaTransform({\n\t\t\t\t...group,\n\t\t\t\tpictureUrl: null,\n\t\t\t}),\n\t\t\tisCommunity: group.isCommunity,\n\t\t\tisCommunityAnnounce: group.isCommunityAnnounce,\n\t\t\tjoinApprovalMode: group.joinApprovalMode,\n\t\t\tmemberAddMode: group.memberAddMode,\n\t\t}));\n\nexport type FindGroupByInviteCodeResponse = z.infer<\n\ttypeof FindGroupByInviteCodeResponseSchema\n>;\n\nexport { FindGroupByInviteCodeResponseSchema as ResponseSchema };\n","import type { z } from \"zod\";\n\nimport {\n\tGroupWithParticipantsResponseSchema,\n\tGroupWithParticipantsResponseSchemaTransform,\n} from \"./common\";\n\nexport const FindGroupByJidResponseSchema =\n\tGroupWithParticipantsResponseSchema.transform(\n\t\tGroupWithParticipantsResponseSchemaTransform,\n\t);\n\nexport type FindGroupByJidResponse = z.infer<\n\ttypeof FindGroupByJidResponseSchema\n>;\n\nexport { FindGroupByJidResponseSchema as ResponseSchema };\n","import { z } from \"zod\";\n\nimport { mediaSchema } from \"@/schemas/common\";\nimport { Jid, MessageId } from \"@/types/tags\";\nimport { phoneNumberFromJid } from \"@/utils/phone-numer-from-jid\";\nimport { BaseMessageOptionsSchema } from \"./base\";\n\nexport const AudioMessageOptionsSchema = BaseMessageOptionsSchema.extend({\n\t/**\n\t * Audio URL or file in base64\n\t */\n\taudio: mediaSchema,\n\t/**\n\t * Audio mimetype\n\t */\n\tmimetype: z.string().optional(),\n});\n\nexport const AudioMessageBodySchema = AudioMessageOptionsSchema.transform(\n\t({ audio, ...data }) => ({ ...data, media: audio, mediatype: \"audio\" }),\n);\n\nexport const AudioMessageResponseSchema = z\n\t.object({\n\t\tkey: z.object({\n\t\t\tremoteJid: z.string(),\n\t\t\tid: z.string(),\n\t\t}),\n\t\tmessage: z.object({\n\t\t\taudioMessage: z.object({\n\t\t\t\turl: z.string().url(),\n\t\t\t\tmimetype: z.string().optional(),\n\t\t\t\tfileSha256: z.string().base64(),\n\t\t\t\tfileLength: z.coerce.number(),\n\t\t\t\tseconds: z.number(),\n\t\t\t\tmediaKey: z.string().base64(),\n\t\t\t\tfileEncSha256: z.string().base64(),\n\t\t\t\tdirectPath: z.string(),\n\t\t\t\tmediaKeyTimestamp: z.coerce\n\t\t\t\t\t.number()\n\t\t\t\t\t.transform((value) => new Date(value)),\n\t\t\t}),\n\t\t}),\n\t\tmessageTimestamp: z.coerce.date(),\n\t})\n\t.transform((data) => ({\n\t\treceiver: {\n\t\t\tphoneNumber: phoneNumberFromJid(data.key.remoteJid),\n\t\t\tjid: Jid(data.key.remoteJid),\n\t\t},\n\t\tmedia: {\n\t\t\turl: data.message.audioMessage.url,\n\t\t\tmimetype: data.message.audioMessage.mimetype,\n\t\t\tlength: data.message.audioMessage.fileLength,\n\t\t\tdurationInSeconds: data.message.audioMessage.seconds,\n\t\t\tsha256: data.message.audioMessage.fileSha256,\n\t\t\tencryptedSha256: data.message.audioMessage.fileEncSha256,\n\t\t\tdirectPath: data.message.audioMessage.directPath,\n\t\t\tkey: data.message.audioMessage.mediaKey,\n\t\t\tkeyTimestamp: data.message.audioMessage.mediaKeyTimestamp,\n\t\t},\n\t\tid: MessageId(data.key.id),\n\t\ttimestamp: data.messageTimestamp,\n\t}));\n\nexport type AudioMessageOptions = z.infer<typeof AudioMessageOptionsSchema>;\nexport type AudioMessageResponse = z.infer<typeof AudioMessageResponseSchema>;\n\nexport {\n\tAudioMessageBodySchema as BodySchema,\n\tAudioMessageOptionsSchema as OptionsSchema,\n\tAudioMessageResponseSchema as ResponseSchema,\n};\n","import { z } from \"zod\";\n\nimport { ApiNumberSchema } from \"@/schemas/common\";\n\nexport const BaseMessageOptionsSchema = z.object({\n\t/**\n\t * Number (with country code) or JID to receive the message\n\t */\n\tnumber: ApiNumberSchema,\n\t/**\n\t * Time in milliseconds before sending message\n\t */\n\tdelay: z.number().optional(),\n});\n\nexport type BaseMessageOptions = z.infer<typeof BaseMessageOptionsSchema>;\n","import { parsePhoneNumber } from \"libphonenumber-js\";\nimport { z } from \"zod\";\n\nimport { PhoneNumberSchema } from \"@/schemas/common\";\nimport { Jid, MessageId } from \"@/types/tags\";\nimport { phoneNumberFromJid } from \"@/utils/phone-numer-from-jid\";\nimport { BaseMessageOptionsSchema } from \"./base\";\n\nexport const ContactMessageOptionsSchema = BaseMessageOptionsSchema.extend({\n\t/**\n\t * Contact list\n\t */\n\tcontacts: z.array(\n\t\tz.object({\n\t\t\t/**\n\t\t\t * Contact display name\n\t\t\t */\n\t\t\tfullName: z.string(),\n\t\t\t/**\n\t\t\t * Contact phone number\n\t\t\t */\n\t\t\tphoneNumber: PhoneNumberSchema,\n\t\t\t/**\n\t\t\t * Contact organization\n\t\t\t */\n\t\t\torganization: z.string().optional(),\n\t\t\t/**\n\t\t\t * Contact email\n\t\t\t */\n\t\t\temail: z.string().email().optional(),\n\t\t\t/**\n\t\t\t * Contact website url\n\t\t\t */\n\t\t\turl: z.string().url().optional(),\n\t\t}),\n\t),\n});\n\nexport const ContactMessageBodySchema = ContactMessageOptionsSchema.transform(\n\t({ contacts, ...data }) => ({\n\t\t...data,\n\t\tcontact: contacts.map((contact) => ({\n\t\t\t...contact,\n\t\t\tphoneNumber: parsePhoneNumber(contact.phoneNumber).formatInternational(),\n\t\t\twuid: contact.phoneNumber.replace(/\\D/g, \"\"),\n\t\t})),\n\t}),\n);\n\nexport const ContactMessageResponseSchema = z\n\t.object({\n\t\tkey: z.object({\n\t\t\tremoteJid: z.string(),\n\t\t\tid: z.string(),\n\t\t}),\n\t\tmessage: z.union([\n\t\t\tz.object({\n\t\t\t\tcontactMessage: z.object({\n\t\t\t\t\tdisplayName: z.string(),\n\t\t\t\t\tvcard: z.string(),\n\t\t\t\t}),\n\t\t\t}),\n\t\t\tz.object({\n\t\t\t\tcontactsArrayMessage: z.object({\n\t\t\t\t\tcontacts: z.array(\n\t\t\t\t\t\tz.object({\n\t\t\t\t\t\t\tdisplayName: z.string(),\n\t\t\t\t\t\t\tvcard: z.string(),\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t}),\n\t\t\t}),\n\t\t]),\n\t\tmessageTimestamp: z.coerce.date(),\n\t})\n\t.transform((data) => ({\n\t\treceiver: {\n\t\t\tphoneNumber: phoneNumberFromJid(data.key.remoteJid),\n\t\t\tjid: Jid(data.key.remoteJid),\n\t\t},\n\t\tcontacts:\n\t\t\t\"contactMessage\" in data.message\n\t\t\t\t? [data.message.contactMessage]\n\t\t\t\t: data.message.contactsArrayMessage.contacts,\n\t\tid: MessageId(data.key.id),\n\t\ttimestamp: data.messageTimestamp,\n\t}));\n\nexport type ContactMessageOptions = z.infer<typeof ContactMessageOptionsSchema>;\nexport type ContactMessageResponse = z.infer<\n\ttypeof ContactMessageResponseSchema\n>;\n\nexport {\n\tContactMessageBodySchema as BodySchema,\n\tContactMessageOptionsSchema as OptionsSchema,\n\tContactMessageResponseSchema as ResponseSchema,\n};\n","import { z } from \"zod\";\n\nimport { mediaSchema } from \"@/schemas/common\";\nimport { Jid, MessageId } from \"@/types/tags\";\nimport { phoneNumberFromJid } from \"@/utils/phone-numer-from-jid\";\nimport { BaseMessageOptionsSchema } from \"./base\";\n\nexport const DocumentMessageOptionsSchema = BaseMessageOptionsSchema.extend({\n\t/**\n\t * Document URL or file in base64\n\t */\n\tdocument: mediaSchema,\n\t/**\n\t * Caption to send with document\n\t */\n\tcaption: z.string().optional(),\n\t/**\n\t * Document mimetype\n\t */\n\tmimetype: z.string().optional(),\n\t/**\n\t * Name of the file\n\t */\n\tfileName: z.string().optional(),\n}).refine(\n\t(data) => (URL.canParse(data.document) ? true : Boolean(data.fileName)),\n\t{\n\t\tmessage: \"fileName must be provided when document is not an URL\",\n\t\tpath: [\"fileName\"],\n\t},\n);\n\nexport const DocumentMessageBodySchema = DocumentMessageOptionsSchema.transform(\n\t({ document, ...data }) => ({\n\t\t...data,\n\t\tmedia: document,\n\t\tmediatype: \"document\",\n\t}),\n);\n\nexport const DocumentMessageResponseSchema = z\n\t.object({\n\t\tkey: z.object({\n\t\t\tremoteJid: z.string(),\n\t\t\tid: z.string(),\n\t\t}),\n\t\tmessage: z.object({\n\t\t\tdocumentMessage: z.object({\n\t\t\t\turl: z.string().url(),\n\t\t\t\tmimetype: z.string().optional(),\n\t\t\t\tfileSha256: z.string().base64(),\n\t\t\t\tfileLength: z.coerce.number(),\n\t\t\t\tmediaKey: z.string().base64(),\n\t\t\t\tcaption: z.string().optional(),\n\t\t\t\tfileName: z.string(),\n\t\t\t\tfileEncSha256: z.string().base64(),\n\t\t\t\tdirectPath: z.string(),\n\t\t\t\tmediaKeyTimestamp: z.coerce\n\t\t\t\t\t.number()\n\t\t\t\t\t.transform((value) => new Date(value)),\n\t\t\t}),\n\t\t}),\n\t\tmessageTimestamp: z.coerce.date(),\n\t})\n\t.transform((data) => ({\n\t\treceiver: {\n\t\t\tphoneNumber: phoneNumberFromJid(data.key.remoteJid),\n\t\t\tjid: Jid(data.key.remoteJid),\n\t\t},\n\t\tmedia: {\n\t\t\turl: data.message.documentMessage.url,\n\t\t\tcaption: data.message.documentMessage.caption,\n\t\t\tmimetype: data.message.documentMessage.mimetype,\n\t\t\tlength: data.message.documentMessage.fileLength,\n\t\t\tsha256: data.message.documentMessage.fileSha256,\n\t\t\tfileName: data.message.documentMessage.fileName,\n\t\t\tencryptedSha256: data.message.documentMessage.fileEncSha256,\n\t\t\tdirectPath: data.message.documentMessage.directPath,\n\t\t\tkey: data.message.documentMessage.mediaKey,\n\t\t\tkeyTimestamp: data.message.documentMessage.mediaKeyTimestamp,\n\t\t},\n\t\tid: MessageId(data.key.id),\n\t\ttimestamp: data.messageTimestamp,\n\t}));\n\nexport type DocumentMessageOptions = z.infer<\n\ttypeof DocumentMessageOptionsSchema\n>;\nexport type DocumentMessageResponse = z.infer<\n\ttypeof DocumentMessageResponseSchema\n>;\n\nexport {\n\tDocumentMessageBodySchema as BodySchema,\n\tDocumentMessageOptionsSchema as OptionsSchema,\n\tDocumentMessageResponseSchema as ResponseSchema,\n};\n","import { z } from \"zod\";\n\nimport { mediaSchema } from \"@/schemas/common\";\nimport { Jid, MessageId } from \"@/types/tags\";\nimport { phoneNumberFromJid } from \"@/utils/phone-numer-from-jid\";\nimport { BaseMessageOptionsSchema } from \"./base\";\n\nexport const ImageMessageOptionsSchema = BaseMessageOptionsSchema.extend({\n\t/**\n\t * Image URL or file in base64\n\t */\n\timage: mediaSchema,\n\t/**\n\t * Caption to send with image\n\t */\n\tcaption: z.string().optional(),\n\t/**\n\t * Image mimetype\n\t */\n\tmimetype: z.string().optional(),\n});\n\nexport const ImageMessageBodySchema = ImageMessageOptionsSchema.transform(\n\t({ image, ...data }) => ({ ...data, media: image, mediatype: \"image\" }),\n);\n\nexport const ImageMessageResponseSchema = z\n\t.object({\n\t\tkey: z.object({\n\t\t\tremoteJid: z.string(),\n\t\t\tid: z.string(),\n\t\t}),\n\t\tmessage: z.object({\n\t\t\timageMessage: z.object({\n\t\t\t\turl: z.string().url(),\n\t\t\t\tmimetype: z.string().optional(),\n\t\t\t\tfileSha256: z.string().base64(),\n\t\t\t\tfileLength: z.coerce.number(),\n\t\t\t\theight: z.number(),\n\t\t\t\twidth: z.number(),\n\t\t\t\tmediaKey: z.string().base64(),\n\t\t\t\tcaption: z.string().optional(),\n\t\t\t\tfileEncSha256: z.string().base64(),\n\t\t\t\tdirectPath: z.string(),\n\t\t\t\tmediaKeyTimestamp: z.coerce\n\t\t\t\t\t.number()\n\t\t\t\t\t.transform((value) => new Date(value)),\n\t\t\t}),\n\t\t}),\n\t\tmessageTimestamp: z.coerce.date(),\n\t})\n\t.transform((data) => ({\n\t\treceiver: {\n\t\t\tphoneNumber: phoneNumberFromJid(data.key.remoteJid),\n\t\t\tjid: Jid(data.key.remoteJid),\n\t\t},\n\t\tmedia: {\n\t\t\turl: data.message.imageMessage.url,\n\t\t\tcaption: data.message.imageMessage.caption,\n\t\t\tmimetype: data.message.imageMessage.mimetype,\n\t\t\tlength: data.message.imageMessage.fileLength,\n\t\t\theight: data.message.imageMessage.height,\n\t\t\twidth: data.message.imageMessage.width,\n\t\t\tsha256: data.message.imageMessage.fileSha256,\n\t\t\tencryptedSha256: data.message.imageMessage.fileEncSha256,\n\t\t\tdirectPath: data.message.imageMessage.directPath,\n\t\t\tkey: data.message.imageMessage.mediaKey,\n\t\t\tkeyTimestamp: data.message.imageMessage.mediaKeyTimestamp,\n\t\t},\n\t\tid: MessageId(data.key.id),\n\t\ttimestamp: data.messageTimestamp,\n\t}));\n\nexport type ImageMessageOptions = z.infer<typeof ImageMessageOptionsSchema>;\nexport type ImageMessageResponse = z.infer<typeof ImageMessageResponseSchema>;\n\nexport {\n\tImageMessageBodySchema as BodySchema,\n\tImageMessageOptionsSchema as OptionsSchema,\n\tImageMessageResponseSchema as ResponseSchema,\n};\n","import { z } from \"zod\";\n\nimport { Jid, MessageId } from \"@/types/tags\";\nimport { phoneNumberFromJid } from \"@/utils/phone-numer-from-jid\";\nimport { BaseMessageOptionsSchema } from \"./base\";\n\nexport const LocationMessageOptionsSchema = BaseMessageOptionsSchema.extend({\n\t/**\n\t * Location name\n\t */\n\tname: z.string(),\n\t/**\n\t * Location address\n\t */\n\taddress: z.string(),\n\t/**\n\t * Location latitude\n\t */\n\tlatitude: z.number(),\n\t/**\n\t * Location longitude\n\t */\n\tlongitude: z.number(),\n});\n\nexport const LocationMessageBodySchema = LocationMessageOptionsSchema;\n\nexport const LocationMessageResponseSchema = z\n\t.object({\n\t\tkey: z.object({\n\t\t\tremoteJid: z.string(),\n\t\t\tid: z.string(),\n\t\t}),\n\t\tmessage: z.object({\n\t\t\tlocationMessage: z.object({\n\t\t\t\tdegreesLatitude: z.number(),\n\t\t\t\tdegreesLongitude: z.number(),\n\t\t\t\tname: z.string(),\n\t\t\t\taddress: z.string(),\n\t\t\t}),\n\t\t}),\n\t\tmessageTimestamp: z.coerce.date(),\n\t})\n\t.transform((data) => ({\n\t\treceiver: {\n\t\t\tphoneNumber: phoneNumberFromJid(data.key.remoteJid),\n\t\t\tjid: Jid(data.key.remoteJid),\n\t\t},\n\t\tlocation: {\n\t\t\tlatitude: data.message.locationMessage.degreesLatitude,\n\t\t\tlongitude: data.message.locationMessage.degreesLongitude,\n\t\t\tname: data.message.locationMessage.name,\n\t\t\taddress: data.message.locationMessage.address,\n\t\t},\n\t\tid: MessageId(data.key.id),\n\t\ttimestamp: data.messageTimestamp,\n\t}));\n\nexport type LocationMessageOptions = z.infer<\n\ttypeof LocationMessageOptionsSchema\n>;\nexport type LocationMessageResponse = z.infer<\n\ttypeof LocationMessageResponseSchema\n>;\n\nexport {\n\tLocationMessageBodySchema as BodySchema,\n\tLocationMessageOptionsSchema as OptionsSchema,\n\tLocationMessageResponseSchema as ResponseSchema,\n};\n","import { z } from \"zod\";\n\nimport { mediaSchema } from \"@/schemas/common\";\nimport { Jid, MessageId } from \"@/types/tags\";\nimport { phoneNumberFromJid } from \"@/utils/phone-numer-from-jid\";\nimport { BaseMessageOptionsSchema } from \"./base\";\n\nexport const StickerMessageOptionsSchema = BaseMessageOptionsSchema.extend({\n\t/**\n\t * Image URL or file in base64\n\t */\n\tsticker: mediaSchema,\n});\n\nexport const StickerMessageBodySchema = StickerMessageOptionsSchema;\n\nexport const StickerMessageResponseSchema = z\n\t.object({\n\t\tkey: z.object({\n\t\t\tremoteJid: z.string(),\n\t\t\tid: z.string(),\n\t\t}),\n\t\tmessage: z.object({\n\t\t\tstickerMessage: z.object({\n\t\t\t\turl: z.string().url(),\n\t\t\t\tfileSha256: z.string().base64(),\n\t\t\t\tfileEncSha256: z.string().base64(),\n\t\t\t\tmediaKey: z.string().base64(),\n\t\t\t\tmimetype: z.string().optional(),\n\t\t\t\tdirectPath: z.string(),\n\t\t\t\tfileLength: z.coerce.number(),\n\t\t\t\tmediaKeyTimestamp: z.coerce\n\t\t\t\t\t.number()\n\t\t\t\t\t.transform((value) => new Date(value)),\n\t\t\t}),\n\t\t}),\n\t\tmessageTimestamp: z.coerce.date(),\n\t})\n\t.transform((data) => ({\n\t\treceiver: {\n\t\t\tphoneNumber: phoneNumberFromJid(data.key.remoteJid),\n\t\t\tjid: Jid(data.key.remoteJid),\n\t\t},\n\t\tmedia: {\n\t\t\turl: data.message.stickerMessage.url,\n\t\t\tmimetype: data.message.stickerMessage.mimetype,\n\t\t\tlength: data.message.stickerMessage.fileLength,\n\t\t\tsha256: data.message.stickerMessage.fileSha256,\n\t\t\tencryptedSha256: data.message.stickerMessage.fileEncSha256,\n\t\t\tdirectPath: data.message.stickerMessage.directPath,\n\t\t\tkey: data.message.stickerMessage.mediaKey,\n\t\t\tkeyTimestamp: data.message.stickerMessage.mediaKeyTimestamp,\n\t\t},\n\t\tid: MessageId(data.key.id),\n\t\ttimestamp: data.messageTimestamp,\n\t}));\n\nexport type StickerMessageOptions = z.infer<typeof StickerMessageOptionsSchema>;\nexport type StickerMessageResponse = z.infer<\n\ttypeof StickerMessageResponseSchema\n>;\n\nexport {\n\tStickerMessageBodySchema as BodySchema,\n\tStickerMessageOptionsSchema as OptionsSchema,\n\tStickerMessageResponseSchema as ResponseSchema,\n};\n","import { z } from \"zod\";\n\nimport { Jid, MessageId } from \"@/types/tags\";\nimport { phoneNumberFromJid } from \"@/utils/phone-numer-from-jid\";\nimport { BaseMessageOptionsSchema } from \"./base\";\n\nexport const TextMessageOptionsSchema = BaseMessageOptionsSchema.extend({\n\t/**\n\t * Message text content\n\t */\n\ttext: z.string(),\n\t/**\n\t * Whether link preview should be shown\n\t */\n\tlinkPreview: z.boolean().optional(),\n});\n\nexport const TextMessageBodySchema = TextMessageOptionsSchema;\n\nexport const TextMessageResponseSchema = z\n\t.object({\n\t\tkey: z.object({\n\t\t\tremoteJid: z.string(),\n\t\t\tid: z.string(),\n\t\t}),\n\t\tmessageTimestamp: z.coerce.date(),\n\t})\n\t.transform((data) => ({\n\t\treceiver: {\n\t\t\tphoneNumber: phoneNumberFromJid(data.key.remoteJid),\n\t\t\tjid: Jid(data.key.remoteJid),\n\t\t},\n\t\tmessageId: MessageId(data.key.id),\n\t\ttimestamp: data.messageTimestamp,\n\t}));\n\nexport type TextMessageOptions = z.infer<typeof TextMessageOptionsSchema>;\nexport type TextMessageResponse = z.infer<typeof TextMessageResponseSchema>;\n\nexport {\n\tTextMessageBodySchema as BodySchema,\n\tTextMessageOptionsSchema as OptionsSchema,\n\tTextMessageResponseSchema as ResponseSchema,\n};\n","import { z } from \"zod\";\n\nimport { mediaSchema } from \"@/schemas/common\";\nimport { Jid, MessageId } from \"@/types/tags\";\nimport { phoneNumberFromJid } from \"@/utils/phone-numer-from-jid\";\nimport { BaseMessageOptionsSchema } from \"./base\";\n\nexport const VideoMessageOptionsSchema = BaseMessageOptionsSchema.extend({\n\t/**\n\t * Video URL or file in base64\n\t */\n\tvideo: mediaSchema,\n\t/**\n\t * Caption to send with video\n\t */\n\tcaption: z.string().optional(),\n\t/**\n\t * Video mimetype\n\t */\n\tmimetype: z.string().optional(),\n});\n\nexport const VideoMessageBodySchema = VideoMessageOptionsSchema.transform(\n\t({ video, ...data }) => ({ ...data, media: video, mediatype: \"video\" }),\n);\n\nexport const VideoMessageResponseSchema = z\n\t.object({\n\t\tkey: z.object({\n\t\t\tremoteJid: z.string(),\n\t\t\tid: z.string(),\n\t\t}),\n\t\tmessage: z.object({\n\t\t\tvideoMessage: z.object({\n\t\t\t\turl: z.string().url(),\n\t\t\t\tmimetype: z.string().optional(),\n\t\t\t\tfileSha256: z.string().base64(),\n\t\t\t\tfileLength: z.coerce.number(),\n\t\t\t\tmediaKey: z.string().base64(),\n\t\t\t\tcaption: z.string().optional(),\n\t\t\t\tgifPlayback: z.boolean(),\n\t\t\t\tfileEncSha256: z.string().base64(),\n\t\t\t\tdirectPath: z.string(),\n\t\t\t\tmediaKeyTimestamp: z.coerce\n\t\t\t\t\t.number()\n\t\t\t\t\t.transform((value) => new Date(value)),\n\t\t\t}),\n\t\t}),\n\t\tmessageTimestamp: z.coerce.date(),\n\t})\n\t.transform((data) => ({\n\t\treceiver: {\n\t\t\tphoneNumber: phoneNumberFromJid(data.key.remoteJid),\n\t\t\tjid: Jid(data.key.remoteJid),\n\t\t},\n\t\tmedia: {\n\t\t\turl: data.message.videoMessage.url,\n\t\t\tcaption: data.message.videoMessage.caption,\n\t\t\tmimetype: data.message.videoMessage.mimetype,\n\t\t\tgifPlayback: data.message.videoMessage.gifPlayback,\n\t\t\tlength: data.message.videoMessage.fileLength,\n\t\t\tsha256: data.message.videoMessage.fileSha256,\n\t\t\tencryptedSha256: data.message.videoMessage.fileEncSha256,\n\t\t\tdirectPath: data.message.videoMessage.directPath,\n\t\t\tkey: data.message.videoMessage.mediaKey,\n\t\t\tkeyTimestamp: data.message.videoMessage.mediaKeyTimestamp,\n\t\t},\n\t\tid: MessageId(data.key.id),\n\t\ttimestamp: data.messageTimestamp,\n\t}));\n\nexport type VideoMessageOptions = z.infer<typeof VideoMessageOptionsSchema>;\nexport type VideoMessageResponse = z.infer<typeof VideoMessageResponseSchema>;\n\nexport {\n\tVideoMessageBodySchema as BodySchema,\n\tVideoMessageOptionsSchema as OptionsSchema,\n\tVideoMessageResponseSchema as ResponseSchema,\n};\n","import { z } from \"zod\";\n\nimport { mediaSchema } from \"@/schemas/common\";\nimport { Jid, MessageId } from \"@/types/tags\";\nimport { phoneNumberFromJid } from \"@/utils/phone-numer-from-jid\";\nimport { BaseMessageOptionsSchema } from \"./base\";\n\nexport const VoiceMessageOptionsSchema = BaseMessageOptionsSchema.extend({\n\t/**\n\t * Audio URL or file in base64\n\t */\n\taudio: mediaSchema,\n\t/**\n\t * Encode audio into WhatsApp default format (allows audio to be sped up)\n\t * @default true\n\t */\n\tencoding: z.boolean().optional().default(true),\n});\n\nexport const VoiceMessageBodySchema = VoiceMessageOptionsSchema;\n\nexport const VoiceMessageResponseSchema = z\n\t.object({\n\t\tkey: z.object({\n\t\t\tremoteJid: z.string(),\n\t\t\tid: z.string(),\n\t\t}),\n\t\tmessage: z.object({\n\t\t\taudioMessage: z.object({\n\t\t\t\turl: z.string().url(),\n\t\t\t\tmimetype: z.string(),\n\t\t\t\tfileSha256: z.string().base64(),\n\t\t\t\tfileLength: z.coerce.number(),\n\t\t\t\tseconds: z.number(),\n\t\t\t\tptt: z.boolean().optional(),\n\t\t\t\tmediaKey: z.string().base64(),\n\t\t\t\tfileEncSha256: z.string().base64(),\n\t\t\t\tdirectPath: z.string(),\n\t\t\t\tmediaKeyTimestamp: z.coerce\n\t\t\t\t\t.number()\n\t\t\t\t\t.transform((value) => new Date(value)),\n\t\t\t\twaveform: z.string().base64().nullish(),\n\t\t\t}),\n\t\t}),\n\t\tmessageTimestamp: z.coerce.date(),\n\t})\n\t.transform((data) => ({\n\t\treceiver: {\n\t\t\tphoneNumber: phoneNumberFromJid(data.key.remoteJid),\n\t\t\tjid: Jid(data.key.remoteJid),\n\t\t},\n\t\tmedia: {\n\t\t\turl: data.message.audioMessage.url,\n\t\t\tmimetype: data.message.audioMessage.mimetype,\n\t\t\tlength: data.message.audioMessage.fileLength,\n\t\t\tdurationInSeconds: data.message.audioMessage.seconds,\n\t\t\tsha256: data.message.audioMessage.fileSha256,\n\t\t\tencryptedSha256: data.message.audioMessage.fileEncSha256,\n\t\t\tdirectPath: data.message.audioMessage.directPath,\n\t\t\t/**\n\t\t\t * Indicates whether the audio message is a push-to-talk (PTT) message\n\t\t\t */\n\t\t\tisPtt: data.message.audioMessage.ptt,\n\t\t\tkey: data.message.audioMessage.mediaKey,\n\t\t\tkeyTimestamp: data.message.audioMessage.mediaKeyTimestamp,\n\t\t\twaveform: data.message.audioMessage.waveform,\n\t\t},\n\t\tmessageId: MessageId(data.key.id),\n\t\ttimestamp: data.messageTimestamp,\n\t}));\n\nexport type VoiceMessageOptions = z.infer<typeof VoiceMessageOptionsSchema>;\nexport type VoiceMessageResponse = z.infer<typeof VoiceMessageResponseSchema>;\n\nexport {\n\tVoiceMessageBodySchema as BodySchema,\n\tVoiceMessageOptionsSchema as OptionsSchema,\n\tVoiceMessageResponseSchema as ResponseSchema,\n};\n","import { Routes } from \"@/api/routes\";\nimport type { ApiService } from \"@/api/service\";\n\nimport * as Audio from \"./schemas/audio\";\nimport * as Contact from \"./schemas/contact\";\nimport * as Document from \"./schemas/document\";\nimport * as Image from \"./schemas/image\";\nimport * as Location from \"./schemas/location\";\nimport * as Sticker from \"./schemas/sticker\";\nimport * as Text from \"./schemas/text\";\nimport * as Video from \"./schemas/video\";\nimport * as Voice from \"./schemas/voice\";\n\nexport class MessagesModule {\n\tconstructor(private readonly api: ApiService) {}\n\n\t/**\n\t * Sends a text message\n\t * @param options - Text message options\n\t */\n\tasync sendText(\n\t\toptions: Text.TextMessageOptions,\n\t): Promise<Text.TextMessageResponse> {\n\t\tconst body = Text.BodySchema.parse(options);\n\t\tconst response = await this.api.post(Routes.Message.SendText, { body });\n\n\t\treturn Text.ResponseSchema.parse(response);\n\t}\n\n\t/**\n\t * Sends an image\n\t * @param options - Image message options\n\t */\n\tasync sendImage(\n\t\toptions: Image.ImageMessageOptions,\n\t): Promise<Image.ImageMessageResponse> {\n\t\tconst body = Image.BodySchema.parse(options);\n\t\tconst response = await this.api.post(Routes.Message.SendMedia, { body });\n\n\t\treturn Image.ResponseSchema.parse(response);\n\t}\n\n\t/**\n\t * Sends a video\n\t * @param options - Video message options\n\t */\n\tasync sendVideo(\n\t\toptions: Video.VideoMessageOptions,\n\t): Promise<Video.VideoMessageResponse> {\n\t\tconst body = Video.BodySchema.parse(options);\n\t\tconst response = await this.api.post(Routes.Message.SendMedia, { body });\n\n\t\treturn Video.ResponseSchema.parse(response);\n\t}\n\n\t/**\n\t * Sends a document\n\t * @param options - Document message options\n\t */\n\tasync sendDocument(\n\t\toptions: Document.DocumentMessageOptions,\n\t): Promise<Document.DocumentMessageResponse> {\n\t\tconst body = Document.BodySchema.parse(options);\n\t\tconst response = await this.api.post(Routes.Message.SendMedia, { body });\n\n\t\treturn Document.ResponseSchema.parse(response);\n\t}\n\n\t/**\n\t * Sends an audio\n\t * @param options - Audio message options\n\t */\n\tasync sendAudio(\n\t\toptions: Audio.AudioMessageOptions,\n\t): Promise<Audio.AudioMessageResponse> {\n\t\tconst body = Audio.BodySchema.parse(options);\n\t\tconst response = await this.api.post(Routes.Message.SendMedia, { body });\n\n\t\treturn Audio.ResponseSchema.parse(response);\n\t}\n\n\t/**\n\t * Sends a voice message\n\t * @param options - Voice message options\n\t */\n\tasync sendVoice(\n\t\toptions: Voice.VoiceMessageOptions,\n\t): Promise<Voice.VoiceMessageResponse> {\n\t\tconst body = Voice.BodySchema.parse(options);\n\t\tconst response = await this.api.post(Routes.Message.SendVoice, { body });\n\n\t\treturn Voice.ResponseSchema.parse(response);\n\t}\n\n\t/**\n\t * Sends a sticker\n\t * @param options - Sticker message options\n\t */\n\tasync sendSticker(\n\t\toptions: Sticker.StickerMessageOptions,\n\t): Promise<Sticker.StickerMessageResponse> {\n\t\tconst body = Sticker.BodySchema.parse(options);\n\t\tconst response = await this.api.post(Routes.Message.SendSticker, { body });\n\n\t\treturn Sticker.ResponseSchema.parse(response);\n\t}\n\n\t/**\n\t * Sends a location\n\t * @param options - Location message options\n\t */\n\tasync sendLocation(\n\t\toptions: Location.LocationMessageOptions,\n\t): Promise<Location.LocationMessageResponse> {\n\t\tconst body = Location.BodySchema.parse(options);\n\t\tconst response = await this.api.post(Routes.Message.SendLocation, { body });\n\n\t\treturn Location.ResponseSchema.parse(response);\n\t}\n\n\t/**\n\t * Sends a contact\n\t * @param options - Contact message options\n\t */\n\tasync sendContact(\n\t\toptions: Contact.ContactMessageOptions,\n\t): Promise<Contact.ContactMessageResponse> {\n\t\tconst body = Contact.BodySchema.parse(options);\n\t\tconst response = await this.api.post(Routes.Message.SendContact, { body });\n\n\t\treturn Contact.ResponseSchema.parse(response);\n\t}\n}\n","import { z } from \"zod\";\n\nexport const ClientOptionsSchema = z.object({\n\t/**\n\t * Your server URL\n\t */\n\tserverUrl: z.string().url(),\n\t/**\n\t * Your instance token or global API key\n\t */\n\ttoken: z.string(),\n\t/**\n\t * Your instance name\n\t */\n\tinstance: z.string(),\n});\n\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n","import { ApiService } from \"./api/service\";\nimport { ChatsModule } from \"./modules/chats\";\nimport { GroupsModule } from \"./modules/groups\";\nimport { MessagesModule } from \"./modules/messages\";\nimport { type ClientOptions, ClientOptionsSchema } from \"./schemas/client\";\n\nexport class EvolutionClient {\n\t/**\n\t * API service for directly interacting with the Evolution API (no specific typings)\n\t */\n\tpublic readonly api: ApiService;\n\n\t/**\n\t * Find and manage chats, send presences and check numbers\n\t */\n\tpublic readonly chats: ChatsModule;\n\t/**\n\t * Find and manage groups\n\t */\n\tpublic readonly groups: GroupsModule;\n\t/**\n\t * Send messages\n\t */\n\tpublic readonly messages: MessagesModule;\n\n\t/**\n\t * Evolution Client - API client for interacting with the Evolution API\n\t * @param options - Client options\n\t */\n\tconstructor(public readonly options: ClientOptions) {\n\t\tClientOptionsSchema.parse(options);\n\n\t\tthis.api = new ApiService(options);\n\t\tthis.chats = new ChatsModule(this.api);\n\t\tthis.groups = new GroupsModule(this.api);\n\t\tthis.messages = new MessagesModule(this.api);\n\t}\n}\n\nexport { EvolutionApiError } from \"./api/errors\";\nexport { ChatId, GroupJid, Jid, MessageId } from \"./types/tags\";\nexport { phoneNumberFromJid } from \"./utils/phone-numer-from-jid\";\n\nexport type * from \"./modules/chats/schemas\";\nexport type * from \"./modules/groups/schemas\";\nexport type * from \"./modules/messages/schemas\";\nexport type { ClientOptions };\n"],"mappings":";;;;;AAAA,SAAS,SAAS;AAEX,IAAM,oBAAN,MAAM,2BAA0B,MAAM;AAAA,EAC5C,YAAY,SAAiB,OAAiB;AAC7C,UAAM,QAAQ,gBAAgB,KAAK;AAEnC,UAAM,SAAS,QAAQ,SAAY,EAAE,MAAM,CAAC;AAE5C,SAAK,OAAO,mBAAkB;AAC9B,SAAK,UAAU,SAAS;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