how do i send message from google sheet to whatsapp directly? i am using this script but message not sent no error message display
function sendWhatsAppMessage() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const data = sheet.getDataRange().getValues();
const today = new Date();
for (let i = 1; i < data.length; i++) {
const workerName = data[i][0];
const mobileNumber = data[i][1];
const task = data[i][2];
const taskDate = new Date(data[i][3]);
const reminderDate = new Date(taskDate);
reminderDate.setDate(reminderDate.getDate() - 1);
if (today.getTime() === reminderDate.getTime()) {
var MAYTAPI_PRODUCT_ID = '3xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
var MAYTAPI_TOKEN = 'f1xxxx-xxxx-xxxx-xxxxxxxxxxxx';
var MAYTAPI_PHONE_ID = '5xxxx';
const maytapiUrl = 'https://api.maytapi.com/api/sendMessage'+ MAYTAPI_PRODUCT_ID + "/" + String(MAYTAPI_PHONE_ID) + "/sendMessage?token=" + MAYTAPI_TOKEN;
const payload = {
product_id: '3xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
token: 'f1xxxx-xxxx-xxxx-xxxxxxxxxxxx',
phone: mobileNumber,
text: `Reminder for ${workerName}: ${task}`,
};
const options = {
method: 'post',
contentType: 'application/json',
payload: JSON.stringify(payload),
};
const response = UrlFetchApp.fetch(maytapiUrl, options);
Logger.log(`Message sent to ${workerName}: ${response.getContentText()}`);
}
}
}
What I have tried:
how do i send message from google sheet to whatsapp directly? i am using this script but message not sent no error message display
function sendWhatsAppMessage() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const data = sheet.getDataRange().getValues();
const today = new Date();
for (let i = 1; i < data.length; i++) {
const workerName = data[i][0];
const mobileNumber = data[i][1];
const task = data[i][2];
const taskDate = new Date(data[i][3]);
const reminderDate = new Date(taskDate);
reminderDate.setDate(reminderDate.getDate() - 1);
if (today.getTime() === reminderDate.getTime()) {
var MAYTAPI_PRODUCT_ID = '3xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
var MAYTAPI_TOKEN = 'f1xxxx-xxxx-xxxx-xxxxxxxxxxxx';
var MAYTAPI_PHONE_ID = '5xxxx';
const maytapiUrl = 'https://api.maytapi.com/api/sendMessage'+ MAYTAPI_PRODUCT_ID + "/" + String(MAYTAPI_PHONE_ID) + "/sendMessage?token=" + MAYTAPI_TOKEN;
const payload = {
product_id: '3xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
token: 'f1xxxx-xxxx-xxxx-xxxxxxxxxxxx',
phone: mobileNumber,
text: `Reminder for ${workerName}: ${task}`,
};
const options = {
method: 'post',
contentType: 'application/json',
payload: JSON.stringify(payload),
};
const response = UrlFetchApp.fetch(maytapiUrl, options);
Logger.log(`Message sent to ${workerName}: ${response.getContentText()}`);
}
}
}