Redirecting with Wix location ?

The code I wrote is not working. Can you help me? My js knowledge is very weak.

import wixLocation from ‘wix-location’;

$w.onReady(function () {
// “sendWhatsApp1” adlı butona tıklanınca gerçekleşecek işlem
$w(“#sendWhatsApp1”).onClick((event) => {
// Sayfanın URL’sini al
let currentPageURL = wixLocation.url;

    // Mesaj içeriği
    let message = "Merhabalar! Sayfayı incelemek isterseniz şu linki kullanabilirsiniz: ";

    // WhatsApp'a gönderilecek URL'yi oluştur
    let whatsappURL = "https://api.whatsapp.com/send?phone=908508885206&text=" + encodeURIComponent(message + currentPageURL);

    // WhatsApp'a gönderme işlemi
    wixLocation.to(whatsappURL);
});

});

Where did you find this code?

Normaly…

In short, WhatsApp’s design doesn’t allow automatic message sending without user interaction, ensuring user privacy and preventing spam.

All what your code would do, is to open a whatsapp-browser-window with prefilled message text. An automatic sending of the message would not work. It would need a user-interaction → like a button confirmation-click.

But what would work is —> if you would have the WhattsApp-Business-Package, or using Twilio.

You can test this WHATTSAPP-LINK (entering your own phone-number) → replacing the → 1111111111111111

Before using the shown link → make sure that WHATSAPP is installed on your device.

  1. WhatsApp. Object data sent to HTTP Function
  2. How to receive Whatsapp message from Twilio to Wix?
  3. Send message by whatsaap through twilio