Skip to content

WhatsApp links

import { createWhatsAppLink } from 'pakdatakit/whatsapp'

Turns a Pakistani mobile number into a WhatsApp click-to-chat link. It accepts local, international and short phone formats, and can add a message that opens pre-filled in the chat.

createWhatsAppLink() Valid

Link
https://wa.me/923001234567?text=Is%20this%20still%20available%3F
import { createWhatsAppLink } from 'pakdatakit';
createWhatsAppLink('0300 1234567');
// → 'https://wa.me/923001234567'
createWhatsAppLink('+92 321 7654321', 'Is this still available?');
// → 'https://wa.me/923217654321?text=Is%20this%20still%20available%3F'
createWhatsAppLink('042-35761234');
// → null
function createWhatsAppLink(phone: string, message?: string): string | null;

Parameters.

  • phone: a Pakistani mobile number in any supported format.
  • message: optional pre-filled message. It is URL-encoded for you.

Returns a https://wa.me/… link, or null if the phone number is invalid. Without a message (or with an empty one) the link has no ?text= part.

Related: validatePhone(), getNetwork().