How to Fix WhatsApp Api on Desktop Browsers

Jean Livino
2 min readJan 12, 2018

--

In this post I will teach you how to solve the WhatsApp api link problem “Click to Chat” does not work in Firefox and Safari desktop browsers by creating a “responsive” WhatsApp link.

What is the api of WhatsApp?

There’s a time WhatsApp has released a “Click to Chat” function where you can create links where the person can start a conversation with you without it having the saved phone number. With this function you can even add standard texts for the person to send to you.

What’s the problem?

There are three bases for you to do this solution: whatsapp://, api.whatsapp and web.whatsapp. Throughout the internet you will find people teaching with api., However in some tests I realized that it doesn't work in Firefox and Safari desktop browsers and iPhone. Web.whatsapp doesn't work on desktops and whatsapp:// works on mobiles.

How to Solve?

This can be solved with a simple script that will redirect the user according to the device he is using.

Update 01/2019 — I create a link generator with React and Express what you can use in your server or with my example. read more at: https://github.com/jeanlivino/whatsapp-link-generator

Update 05/2019 — For WordPress users i create a plugin to generate redirect links: https://github.com/jeanlivino/whatsapp-redirect-wordpress-plugin

<?php// Fix Api Whatsapp on Desktops// Dev: Jean Livino// insert the text and message$phone = 'YOURNUMBER';$message = 'YOURTEXT';// DO NOT EDIT BELOW$message = urlencode($message);$message = str_replace('+','%20',$message);$devicesmobile = ["iPhone", "Android", "webOS", "BlackBerry", "iPad", "iPod"];// check if is a mobile$isMobile = false;foreach ($devicesmobile as $key => $device) {if (strpos($_SERVER['HTTP_USER_AGENT'],$device)){$isMobile = true;break;}}if ($ismobile){header('Location: whatsapp://send?phone='.$phone.'&text='.$message);//ORecho "<script>window.location='whatsapp://send?phone='.$phone.'&text='.$message</script>";}// all otherselse {header('Location: https://web.whatsapp.com/send?phone='.$phone.'&text='.$message);//ORecho "<script>window.location='https://web.whatsapp.com/send?phone='.$phone.'&text='.$message</script>";}

GitHub Link

  1. A Change where “YOURNUMBER” is by its number in the following format 15551234567, without the “+” and “()”..
  2. Replace the text “YOURTEXT” with what you want the person to send.
  3. Save the file named index.php and upload it to your server.

Conclusion

The “Click to Chat” solution is awesome, but for your actions you need to be aware of this api, otherwise you will end up losing many leads that use Safari and Firefox.

This is my first post on Medium. Did you find this post relevant? If so, give a Clap and a Follow to help: D

Originally published at medium.com on January 12, 2018.

--

--

Jean Livino

FrontEnd Developer and Digital Marketing adept at Growth Hacking. | Desenvolvedor FrontEnd e Marketing Digital adepto ao Growth Hacking.