_68// Twilio Notify API to send bulk SMS with the same message (body) as one API request
_68// Upload notifyList.txt as a private Twilio asset
_68// notifyList.txt format (comma separated numbers w/wo spaces): +15105550100, +15105550101, +15105550102, +15105550103
_68// Execute Syntax: https://x.x.x.x/<path>?queryParamPasscode=8675309
_68// (change passcode below, replace this method with a secure auth method in production)
_68// Make sure under Functions Global Config tab:
_68// "Add my Twilio Credentials (ACCOUNT_SID) and (AUTH_TOKEN) to ENV" is CHECKED
_68const fs = require('fs');
_68// Add node-fetch 2.6.0 as a dependency under Settings, Dependencies
_68const fetch = require('node-fetch');
_68//** START NECESSARY CONFIGURATION**
_68// You must define your unique Twilio Notify SID - https://www.twilio.com/console/notify/services below
_68// Notify will make use of a Twilio Messaging Service which you also need to define with a Twilio number(s)
_68// https://www.twilio.com/console/sms/services
_68const notifySid = 'IS076575.....';
_68const passCode = '8675309'; // CHANGE THIS
_68// Notify Bulk Message Body to Send
_68const bulkMsgBody = '😸 Hello from Winston 😸';
_68//** END NECESSARY CONFIGURATION**
_68exports.handler = function (context, event, callback) {
_68 const params = new URLSearchParams();
_68 const queryParamPasscode = event.queryParamPasscode;
_68 const fileName = '/notifyList.txt';
_68 const file = Runtime.getAssets()[fileName].path;
_68 const numbers = fs.readFileSync(file, 'utf8').trim();
_68 // Must pass a URL query parameter of queryParamPasscode with the value of passCode to execute
_68 if (queryParamPasscode != passCode) return callback('invalid operation'); // You can change the error message
_68 params.append('Body', bulkMsgBody);
_68 numbers.split(',').forEach((number) => {
_68 `{ "binding_type": "sms", "address": "${number}" }`
_68 new Buffer.from(`${context.ACCOUNT_SID}:${context.AUTH_TOKEN}`).toString(
_68 fetch(`https://notify.twilio.com/v1/Services/${notifySid}/Notifications`, {
_68 .then((res) => res.json())
_68 return callback(null, { result: 'success' });
_68 console.error(error);
_68 return callback({ result: 'error' });