Text messaging Receive only: database 4.3.6 adds sms_providers.sms_provider_send, and a provider set to Receive only in its window takes texts in as tickets, replies and codes and texts nothing out (no Text reply, ticket number, STOP or HELP answers, texts to clients or test texts), needs no SID or secret, cancels the texts waiting to go when switched, and is shown on Text Messaging, Text Messages, Notifications and Tickets settings and in the reply box of a ticket that came in by text, with the number to call; 26.12.3 changelog

This commit is contained in:
johnnyq
2026-12-01 12:42:51 -05:00
parent 89645add5e
commit abcd1a6fcf
11 changed files with 174 additions and 27 deletions

View File

@@ -0,0 +1,23 @@
<?php
/*
* ITFlow - Database update to version 4.3.6 (from 4.3.5)
* Included by admin/database_updates.php - do not access directly
*
* sms_providers.sms_provider_send - whether texts go out through the provider (1), or it only takes texts in (0,
* Receive only: texts to the number still become tickets, replies and codes, and nothing is texted - for a number
* that can't send yet, or a service where sending is a hassle to set up). Every provider set up already sends.
*
* Re-runnable: the column is made only where it isn't there.
*/
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
$itflow_sms_table = mysqli_query($mysqli, "SELECT 1 FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'sms_providers' LIMIT 1");
if ($itflow_sms_table && mysqli_num_rows($itflow_sms_table) > 0) {
$itflow_send_exists = mysqli_query($mysqli, "SELECT 1 FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'sms_providers' AND COLUMN_NAME = 'sms_provider_send' LIMIT 1");
if (!$itflow_send_exists || mysqli_num_rows($itflow_send_exists) === 0) {
mysqli_query($mysqli, "ALTER TABLE `sms_providers` ADD `sms_provider_send` tinyint(1) NOT NULL DEFAULT 1 AFTER `sms_provider_active`");
}
}

View File

