APPS SCRIPT SMS : Send SMS by Google apps script and textlocal - CodyLab

TEXTLOCAL SMS EXAMPLE IN APPS SCRIPT

         In this example, We have tried to show the textlocal API integeration in Google Script. And make it able to send sms  to the particular customer. With this goal, Lets move to next step.
        First we need to move to the apps script page and create a new app. And paste the following code into the Code.gs file.
YOU NEED TO MAKE CHANGE IN FOLLOWING:
  # MOBILE NUMBER PUT YOUR OR OTHER NUMBER WHOM YOU WANT TO SEND SMS.
# YOUR API KEY PUT YOUR API KEY LOOK ALIKE " MzI1YXXXXXXXXXXXXXXXXXX5NzE=" .

Code.gs     

function doGet() {
 var x;
     x = HtmlService.createTemplateFromFile('Index').evaluate();
     x.setTitle("Send SMS | TextLocal API");
    return x;
}

function myFunction(sd) {
  var numbers = "&numbers=" + " MOBILE NUMBER ";
  var message = "&message=" + "This is your message";
  var apiKey = "apikey=" + " YOUR API KEY ";
  var sender = "&sender=" + "TXTLCL";

  var url = "https://api.textlocal.in/send/?"+apiKey + numbers + message + sender;
  var options = {
  "async"true,
  "crossDomain"true,
  "method""GET"
}
  var response = UrlFetchApp.fetch(urloptions).getContentText();
  return response;
}


In Above code, you have to put your textlocal API, and mobile number or numbers seprated by
commas and your own message. After changing, save your file. And move to next step.
Now Create a new html file, Rename it as 'Index.html'. And Paste the following code
in it. And save.


Index.html

<!DOCTYPE html>
<html>
  <head>
     <base target="_top" />
     <h2>SEND SMS | TEXTLOCAL  API | JAVASCRIPT | APPS SCRIPT</h2>
     <style>
input,textarea {
  width: 40%;
  padding: 12px 20px;
  margin: 8px 0;
  display: inline-block;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
}
textarea{height:200px;}
</style>
  </head>
  <body align="center">
    <div id="result"></div>
       <br>
    <input type="tel"id="number" placeholder="Mobile number"/>
      <br>  
    <textarea id="text" min="0" max="100" placeholder="Write massage here..." 
height="400px"></textarea>
      <br>  
    <input type="submit" value="SEND" onclick="sendSMS()"/>
    <script>
      function sendSMS() {
        let number = document.querySelector('#number').value;
        let text = document.querySelector('#text').value;

         let nt = [number,text];
         let updateLocation = document.querySelector('#result');

         function onFailure(error){
          updateLocation.innerHTML = `<span style="color:red">${error}</span>`;;

        };
        
        function onSuccess(response){
          updateLocation.innerHTML = "<span style='color:green'>"+response+"</span>";

        };
        updateLocation.innerHTML = "Processing.....";
        google.script.run.withFailureHandler(onFailure)
                         .withSuccessHandler(onSuccess)
                         .mPro(nt);

      };
    </script>
  </body>
</html>
After saving both file name 'Code.gs and Index.html' Deploy it as google web app and enjoy.
>>>TRY TO CHECK OUT , IF ANY ERROR FOUND. PLEASE LET ME KNOW BY COMMENT.
I'LL TRY MY LEVEL BEST TO FIX THE PROBLEM.
THANKS FOR VISITING CodyLab
                                                                                 Have a nice day!
-------------------------- -------------------------
Donate me through - PayPal or RozorPay or Paytm

Post a Comment

Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.