UNPKG

evolution-api-sdk

Version:

Unofficial SDK for the Evolution Whatsapp API v2

1 lines 4.03 kB
{"version":3,"sources":["../../../../src/types/tags.ts","../../../../src/utils/phone-numer-from-jid.ts","../../../../src/modules/messages/schemas/poll.ts"],"sourcesContent":["export type Jid = `${string}@s.whatsapp.net` | string;\nexport const Jid = (jid: string) => jid as Jid;\n\nexport type GroupJid = `${string}@g.us` | string;\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","// Pure TypeScript interfaces for better IDE support and performance\nimport { Jid, MessageId } from \"@/types/tags\";\nimport { phoneNumberFromJid } from \"@/utils/phone-numer-from-jid\";\nimport { BaseMessageOptions } from \"./base\";\n\n// Raw response interface from API\nexport interface PollMessageResponseRaw {\n\tkey: {\n\t\tremoteJid: string;\n\t\tid: string;\n\t};\n\tmessage: {\n\t\tpollCreationMessageV3: {\n\t\t\tname: string;\n\t\t\toptions: { optionName: string }[];\n\t\t\tselectableOptionsCount: number;\n\t\t};\n\t};\n\tmessageTimestamp: string | Date;\n}\n\n// Request interfaces\nexport interface PollMessageOptions extends BaseMessageOptions {\n\t/**\n\t * Name of the poll\n\t */\n\tname: string;\n\t/**\n\t * Whether multiple options can be selected\n\t * @default false\n\t */\n\tmultiple?: boolean;\n\t/**\n\t * Poll options\n\t */\n\toptions: string[];\n}\n\nexport interface PollMessageBody extends BaseMessageOptions {\n\tname: string;\n\tselectableCount: number;\n\tvalues: string[];\n}\n\n// Response interfaces\nexport interface PollMessageResponse {\n\treceiver: {\n\t\tphoneNumber: string;\n\t\tjid: Jid;\n\t};\n\tpoll: {\n\t\tname: string;\n\t\toptions: string[];\n\t\tmultiple: boolean;\n\t};\n\tid: MessageId;\n\ttimestamp: Date;\n}\n\n// Transform functions\nexport const PollMessageBodyTransform = (\n\t{ multiple, options, ...data }: PollMessageOptions\n): PollMessageBody => ({\n\t...data,\n\tselectableCount: multiple ? options.length : 1,\n\tvalues: options,\n});\n\nexport const PollMessageResponseTransform = (data: PollMessageResponseRaw): PollMessageResponse => ({\n\treceiver: {\n\t\tphoneNumber: phoneNumberFromJid(data.key.remoteJid),\n\t\tjid: Jid(data.key.remoteJid),\n\t},\n\tpoll: {\n\t\tname: data.message.pollCreationMessageV3.name,\n\t\toptions: data.message.pollCreationMessageV3.options.map(\n\t\t\t(option) => option.optionName,\n\t\t),\n\t\tmultiple: data.message.pollCreationMessageV3.selectableOptionsCount > 1,\n\t},\n\tid: MessageId(data.key.id),\n\ttimestamp: new Date(data.messageTimestamp),\n});\n\n// Backward compatibility aliases\nexport const BodySchema = { parse: PollMessageBodyTransform };\nexport const ResponseSchema = { parse: PollMessageResponseTransform };\n"],"mappings":";AACO,IAAM,MAAM,CAAC,QAAgB;AAS7B,IAAM,YAAY,CAAC,OAAe;;;ACVzC,SAAS,wBAAwB;AAM1B,SAAS,mBAAmB,KAAa;AAC/C,SAAO,iBAAiB,IAAI,IAAI,MAAM,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE;AAClD;;;ACoDO,IAAM,2BAA2B,CACvC,EAAE,UAAU,SAAS,GAAG,KAAK,OACP;AAAA,EACtB,GAAG;AAAA,EACH,iBAAiB,WAAW,QAAQ,SAAS;AAAA,EAC7C,QAAQ;AACT;AAEO,IAAM,+BAA+B,CAAC,UAAuD;AAAA,EACnG,UAAU;AAAA,IACT,aAAa,mBAAmB,KAAK,IAAI,SAAS;AAAA,IAClD,KAAK,IAAI,KAAK,IAAI,SAAS;AAAA,EAC5B;AAAA,EACA,MAAM;AAAA,IACL,MAAM,KAAK,QAAQ,sBAAsB;AAAA,IACzC,SAAS,KAAK,QAAQ,sBAAsB,QAAQ;AAAA,MACnD,CAAC,WAAW,OAAO;AAAA,IACpB;AAAA,IACA,UAAU,KAAK,QAAQ,sBAAsB,yBAAyB;AAAA,EACvE;AAAA,EACA,IAAI,UAAU,KAAK,IAAI,EAAE;AAAA,EACzB,WAAW,IAAI,KAAK,KAAK,gBAAgB;AAC1C;AAGO,IAAM,aAAa,EAAE,OAAO,yBAAyB;AACrD,IAAM,iBAAiB,EAAE,OAAO,6BAA6B;","names":[]}