@solufy/evolution-sdk
Version:
Unofficial SDK for the Evolution Whatsapp API v2
1 lines • 5.25 kB
Source Map (JSON)
{"version":3,"sources":["../../../../src/modules/messages/schemas/text.ts","../../../../src/types/tags.ts","../../../../src/utils/phone-numer-from-jid.ts","../../../../src/modules/messages/schemas/base.ts","../../../../src/schemas/common.ts"],"sourcesContent":["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","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 { 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 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 { 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"],"mappings":";AAAA,SAAS,KAA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