Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send whatsapp message via Javascript

Hi I would like to know if there is something to send a whatsapp message using javascript or something I was searching but I did not find any new post. This is not for any special purpose. I found this but it only works if you have whatsapp web. I was thinking on clicking on a link to send a default message to a default number

<a href="https://api.whatsapp.com/send?phone=1111111111">Send Message</a>
like image 754
Jiga Garcia Avatar asked Nov 11 '17 21:11

Jiga Garcia


People also ask

How send WhatsApp message in Javascript?

js) → We need to scan this QR from the WhatsAPPWeb from WhatsApp mobile app. var data = [{ id: 1, received: 'Hello', reply: 'Hi'},{ id: 2, received: 'Sorry', reply: 'No problem'},{ id: 3, received: 'Can we have a call? ', reply: 'Please leave a voicemail.

Can I automate sending of WhatsApp messages?

Sure! We only need to install a library called pywhatkit. Then we can schedule messages to send to any of our contacts or even to a group. Here are the 3 steps you need to follow to send WhatsApp messages to contacts and groups using Python.

How use WhatsApp Web with Javascript?

js works by running WhatsApp Web in the background and automating its interaction, you'll need to authorize the client by scanning a QR code from WhatsApp on your phone. Copied! And now we'll modify our code to use this new module: const qrcode = require('qrcode-terminal'); const { Client } = require('whatsapp-web.

Can I use WhatsApp API to send message?

Install the WhatsApp Business API Client — Install your API client. Once your client is working, you can update your application settings. Start using the client — Register your phone number with an API call to /account and send a test message with a call to /messages .


1 Answers

Just make use of this function in web browser to get it running as you want.

Note: You need to run the code manually through browser console with an opened conversation in WhatsApp (web version).

function sendMessage (message) {
  window.InputEvent = window.Event || window.InputEvent;

  var event = new InputEvent('input', {
    bubbles: true
  });

  var textbox = document.querySelector('div._2S1VP');

  textbox.textContent = message;
  textbox.dispatchEvent(event);

  document.querySelector("button._35EW6").click();
}

My gist

Original code

Thanks to Gabriel!

Important: If you're trying to send a message directly from URL (i.e using API), you cant. Its impossible to send WhatsApp messages without user interaction.

like image 92
Renan Coelho Avatar answered Oct 11 '22 12:10

Renan Coelho