whatsapp

705 views
Skip to first unread message

Pravenesh B

unread,
Apr 13, 2023, 3:21:39 AM4/13/23
to Google Apps Script Community
Hi, its possible to send a bulk message in whatsapp using Google sheets (app script/ extenstion)

Nerio Villalobos

unread,
Apr 13, 2023, 7:35:14 AM4/13/23
to google-apps-sc...@googlegroups.com
Yes, it is possible to send bulk messages in WhatsApp using Google Sheets and Apps Script. However, it is important to note that automated or bulk messaging violates WhatsApp's terms of service and can result in your account being banned.

Assuming that you want to send personalized messages to a list of contacts, here's a high-level overview of the process:

Import the contact list into a Google Sheet.
Write an Apps Script function that reads the contact information and sends personalized messages to each contact using the WhatsApp API.
Use a WhatsApp API provider to send the messages.
Here are the steps in more detail:

Import the contact list into a Google Sheet:
You can create a Google Sheet and import the contact list into it. Make sure the contact information is organized into separate columns (e.g., name, phone number, message).

Write an Apps Script function that sends personalized messages to each contact:
You can write a script that reads the contact information from the Google Sheet and sends personalized messages to each contact using the WhatsApp API. Here's an example code snippet to get you started:

function sendWhatsappMessages() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var range = sheet.getDataRange();
  var values = range.getValues();
  var whatsapp = 'https://api.whatsapp.com/send?phone=';
 
  for (var i = 1; i < values.length; i++) {
    var name = values[i][0];
    var phone = values[i][1];
    var message = values[i][2];
    var encodedMessage = encodeURIComponent(message);
    var url = whatsapp + phone + '&text=' + encodedMessage;
    var options = {
      'method': 'get',
      'headers': {
        'User-Agent': 'Mozilla/5.0'
      }
    };
    UrlFetchApp.fetch(url, options);
  }
}

This script reads the contact information from the active sheet, iterates through each row, and sends a personalized message to each contact using the WhatsApp API.

Use a WhatsApp API provider to send the messages:
Finally, you need to use a WhatsApp API provider to actually send the messages. There are several WhatsApp API providers available, such as Twilio or Nexmo. You will need to sign up for an account with one of these providers and obtain an API key to use their API. Once you have the API key, you can modify the script above to use the API provider's URL and authentication method.

It's important to note that sending bulk messages is against WhatsApp's terms of service and can result in your account being banned. Use this approach with caution and only for legitimate, non-spammy purposes.

El jue, 13 abr 2023 a la(s) 04:21, 'Pravenesh B' via Google Apps Script Community (google-apps-sc...@googlegroups.com) escribió:
Hi, its possible to send a bulk message in whatsapp using Google sheets (app script/ extenstion)

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/1b5394b1-af1b-426f-beb5-e225be1bdcb2n%40googlegroups.com.


--
__________________________
Nerio Enrique Villalobos Morillo
Buenos Aires, Argentina

Abhimanyu Kumar Singh

unread,
Apr 13, 2023, 8:28:55 AM4/13/23
to ner...@gmail.com, google-apps-sc...@googlegroups.com
Dear nervill,

Thanks for your valuable knowledge !!

With the help of your code , i change the code to generate a link and the same has to be added in the google sheet :-

Message is not getting triggered to each user while running the functions successfully.

I have to manually go to each and every user link and then have to deliver the message.

Is it possible to deliver the message to people automatically by taking a prime number or base number sfrom which the message has to be delivered?


function sendWhatsappMessages() {

  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("whatsappmessage");
  var range = sheet.getDataRange();
  var values = range.getValues();
  var whatsapp = 'https://api.whatsapp.com/send?phone=';
 
  for (var i = 1i <= values.lengthi++) {
    var name = values[i][0];
    var phone = values[i][1];
    var message = values[i][2];
    var encodedMessage = encodeURIComponent(message);
    Logger.log(name+', '+phone+', '+'message'+', '+encodedMessage)
    var url = whatsapp + phone + '&text=' + encodedMessage;
    Logger.log(url)
    var options = {
      'method''get',
      'headers': {
        'User-Agent''Mozilla/5.0'
      }
    };
    UrlFetchApp.fetch(urloptions);
    sheet.getRange(i+1,4).setValue(url);
  }
}






--
Regards,
Abhimanyu Kr. Singh 
📚 Data Analyst
📲  7903679668


Mailtrack Sender notified by
Mailtrack
04/13/23, 05:56:16 PM
Reply all
Reply to author
Forward
0 new messages