DEV Community

Cover image for Script to send a WhatsApp message to yourself

Posted on • Originally published at

Script to send a WhatsApp message to yourself

I do not save numbers any more.

You can send a Whatsapp message to a valid international number without the need to save a contact. The API link looks like this


So here is a quick JavaScript, in a quick HTML file:

    const url =  "whatsapp://send/?phone="; 

    function phone() {
        // get number, append, and browse to whatsapp://send/?phone=number
        // PS you can also add "&text=" parameter
        const phone = document.querySelector("#phone");
        let val = phone.value;
        // clean up
        val = val.replace(/[^\d]/gi, '');
        const _phone = url + val;
        document.location.href = _phone;


<input type="text" id="phone" placeholder="Phone">
<button  onclick="phone()">Send</button>
Enter fullscreen mode Exit fullscreen mode

This will open WhatsApp on desktop, or on mobile if it exists, with the phone number as the chat window. You can actually message yourself.

Deployed via the beautiful

Try it

PS: I could not find reference for that on WhatsApp Docs website, no idea why. Can you?


Top comments (0)