UNPKG

evolution-api-sdk

Version:

Unofficial SDK for the Evolution Whatsapp API v2

1 lines 3.51 kB
{"version":3,"sources":["../../../../src/types/tags.ts","../../../../src/utils/phone-numer-from-jid.ts","../../../../src/modules/messages/schemas/location.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 LocationMessageResponseRaw {\n\tkey: {\n\t\tremoteJid: string;\n\t\tid: string;\n\t};\n\tmessage: {\n\t\tlocationMessage: {\n\t\t\tdegreesLatitude: number;\n\t\t\tdegreesLongitude: number;\n\t\t\tname: string;\n\t\t\taddress: string;\n\t\t};\n\t};\n\tmessageTimestamp: string | Date;\n}\n\n// Request interfaces\nexport interface LocationMessageOptions extends BaseMessageOptions {\n\t/**\n\t * Location name\n\t */\n\tname: string;\n\t/**\n\t * Location address\n\t */\n\taddress: string;\n\t/**\n\t * Location latitude\n\t */\n\tlatitude: number;\n\t/**\n\t * Location longitude\n\t */\n\tlongitude: number;\n}\n\n// Response interfaces\nexport interface LocationMessageResponse {\n\treceiver: {\n\t\tphoneNumber: string;\n\t\tjid: Jid;\n\t};\n\tlocation: {\n\t\tlatitude: number;\n\t\tlongitude: number;\n\t\tname: string;\n\t\taddress: string;\n\t};\n\tid: MessageId;\n\ttimestamp: Date;\n}\n\n// Transform function\nexport const LocationMessageResponseTransform = (data: LocationMessageResponseRaw): LocationMessageResponse => ({\n\treceiver: {\n\t\tphoneNumber: phoneNumberFromJid(data.key.remoteJid),\n\t\tjid: Jid(data.key.remoteJid),\n\t},\n\tlocation: {\n\t\tlatitude: data.message.locationMessage.degreesLatitude,\n\t\tlongitude: data.message.locationMessage.degreesLongitude,\n\t\tname: data.message.locationMessage.name,\n\t\taddress: data.message.locationMessage.address,\n\t},\n\tid: MessageId(data.key.id),\n\ttimestamp: new Date(data.messageTimestamp),\n});\n\n// Backward compatibility aliases\nexport const ResponseSchema = { parse: LocationMessageResponseTransform };\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;;;ACmDO,IAAM,mCAAmC,CAAC,UAA+D;AAAA,EAC/G,UAAU;AAAA,IACT,aAAa,mBAAmB,KAAK,IAAI,SAAS;AAAA,IAClD,KAAK,IAAI,KAAK,IAAI,SAAS;AAAA,EAC5B;AAAA,EACA,UAAU;AAAA,IACT,UAAU,KAAK,QAAQ,gBAAgB;AAAA,IACvC,WAAW,KAAK,QAAQ,gBAAgB;AAAA,IACxC,MAAM,KAAK,QAAQ,gBAAgB;AAAA,IACnC,SAAS,KAAK,QAAQ,gBAAgB;AAAA,EACvC;AAAA,EACA,IAAI,UAAU,KAAK,IAAI,EAAE;AAAA,EACzB,WAAW,IAAI,KAAK,KAAK,gBAAgB;AAC1C;AAGO,IAAM,iBAAiB,EAAE,OAAO,iCAAiC;","names":[]}