UNPKG

social-link-parser

Version:

Extract usernames, IDs, and metadata from social media URLs across 100+ platforms

60 lines 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.whatsapp = void 0; const types_1 = require("../../core/types"); const url_1 = require("../../utils/url"); const constants_1 = require("../../utils/constants"); const domains = ['wa.me', 'whatsapp.com']; const subdomains = ['api', 'web', 'chat']; exports.whatsapp = { id: types_1.Platforms.WhatsApp, name: 'WhatsApp', color: '#25D366', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://wa\\.me/(\\d{6,15})/?${constants_1.QUERY_HASH}$`, 'i'), handle: /^\d{6,15}$/, content: { group: new RegExp(`^https?://(?:chat|whatsapp)\\.whatsapp\\.com/(?:invite/)?([\A-Za-z0-9]{20,})/?${constants_1.QUERY_HASH}$`, 'i'), send: new RegExp(`^https?://api\\.whatsapp\\.com/send\\?phone=(\\d{6,15})${constants_1.QUERY_HASH}`, 'i'), }, }, detect(url) { if (!this.domains.some(d => url.includes(d))) return false; return this.patterns.profile.test(url) || !!(this.patterns.content?.send?.test(url)) || !!(this.patterns.content?.group?.test(url)); }, extract(url, result) { const phoneMatch = this.patterns.profile.exec(url) || this.patterns.content?.send?.exec(url); if (phoneMatch) { result.userId = phoneMatch[1]; result.metadata.isProfile = true; result.metadata.contentType = 'profile'; return; } const groupMatch = this.patterns.content?.group?.exec(url); if (groupMatch) { result.ids.groupInviteCode = groupMatch[1]; result.metadata.isGroupInvite = true; result.metadata.contentType = 'group'; } }, validateHandle(handle) { return /^\d{6,15}$/.test(handle); }, buildProfileUrl(phone) { return `https://wa.me/${phone.replace(/\D/g, '')}`; }, buildContentUrl(contentType, id) { if (contentType === 'group') return `https://chat.whatsapp.com/${id}`; return `https://wa.me/${id}`; }, normalizeUrl(url) { return (0, url_1.normalize)(url); }, }; //# sourceMappingURL=index.js.map