diff --git a/package-lock.json b/package-lock.json index fc73015..c9bcbb7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "fullsend", - "version": "1.6.2", + "version": "1.7.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "fullsend", - "version": "1.6.2", + "version": "1.7.0", "license": "MIT", "dependencies": { "bcryptjs": "^2.4.3", diff --git a/package.json b/package.json index a2875e5..f3869a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fullsend", - "version": "1.6.2", + "version": "1.7.0", "description": "Fullsend allows allowed users to send bulk text messages to groups of recipients", "main": "server.js", "scripts": { diff --git a/public/help.html b/public/help.html index 86789ba..882741d 100644 --- a/public/help.html +++ b/public/help.html @@ -63,6 +63,10 @@
+ Refactors SMS code to handle upcoming API deprecation +
Adds terms of service and privacy policy diff --git a/src/messages.js b/src/messages.js index 9282d6d..703d878 100644 --- a/src/messages.js +++ b/src/messages.js @@ -17,7 +17,7 @@ const client = new twilio( ); const MESSAGE_ADD = - "INSERT INTO messages (`id`, `user_id`, `text`, `sent_at`) VALUES (null, ?, ?, NOW())"; +"INSERT INTO messages (`id`, `user_id`, `text`, `sent_at`) VALUES (null, ?, ?, NOW())"; const MESSAGE_GROUP_ADD = "INSERT INTO messages_groups VALUES (?, ?)"; const MESSAGE_CONTACT_ADD = "INSERT INTO messages_contacts VALUES (?, ?)"; @@ -39,39 +39,44 @@ exports.sendMessage = async (pool, userId, text, groups, individuals) => { group, ]); } - + for (const id of individuals) { const number = (await contactsApi.getContactPhone(pool, id)).data[0] - .phone_number; + .phone_number; numbers.add(number); await execQuery(pool, MESSAGE_CONTACT_ADD, [ messageAdded.data.insertId, id, ]); } - + let binding = []; - + const userPhoneNumber = await usersApi.getUserPhoneNumber(pool, userId); - + if (userPhoneNumber) numbers.add(userPhoneNumber); - + for (const number of numbers) { binding.push(JSON.stringify({ binding_type: "sms", address: number })); } - + if (SENDING_ENABLED) { try { - await client.notify.services(TWILIO_SID).notifications.create({ - toBinding: binding, - body: cleanText, - }); + for (const number of numbers) { + await client.messages.create({ + from: TWILIO_FROM, + to: number, + body: cleanText + }); + } } catch (err) { console.error(err); } } else { console.log("Sending disabled..."); - console.log(binding); - console.log(cleanText); + for (const number of numbers) { + console.log(`to: ${number}`); + } + console.log(`body: ${cleanText}`); } };