Created
November 22, 2020 15:44
-
-
Save nidhinkumar06/8eff9261ae58b503c8270f41a612be0c to your computer and use it in GitHub Desktop.
Twilio Balance Checker
This file contains hidden or 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 checkTwilioBalance() { | |
| var options = {}; | |
| options.headers = {"Authorization": "Basic " + Utilities.base64Encode('AC123abc45678901c3ff481ea2' + ":" + 'baa9fe5ad79a7a97dxxx00c012a3d4ce')}; | |
| var url = 'https://api.twilio.com/2010-04-01/Accounts/AC123abc45678901c3ff481ea2/Balance.json'; | |
| var response = UrlFetchApp.fetch(url, options); | |
| //parse JSON | |
| var json = response.getContentText(); | |
| var data = JSON.parse(json); | |
| Logger.log('data is', data); | |
| const balance = parseFloat(data.balance); | |
| if(balance < 7) { | |
| var subject = 'RE: Recharge Twilio balance for Your Project'; | |
| var body = "Hi, \n\n I hope you are doing well. Please recharge the Twilio account of your project ASAP. \n Current Balance is $ " + balance + " \n\n Note: This is an auto generated email."; | |
| sendEmail(subject, body); | |
| } | |
| } | |
| function sendEmail(subject, body) { | |
| // REPLACE THE EMAIL ADDRESS WITH VALID ONE | |
| var receipient = '[email protected]'; | |
| var CarbonCopyEmails = '[email protected], [email protected]'; | |
| GmailApp.sendEmail(receipient, subject, body, {cc: CarbonCopyEmails}); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment