Skip to content

Instantly share code, notes, and snippets.

@whatsmate
Last active July 16, 2023 11:05
Show Gist options
  • Save whatsmate/96637d1c46e1a199756f18413e739f7b to your computer and use it in GitHub Desktop.
Save whatsmate/96637d1c46e1a199756f18413e739f7b to your computer and use it in GitHub Desktop.
Sending a WhatsApp message from Google Apps Script
function main() {
var destNumber = "12025550108"; // TODO: Specify the recipient's number here. NOT THE GATEWAY NUMBER!
var message = "Aloha, this is my first message.";
sendWhatsapp(destNumber, message);
}
function sendWhatsapp(destNumber, message) {
var instanceId = "YOUR_INSTANCE_ID_HERE"; // TODO: Replace it with your gateway instance ID here
var clientId = "YOUR_CLIENT_ID_HERE"; // TODO: Replace it with your Forever Green client ID here
var clientSecret = "YOUR_CLIENT_SECRET_HERE"; // TODO: Replace it with your Forever Green client secret here
var jsonPayload = JSON.stringify({
number: destNumber,
message: message
});
var options = {
"method" : "post",
"contentType": "application/json",
"headers": {
"X-WM-CLIENT-ID": clientId,
"X-WM-CLIENT-SECRET": clientSecret
},
"payload" : jsonPayload,
"Content-Length": jsonPayload.length
};
UrlFetchApp.fetch("http://api.whatsmate.net/v3/whatsapp/single/text/message/" + instanceId, options);
}
@whatsmate
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment