Create a link that will open Viber and WhatsApp and will send a message to me

99.7k views Asked by At

Everyone around used to use IM. On my site I need to put a link that will open given instant messaging application (both on PC and on mobile) and open a send message to my number - and I can't find a way!

I suppose to use some URL scheme to do that, but all I can find is (__number is my mobile phone number):

<a href="intent://send/__number__#Intent;scheme=smsto;package=com.whatsapp;action=android.intent.action.SENDTO;end">WhatsApp</a>

and

<a href="viber://add?number=__number__">Viber</a>

(I don't even know if I should use phone in +1202... or simple 1202... (that is, if the plus is needed)

but frankly speaking it won't work. Viber opens its window and then tells me it won't handle that request, and WhatsApp is not linked to intent scheme at all (tested at several devices and OSes).

So, I please ask you to help me with this small problem: what kind of URL will open Viber and WhatsApp apps to let visitors of the site to contact me?

8

There are 8 answers

3
Pedro Lobito On BEST ANSWER

What you need is called deep-linking, some examples for viber and whatsapp are:

Viber:

<a href="viber://pa?chatURI=[public account URI]&text=[message text]"> some text </a>

WhatsApp:

<a href="whatsapp://send?abid=[users name]&text=[message text]"> some text </a>

While not a deep link, you can also use the following url (don't use + on phone) for WhatsApp:

<a href="https://api.whatsapp.com/send?phone=0000000">Contact Me</a>

Sources:

http://origamiengine.com/deep-linking
https://developers.viber.com/docs/tools/deep-links/

0
anstak On

Actually viber://add?number=XXXXXXXXX is not working for Desktop app, it's working only if you open from Mobile phone. For desktop you need to use viber://chat?number=XXXXXXXXX.

For whatsapp link is very simple: https://wa.me/XXXXXXXXXX.

Remember how to generate links for all messengers is unreal, so I always use https://msng.link/ for generating whatsapp and telegram link, it's very easy.

0
prokopis kontogiannis On

Since you don't want to create a public account (aka viber links including /pa? ) then simple add the link: <a href="viber://chat?number=012345678901"">chat with me</a> The first two digits are country code and no + sign needed.

0
Leutecia On
viber://chat?number=%2B977-9800000000

For me, this worked for both desktop and mobile. I replaced + with %2B.

1
Oleg Dmitrochenko On

Viber uses differents links for Desktop and mobile devices.

For mobile devices:

<a href="viber://chat?number=PHONE_WITHOUT_PLUS">Text to Viber</a>

<a href="viber://add?number=PHONE_WITHOUT_PLUS">Add the phone to Viber</a>

For desktop devices:

<a href="viber://chat?number=+PHONE_WITH_PLUS">Text to Viber</a>

<!-- or use %2B = + -->

<a href="viber://chat?number=%2BPHONE_WITH_PLUS">Text to Viber</a>

Viber should be installed.

In the server code need to detect a type of user's device (desktop or mobile) by the user agent or to use CSS rules (example, @min-width()) or JS to show a necessary link.

PHP (without any libraries):

function isMobile($userAgent) { 
    $userAgent = strtolower($userAgent);
    $mobileAgents = array('ipad', 'iphone', 'android', 'pocket', 'palm', 'windows ce', 'windowsce', 'cellphone', 'opera mobi', 'ipod', 'small', 'sharp', 'sonyericsson', 'symbian', 'opera mini', 'nokia', 'htc_', 'samsung', 'motorola', 'smartphone', 'blackberry', 'playstation portable', 'tablet browser');
     
    foreach ($mobileAgents as $value) {    
        if (strpos($userAgent, $value) !== false) return true;   
    };     
    
    return false; 
};
    
// Gets a user agent from the server variable
$agent = $_SERVER['HTTP_USER_AGENT'];
// Gets a user agent from Laravel Request
$agent = request()->userAgent();

$mobile = isMobile($agent);

// Simple PHP output
<?php if($mobile): ?>
   <a href="viber://chat?number=PHONE_WITHOUT_PLUS">Text to Viber</a>
<?php else: ?>
   <a href="viber://chat?number=+PHONE_WITH_PLUS">Text to Viber</a>
<?php endif; ?>

HTML & CSS with the Twitter Bootstrap v5 (Large lg ≥992px):

<a href="viber://chat?number=PHONE_WITHOUT_PLUS" class="d-lg-none">Text to Viber (Mobile)</a>
<a href="viber://chat?number=+PHONE_WITH_PLUS" class="d-none d-lg-block">Text to Viber (Desktop)</a>
0
Viaceslav Vasiljev On

For WhatsUp you can use this link, that will open a chat with you on mobile, just enter your phone without the + sign.

<a href="https://api.whatsapp.com/send?phone=123456789">WhatsUp</a>

0
waruna abeykoon On

For whatsapp it is easy.

use the following format **https://wa.me/123456/** and that's it. here 123456 means your whatsapp number with the country code. Don't include + or preceding 00 just put your number with the country code. like 912232232. Here 91 is country code and the rest is the phone number. this works with the app, and also for whatsapp web.

for Viber this format works with public accounts. if you have a viber username you can use the same method.

https://viber.me/username/ will send you to the page.

this even work for facebook. if your facebook profile is visible to search engines, you can use this method.

use the above format with fb.me/username this will redirect you to the facebook page of the user. I think it works for pages too. but I haven't tried.I believe it should work.

2
Iggy On

Viber link to user should be like this:

viber://contact?number=%2B0000000000000

Use international telephone number format without + but with %2B.