@@ -2,8 +2,9 @@
/*
* Admin > Text Messaging - one provider's window: Add (no id, or from sms_provider_add.php)
* or Edit. Its SID and secret - the secret never put back into the page, so left empty it
* stays - the number texts go from, and whether it is on. Save asks first (check_sms_provider,
* or Edit. Whether it sends and receives or is Receive only (database 4.3.6), its SID and
* secret - needed only to send; the secret never put back into the page, so left empty it
* stays - your number, and whether it is on. Save asks first (check_sms_provider,
* admin/post/sms_provider.php): what is wrong shows beside each field and the window stays
* open; once all is right, it saves.
*/
@@ -28,6 +29,9 @@ $free_kinds = array_diff_key($kinds, $taken);
$name = $row ? (string) $row['sms_provider_name'] : (string) (array_key_first($free_kinds) ?? array_key_first($kinds));
$kind = $kinds[$name] ?? reset($kinds);
$number = $row ? smsNumberText($row['sms_provider_number']) : '';
// Send and receive, or Receive only - after the 4.3.6 database update
$can_receive_only = smsColumnExists('sms_providers', 'sms_provider_send');
$sends = !$row || smsSends($row);
// Where what is wrong with a field shows
$error_for = function ($field) {
@@ -69,12 +73,26 @@ ob_start();
<div class="mb-3">
<div class="form-check form-switch">
<input type="checkbox" class="form-check-input" name="active" value="1" id="smsProviderActive" <?= intval($row['sms_provider_active']) ? 'checked' : '' ?>>
<label class="form-check-label" for="smsProviderActive">On - texts go out, and texts to the number come in</label>
<label class="form-check-label" for="smsProviderActive">On - texts to the number come in<?= $sends ? ', and texts go out' : '' ?></label>
</div>
<div class="form-text ps-5">Off, nothing is texted and texts to the number aren't taken in. Texts waiting to go wait.</div>
</div>
<?php } ?>
<?php if ($can_receive_only) { ?>
<div class="mb-3" data-sms-send-choice>
<label class="form-label d-block">Texts</label>
<div class="btn-group flex-wrap" role="group" aria-label="Texts">
<input type="radio" class="btn-check" name="send" value="1" id="smsProviderSend" <?= $sends ? 'checked' : '' ?>>
<label class="btn btn-outline-secondary" for="smsProviderSend"><i class="fas fa-fw fa-exchange-alt me-1"></i>Send and receive</label>
<input type="radio" class="btn-check" name="send" value="0" id="smsProviderReceiveOnly" <?= $sends ? '' : 'checked' ?>>
<label class="btn btn-outline-secondary" for="smsProviderReceiveOnly"><i class="fas fa-fw fa-inbox me-1"></i>Receive only</label>
</div>
<div class="form-text" data-sms-send-help="1" <?= $sends ? '' : 'hidden' ?>>Texts come in, and ITFlow texts back: replies on tickets, the ticket number for a new one, and the texts to clients in Settings &gt; Notifications.</div>
<div class="form-text" data-sms-send-help="0" <?= $sends ? 'hidden' : '' ?>>Texts to your number still become tickets, replies on tickets and verification codes - nothing is texted out. Replies go by email or the portal. No keys are needed, and the number doesn't have to be registered for sending.<?= $row && $sends ? ' Texts waiting to go are cancelled when you save.' : '' ?></div>
</div>
<?php } ?>
<div class="mb-3">
<label class="form-label" for="smsProviderDescription">Description</label>
<div class="input-group has-validation">
@@ -85,20 +103,21 @@ ob_start();
</div>
<div class="mb-3">
<label class="form-label" for="smsProviderNumber">Number texts go from <strong class="text-danger">*</strong></label>
<label class="form-label" for="smsProviderNumber">Your number <strong class="text-danger">*</strong></label>
<div class="input-group has-validation">
<span class="input-group-text"><i class="fas fa-fw fa-phone"></i></span>
<input type="tel" class="form-control" name="number" id="smsProviderNumber" maxlength="30" placeholder="+1 412 555 0100" value="<?= escapeHtml($number) ?>">
</div>
<?= $error_for('number') ?>
<div class="form-text">SMS-enabled in <?= escapeHtml($name) ?>'s portal - and, for a US number, registered for texting there, or carriers block what it sends.</div>
<div class="form-text">SMS-enabled in <?= escapeHtml($name) ?>'s portal - and, to send from a US number, registered for texting there, or carriers block what it sends.</div>
</div>
<h6 class="fw-semibold mt-4 mb-1">Keys</h6>
<p class="small text-body-secondary mb-2">From <a href="<?= escapeHtml($kind['portal_url']) ?>" target="_blank" rel="noopener noreferrer"><?= escapeHtml($name) ?>'s portal <i class="fas fa-external-link-alt fa-xs"></i></a> - the gear at the top right, then API Keys.</p>
<p class="small text-body-secondary mb-2">From <a href="<?= escapeHtml($kind['portal_url']) ?>" target="_blank" rel="noopener noreferrer"><?= escapeHtml($name) ?>'s portal <i class="fas fa-external-link-alt fa-xs"></i></a> - the gear at the top right, then API Keys.
<span data-sms-keys-optional <?= $sends ? 'hidden' : '' ?>>Only needed to send - leave them empty for Receive only, or fill them in now for later.</span></p>
<div class="mb-3">
<label class="form-label" for="smsProviderUsername"><?= escapeHtml($kind['username_label']) ?> <strong class="text-danger">*</strong></label>
<label class="form-label" for="smsProviderUsername"><?= escapeHtml($kind['username_label']) ?> <strong class="text-danger" data-sms-key-needed <?= $sends ? '' : 'hidden' ?>>*</strong></label>
<div class="input-group has-validation">
<span class="input-group-text"><i class="fas fa-fw fa-id-badge"></i></span>
<input type="text" class="form-control font-monospace" name="username" id="smsProviderUsername" maxlength="250" spellcheck="false" value="<?= escapeHtml($row['sms_provider_username'] ?? '') ?>">
@@ -107,7 +126,7 @@ ob_start();
</div>
<div class="mb-3">
<label class="form-label" for="smsProviderSecret"><?= escapeHtml($kind['secret_label']) ?> <?= $row ? '' : '<strong class="text-danger">*</strong>' ?></label>
<label class="form-label" for="smsProviderSecret"><?= escapeHtml($kind['secret_label']) ?> <?= $row ? '' : '<strong class="text-danger" data-sms-key-needed' . ($sends ? '' : ' hidden') . '>*</strong>' ?></label>
<div class="input-group has-validation">
<span class="input-group-text"><i class="fas fa-fw fa-key"></i></span>
<input type="password" class="form-control font-monospace" name="secret" id="smsProviderSecret" maxlength="500" spellcheck="false" autocomplete="new-password"
@@ -147,6 +166,16 @@ ob_start();
var save = form.querySelector('[data-sms-provider-save]');
var checked = false;
// Send and receive, or Receive only - which help shows, and whether the keys are needed
form.querySelectorAll('input[name="send"]').forEach(function (radio) {
radio.addEventListener('change', function () {
var sends = form.querySelector('input[name="send"]:checked').value === '1';
form.querySelectorAll('[data-sms-send-help]').forEach(function (el) { el.hidden = el.getAttribute('data-sms-send-help') !== (sends ? '1' : '0'); });
form.querySelectorAll('[data-sms-key-needed]').forEach(function (el) { el.hidden = !sends; });
form.querySelectorAll('[data-sms-keys-optional]').forEach(function (el) { el.hidden = sends; });
});
});
function clearErrors() {
form.querySelectorAll('.is-invalid').forEach(function (el) { el.classList.remove('is-invalid'); });
form.querySelectorAll('[data-error-for]').forEach(function (el) {

View File

@@ -45,10 +45,14 @@ if (isset($_POST['check_sms_provider']) || isset($_POST['add_sms_provider']) ||
$name = $after['sms_provider_name'];
$number = smsNumberText($after['sms_provider_number']);
$receive_only = isset($after['sms_provider_send']) && intval($after['sms_provider_send']) === 0;
if (!$before) {
$provider_id = smsProviderWrite($after);
logAudit("Text Message", "Create", "$session_name added texting provider " . escapeSql("$name, texting from $number"), 0, $provider_id);
flashAlert('<strong>' . escapeHtml($name) . '</strong> created, texting from <strong>' . escapeHtml($number) . '</strong> - paste the address texts come back to into its portal, then send a test text');
logAudit("Text Message", "Create", "$session_name added texting provider " . escapeSql("$name, " . ($receive_only ? "receive only, at $number" : "texting from $number")), 0, $provider_id);
flashAlert($receive_only
? '<strong>' . escapeHtml($name) . '</strong> created, receive only, at <strong>' . escapeHtml($number) . '</strong> - paste the address texts come back to into its portal, then text the number to try it'
: '<strong>' . escapeHtml($name) . '</strong> created, texting from <strong>' . escapeHtml($number) . '</strong> - paste the address texts come back to into its portal, then send a test text');
redirect('text_messaging.php');
}
@@ -58,8 +62,13 @@ if (isset($_POST['check_sms_provider']) || isset($_POST['add_sms_provider']) ||
redirect();
}
smsProviderWrite($after, $provider_id);
// Set to Receive only - texts waiting to go would go late, or never
$cancelled = $receive_only && smsSends($before) ? smsCancelWaiting("Texts don't go out - Text Messaging was set to Receive only") : 0;
if ($cancelled) {
$lines[] = "$cancelled text" . ($cancelled === 1 ? '' : 's') . " waiting to go cancelled";
}
logAudit("Text Message", "Edit", "$session_name changed texting provider " . escapeSql("$name: " . implode('; ', $lines)), 0, $provider_id);
flashAlert('<strong>' . escapeHtml($name) . '</strong> saved - ' . escapeHtml(count($lines) === 1 ? $lines[0] : count($lines) . ' changes'));
flashAlert('<strong>' . escapeHtml($name) . '</strong> saved - ' . escapeHtml(count($lines) === 1 ? $lines[0] : implode('; ', $lines)));
redirect();
}
@@ -136,6 +145,10 @@ if (isset($_POST['send_sms_test'])) {
flashAlert('Turn the texting provider on first.', 'error');
redirect();
}
if (!smsSends($row)) {
flashAlert('It is set to Receive only, so nothing is texted - text your number to try it instead.', 'error');
redirect();
}
$number = smsNumber((string) ($_POST['number'] ?? ''));
$text = trim((string) ($_POST['text'] ?? ''));
if ($number === '') {

View File

@@ -75,7 +75,9 @@ echo settingsPageStart('notification');
<?php if (smsColumnExists('settings', 'config_sms_client_tickets')) {
$sms_client = smsClientSettings(); ?>
<?= settingsSectionStart('texts', 'Texts to clients', 'What ITFlow texts your clients by itself - only to contacts who agreed to texts, on their contact or in the client portal. Texts that would land between ' . date('g A', mktime(SMS_QUIET_FROM, 0)) . ' and ' . date('g A', mktime(SMS_QUIET_UNTIL, 0)) . ' wait for the morning. A reply to one about a ticket goes on the ticket.') ?>
<?php if (!smsReady()) { ?>
<?php if (smsReceiveOnly()) { ?>
<div class="alert alert-light border py-2 small" data-notification-no-texting="receive-only"><i class="fas fa-info-circle me-2"></i>Texting is set to Receive only, so none of these go. <a href="text_messaging.php">Text Messaging</a></div>
<?php } elseif (!smsReady()) { ?>
<div class="alert alert-light border py-2 small" data-notification-no-texting><i class="fas fa-info-circle me-2"></i>Texting isn't set up, so none of these go. <a href="text_messaging.php">Set up texting</a></div>
<?php } ?>
<?php if ($config_module_enable_ticketing) { ?>

View File

@@ -77,6 +77,8 @@ echo settingsPageStart('ticket');
<?= settingsSectionStart('text', 'Text to ticket', 'A text to your number from one of your contacts becomes a ticket, and a text on a ticket goes on it - texts from anyone else, verification codes and spam wait in Texts instead. Texting is set up in <a href="text_messaging.php">Text Messaging</a>.') ?>
<?php if (!smsProvider()) { ?>
<div class="alert alert-light border py-2 small" data-ticket-no-texting><i class="fas fa-info-circle me-2"></i>Texting isn't set up yet, so no texts come in.</div>
<?php } elseif (smsReceiveOnly()) { ?>
<div class="alert alert-light border py-2 small" data-ticket-no-texting="receive-only"><i class="fas fa-info-circle me-2"></i>Texting is set to Receive only - texts come in as below, but nothing is texted back: not the ticket number, and no answer to STOP, START or HELP.</div>
<?php } ?>
<?= settingsSwitch('config_ticket_sms_parse', intval($sms_settings['config_ticket_sms_parse']), ['help' => 'Off, every text waits in Texts for an agent - STOP, START and HELP are still answered.']) ?>
<div data-settings-depends-on="config_ticket_sms_parse">

View File

@@ -81,7 +81,13 @@ $ready = smsReady();
</div>
</div>
<?php if (!$ready) { ?>
<?php if (!$ready && smsReceiveOnly()) { ?>
<div class="alert alert-info rounded-0 border-0 border-bottom mb-0 d-flex flex-wrap align-items-center gap-2" data-sms-health="receive-only">
<i class="fas fa-fw fa-inbox"></i>
<div class="me-auto"><strong>Receive only</strong> - texts to your number come in, and nothing is texted out.</div>
<a class="btn btn-sm btn-info" href="text_messaging.php">Text Messaging</a>
</div>
<?php } elseif (!$ready) { ?>
<div class="alert alert-warning rounded-0 border-0 border-bottom mb-0 d-flex flex-wrap align-items-center gap-2" data-sms-health="off">
<i class="fas fa-fw fa-exclamation-triangle"></i>
<div class="me-auto"><strong>Texting isn't on</strong> - nothing goes out, and texts to your number aren't taken in.</div>

View File

@@ -2,7 +2,7 @@
/*
* Admin > Text Messaging - the texting service ITFlow texts through (functions/sms.php), one
* number for every client. Each row says whether it is on, the number, the address its texts
* number for every client. Each row says whether it is on, whether it is Receive only, the number, the address its texts
* come back to (pasted into the service's portal), and its texts in the last 30 days. Send a
* test text tries it; Opted out and blocked lists the numbers that replied STOP or were
* marked spam. Add and Edit are one window (modals/sms_provider/sms_provider_edit.php); the
@@ -114,6 +114,9 @@ $csrf = $_SESSION['csrf_token'];
<?php if (!$on) { ?>
<span class="badge rounded-pill text-bg-secondary ms-1" data-sms-provider-state="off" title="No texts go out, and texts sent to the number aren't taken in">Off</span>
<?php } ?>
<?php if (!smsSends($row)) { ?>
<span class="badge rounded-pill text-bg-info ms-1" data-sms-provider-state="receive-only" title="Texts to the number come in - as tickets, replies and codes - and nothing is texted out">Receive only</span>
<?php } ?>
<?php if (trim((string) $row['sms_provider_description']) !== '') { ?>
<div class="small text-body-secondary"><?= escapeHtml($row['sms_provider_description']) ?></div>
<?php } ?>
@@ -144,7 +147,7 @@ $csrf = $_SESSION['csrf_token'];
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= $edit_url ?>">
<i class="fas fa-fw fa-edit text-secondary me-2"></i>Edit
</a>
<?php if ($on) { ?>
<?php if ($on && smsSends($row)) { ?>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/sms_provider/sms_test.php?id=<?= $provider_id ?>">
<i class="fas fa-fw fa-vial text-secondary me-2"></i>Send a Test Text
</a>
@@ -182,7 +185,7 @@ $csrf = $_SESSION['csrf_token'];
$empty_state = [
'thing' => 'texting providers',
'icon' => 'fa-sms',
'text' => 'Set up Skyetel and your agents can reply to tickets by text, texts from your clients open tickets, and verification codes texted to your number land in Texts.',
'text' => 'Set up Skyetel and texts from your clients open tickets, verification codes texted to your number land in Texts, and your agents can reply to tickets by text - or set it to Receive only, and nothing is texted out.',
'actions' => $can_add ? [['label' => 'New Provider', 'modal' => $add_url]] : [],
];
?>