DEV Community

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

Posted on • Originally published at garage.sekrab.com

4 2

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

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Cloudinary image

Optimize, customize, deliver, manage and analyze your images.

Remove background in all your web images at the same time, use outpainting to expand images with matching content, remove objects via open-set object detection and fill, recolor, crop, resize... Discover these and hundreds more ways to manage your web images and videos on a scale.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay