Reputation: 35
Is it possible to automatically send WhatsApp messages if someone fills my google form,currently storing data into a google sheet. In this form, users fill in their Name and phone number. I want to automatically send them a welcome message when they fill the form. I have successfully sent a welcome email in a similar google form with the help of App Script.
This is what I did in case of email:
function sendMail() {
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("CRM").activate()
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow();
var quotaLeft = MailApp.getRemainingDailyQuota();
// Logger.log(quotaLeft)
if((lr-1) > quotaLeft){
Browser.msgBox("You have only " + quotaLeft + " E-mail left, mails were not sent")
} else{
for(var i=2; i<=lr;i++){
var currentEmail = ss.getRange(i, 1).getValue();
var currentSub = ss.getRange(i, 3).getValue();
var currentName = ss.getRange(i, 2).getValue();
var templateText = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Templates").getRange(i, 2).getValue();
var name = templateText.replace("{name}", currentName);
MailApp.sendEmail(currentEmail, currentSub, name)
}
Browser.msgBox("Welcome emails sent")
}
}
Upvotes: 1
Views: 2262
Reputation: 624
Register in https://panel.rapiwha.com/landing/login.php. Link your number and get the API Key.
Put the below code in your sheet Install a Trigger "On Form Submit"
//
//
function onFormSubmit(e) {
var today=new Date();
var shtname = e.source.getActiveSheet().getName();
switch (shtname) {
case "SaleOrder":
var resp = e.source.getActiveSheet().getRange(e.range.rowStart,1, e.range.rowStart,4 ).getValues();
//name is the first question
//mobile no is second question (with country code, without + sign)
var api_key="xxxxxx"; //from rapiwah
var wup = "Dear " +resp[0][1]+" Thank you for contacting us. We will get back yo you soon";
var formurl2= 'https://panel.rapiwha.com/send_message.php?apikey='+api_key+'&number=' + resp[0][2] +'&text='+wup;
var formurl3 = formurl2.replace(/#/g, "");
var formurl4 = formurl3.replace(/,/g, "");
var formurl = formurl4.replace(/ /g, "%20");
var response = UrlFetchApp.fetch(formurl);
break;
//
default:
break;
}
}
Upvotes: 0
Reputation: 624
It's possible if you use twillo. Try the below code
function sampletTextMessage(){
var ACCOUNT_SID = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var ACCOUNT_TOKEN = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var options = {
"method" : "post",
'headers' : {
"Authorization" : "Basic " + Utilities.base64Encode(ACCOUNT_SID + ":" + ACCOUNT_TOKEN),
},
'payload' :{
'Body' : 'Your Twilio code is 1238432',
'To' : 'whatsapp:+91XXXXXXXXX3',
'From': 'whatsapp:+1XXXXXXXXX6',
},
'muteHttpExceptions' : true
};
var url="https://api.twilio.com/2010-04-01/Accounts/" + ACCOUNT_SID + "/Messages.json";
var response = UrlFetchApp.fetch(url,options);
Logger.log(response);
}
Upvotes: 2