Last active
July 16, 2023 11:05
-
-
Save whatsmate/96637d1c46e1a199756f18413e739f7b to your computer and use it in GitHub Desktop.
Sending a WhatsApp message from Google Apps Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Details: http://whatsmate.github.io/2016-07-02-send-whatsapp-message-google-apps-script/