DEV Community

Cover image for Script to send a WhatsApp message to yourself
Ayyash
Ayyash

Posted on • Originally published at garage.sekrab.com

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

whatsapp://send/?phone=90873737777

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

<script>
    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;

    }
</script>

<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 Surge.sh

Try it

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

RESOURCES

Top comments (0)