Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
4 changes: 4 additions & 0 deletions public/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ <h1>Fullsend</h1>
<div class="row mt-5">
<div class="col">
<h2>Changelog</h2><br>
<h3>v1.7.0</h3>
<p>
Refactors SMS code to handle upcoming API deprecation
</p>
<h3>v1.6.2</h3>
<p>
Adds <a href="/terms">terms of service</a> and <a href="/privacy">privacy policy</a>
Expand Down
33 changes: 19 additions & 14 deletions src/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (?, ?)";

Expand All @@ -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}`);
}
};