Hello, I need help, I need a script to send messages to WhatsApp using Google Sheet

130 views
Skip to first unread message

Ahmed General

unread,
Feb 23, 2024, 6:35:17 AMFeb 23
to Google Apps Script Community
Hello, I need help, I need a script to send messages to WhatsApp using Google Sheet

Brett Grear

unread,
Feb 24, 2024, 3:15:53 PMFeb 24
to Google Apps Script Community
You'll need to be willing to pay for it then I think. WhatsApp used to allow for a free tier but I think they now charge for all developer initiated messages.  More information available at 
https://developers.facebook.com/docs/whatsapp/

DME

unread,
Mar 14, 2024, 4:33:51 AMMar 14
to google-apps-sc...@googlegroups.com

To send messages to WhatsApp using Google Sheets, you'll need to use a third-party service that provides an API for sending WhatsApp messages. One popular option is Twilio, which offers an API for sending messages to WhatsApp.

Here's a basic example of how you can use Twilio's API with Google Apps Script to send WhatsApp messages from a Google Sheets spreadsheet:

  1. Set up a Twilio account: Sign up for a Twilio account if you don't already have one. You'll need to purchase a phone number that can send WhatsApp messages.

  2. Get your Twilio credentials: After signing up for Twilio, you'll need to get your Account SID and Auth Token from the Twilio console. These will be used to authenticate your requests to the Twilio API.

  3. Write the Google Apps Script code:

javascript
function sendWhatsAppMessage() { var accountId = 'YOUR_TWILIO_ACCOUNT_ID'; var authToken = 'YOUR_TWILIO_AUTH_TOKEN'; var twilioNumber = 'YOUR_TWILIO_PHONE_NUMBER'; var recipientNumber = 'RECIPIENT_PHONE_NUMBER'; // Should be in E.164 format (e.g., +15551234567) var message = 'Hello from Google Sheets!'; var payload = { 'From': 'whatsapp:' + twilioNumber, 'Body': message, 'To': 'whatsapp:' + recipientNumber }; var options = { 'method': 'post', 'payload': payload, 'headers': { 'Authorization': 'Basic ' + Utilities.base64Encode(accountId + ':' + authToken) } }; var response = UrlFetchApp.fetch('https://api.twilio.com/2010-04-01/Accounts/' + accountId + '/Messages.json', options); Logger.log(response.getContentText()); }

Replace 'YOUR_TWILIO_ACCOUNT_ID', 'YOUR_TWILIO_AUTH_TOKEN', 'YOUR_TWILIO_PHONE_NUMBER', and 'RECIPIENT_PHONE_NUMBER' with your actual Twilio account ID, auth token, Twilio phone number, and recipient's phone number respectively.

  1. Run the script: Save the script in the Google Sheets script editor (Extensions > Apps Script), and then run the sendWhatsAppMessage function. This will send the specified message to the recipient's WhatsApp number using Twilio's API.

Please note that sending messages using Twilio's API may incur charges, so make sure you understand Twilio's pricing and usage limits. Additionally, ensure that you comply with Twilio's terms of service and any applicable regulations when sending messages.


--
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/39bcb28b-8432-4499-a2cd-ba0200036fc5n%40googlegroups.com.


--
Reply all
Reply to author
Forward
0 new messages