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

8

17

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?

Codycoe answered 25/12, 2016 at 20:41 Comment(0)
W
18

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/

Worn answered 25/12, 2016 at 20:53 Comment(3)
Thank you, but this will send a predefined message to me, isn't it, and I don't want that, I do want to open a chat windows on visitor's PC so he/she can type me his own message. Is it possible? Still see no docs on this on Viber and WA sites.Codycoe
And no, I don't want to establish public account on Viber for this very purpose, I'd like to have a chat with my ordinary Viber account!Codycoe
Text param does nothing as of 2021. It seem to work if you do href="viber://forward?text=test" but not if you do href="viber://chat?number=%2B1111111&text=test" it opens an empty chat.V
R
16

Viber link to user should be like this:

viber://contact?number=%2B0000000000000

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

Recession answered 7/1, 2019 at 17:4 Comment(2)
Is that working for desktop app and mobile app?Nathalie
@Recession Thank you for the %2B - I was having issues with the link not working for Android devices, and working for iOS, when formatted like this viber://contact?number=+0000000000000. When I omitted the plus sign, Android devices had no issues, but iOS had issues. Using URL encoded version of the plus sign / %2B worked universally.Contrayerva
B
6

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.

Bracketing answered 18/5, 2018 at 20:41 Comment(0)
S
4
viber://chat?number=%2B977-9800000000

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

Staceestacey answered 1/9, 2021 at 5:59 Comment(0)
R
3

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>

Revet answered 2/7, 2018 at 9:24 Comment(0)
N
3

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.

Nacelle answered 24/11, 2018 at 22:39 Comment(0)
A
2

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.

Ailyn answered 21/8, 2018 at 7:47 Comment(0)
H
1

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>
Hennie answered 27/2, 2021 at 11:30 Comment(1)
Thank you. By the current date, the link with +PHONE_WITH_PLUS works for both Desktop & mobile.Legging

© 2022 - 2024 — McMap. All rights reserved.