# WhatsApp links

> Create a wa.me click-to-chat link for a Pakistani mobile number, with an optional pre-filled message.

Source: https://pakdatakit.dev/docs/whatsapp/

`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.

## Examples

**TypeScript**

```ts
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
```

**Python**

```python
from pakdatakit import create_whatsapp_link

create_whatsapp_link('0300 1234567')
# → 'https://wa.me/923001234567'

create_whatsapp_link('+92 321 7654321', 'Is this still available?')
# → 'https://wa.me/923217654321?text=Is%20this%20still%20available%3F'

create_whatsapp_link('042-35761234')
# → None
```

**Dart**

```dart
import 'package:pakdatakit/pakdatakit.dart';

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
```

**C#**

```csharp
using PakDataKit;

WhatsApp.CreateLink("0300 1234567");
// → "https://wa.me/923001234567"

WhatsApp.CreateLink("+92 321 7654321", "Is this still available?");
// → "https://wa.me/923217654321?text=Is%20this%20still%20available%3F"

WhatsApp.CreateLink("042-35761234");
// → null
```

**PHP**

```php
use PakDataKit\WhatsApp;

WhatsApp::createLink('0300 1234567');
// → 'https://wa.me/923001234567'

WhatsApp::createLink('+92 321 7654321', 'Is this still available?');
// → 'https://wa.me/923217654321?text=Is%20this%20still%20available%3F'

WhatsApp::createLink('042-35761234');
// → null
```

## Reference

### createWhatsAppLink()

```ts
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()`](https://pakdatakit.dev/docs/phone/#validatephone), [`getNetwork()`](https://pakdatakit.dev/docs/networks/#getnetwork).

## Related

- [Phone](https://pakdatakit.dev/docs/phone/): validate and format mobile numbers.
- [Networks](https://pakdatakit.dev/docs/networks/): the original operator of a mobile prefix.
- [Quality](https://pakdatakit.dev/docs/quality/): check a phone number given for a delivery.
- [API reference](https://pakdatakit.dev/api/typescript/whatsapp/)
