multi number sms suport

This commit is contained in:
2026-09-03 18:48:00 +05:00
parent c2a0846949
commit 02b0577ce2
3 changed files with 158 additions and 39 deletions
+88 -17
View File
@@ -242,6 +242,15 @@
z-index: 100;
}
.input-hint {
display: block;
margin-top: -8px;
margin-bottom: 12px;
font-size: 12px;
color: #888;
}
.modal {
background: var(--bg-secondary);
border-radius: 16px;
@@ -315,7 +324,8 @@
<div class="modal-overlay" id="compose-modal" onclick="if(event.target===this)closeCompose()">
<div class="modal">
<h2>New Message</h2>
<input type="tel" id="compose-to" placeholder="Phone number">
<input type="text" id="compose-to" placeholder="Phone numbers, separated by commas" autocomplete="off">
<small class="input-hint"> Enter multiple phone numbers separated by commas </small>
<textarea id="compose-msg" placeholder="Message"></textarea>
<p class="error-msg" id="compose-error"></p>
<div class="modal-actions">
@@ -495,27 +505,88 @@
}
async function sendCompose() {
const to = document.getElementById('compose-to').value.trim();
const toInput = document.getElementById('compose-to').value.trim();
const text = document.getElementById('compose-msg').value.trim();
if (!to || !text) { document.getElementById('compose-error').textContent = 'Fill all fields'; return; }
const error = document.getElementById('compose-error');
error.textContent = '';
if (!toInput) {
error.textContent = 'Please enter at least one phone number';
return;
}
if (!text) {
error.textContent = 'Please enter a message';
return;
}
// Split numbers by comma
const recipients = toInput
.split(',')
.map(number => number.trim())
.filter(number => number.length > 0);
// Remove duplicate numbers
const uniqueRecipients = [...new Set(recipients)];
if (uniqueRecipients.length === 0) {
error.textContent = 'Please enter at least one phone number';
return;
}
// Basic phone number validation
const invalidNumber = uniqueRecipients.find(number => {
return !/^\+?[0-9\s\-()]+$/.test(number);
});
if (invalidNumber) {
error.textContent = `Invalid phone number: ${invalidNumber}`;
return;
}
const sendButton = document.querySelector(
'#compose-modal .modal-actions button:last-child'
);
sendButton.disabled = true;
sendButton.textContent = 'Sending...';
try {
const r = await fetch('/api/sms/send', {
const response = await fetch('/api/sms/send', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-API-Key': apiKey },
body: JSON.stringify({ to, text })
headers: {
'Content-Type': 'application/json',
'X-API-Key': apiKey
},
body: JSON.stringify({
to: uniqueRecipients,
text: text
})
});
if (r.ok) {
closeCompose();
await loadMessages();
openThread(to);
} else {
const e = await r.json();
document.getElementById('compose-error').textContent = e.error || 'Failed';
}
} catch (e) { document.getElementById('compose-error').textContent = 'Error'; }
}
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || 'Failed to send SMS');
}
closeCompose();
await loadMessages();
// Open the conversation when sending to one number
if (uniqueRecipients.length === 1) {
openThread(uniqueRecipients[0]);
}
} catch (err) {
error.textContent = err.message || 'Failed to send SMS';
} finally {
sendButton.disabled = false;
sendButton.textContent = 'Send';
}
}
function showAbout() { document.getElementById('about-modal').style.display = 'flex'; }
function closeAbout() { document.getElementById('about-modal').style.display = 'none'; }
@@ -531,4 +602,4 @@
setInterval(() => { if (apiKey) { loadMessages(); } }, 15000);
</script>
</body>
</html>
</html