Change phone adapter meta number to type phone_number + add support for boolean adapter data + add a noStaupClose to ovh adapter

This commit is contained in:
osaajani 2022-07-12 13:16:22 +02:00
parent 9c9f99c87a
commit a0f3784baa
8 changed files with 85 additions and 17 deletions

View File

@ -154,7 +154,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
'title' => 'Numéro de téléphone virtuel',
'description' => 'Numéro de téléphone virtuel Octopush à utiliser.',
'required' => true,
'number' => true,
'type' => 'phone_number',
],
[
'name' => 'sms_type',

View File

@ -144,6 +144,13 @@ namespace adapters;
'description' => 'Paramètre "Consumer Key" obtenu lors de la génération de la clef API OVH.',
'required' => true,
],
[
'name' => 'no_stop_clause',
'title' => 'Désactiver la clause "STOP SMS" automatique',
'description' => 'En cochant ce paramètre, la clause "STOP SMS" ne sera pas ajoutée automatiquement au SMS par OVH.',
'required' => false,
'type' => 'boolean'
],
];
}
@ -222,6 +229,7 @@ namespace adapters;
'message' => $text,
'receivers' => [$destination],
'senderForResponse' => true,
'noStopClause' => (bool) ($this->data['no_stop_clause'] ?? false),
];
if ($this->data['sender'])
@ -325,7 +333,7 @@ namespace adapters;
{
$success = true;
if ($this->data['sender'] && (mb_strlen($this->data['sender']) < 3 || mb_strlen($this->data['sender'] > 11)))
if ($this->data['sender'] && (mb_strlen($this->data['sender']) < 3 || mb_strlen($this->data['sender']) > 11))
{
return false;
}
@ -334,6 +342,7 @@ namespace adapters;
$endpoint = '/sms/' . $this->data['service_name'];
$response = $this->api->get($endpoint);
return $success && (bool) $response;
}
catch (\Throwable $t)

View File

@ -135,7 +135,7 @@ namespace adapters;
'title' => 'Numéro',
'description' => 'Numéro de téléphone virtuel chez OVH.',
'required' => true,
'number' => true,
'type' => 'phone_number',
],
[
'name' => 'app_key',

View File

@ -140,7 +140,7 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
'title' => 'Numéro de téléphone virtuel',
'description' => 'Numéro de téléphone virtuel Twilio à utiliser parmis les numéro actifs (format international), <a href="https://www.twilio.com/console/phone-numbers/incoming" target="_blank">voir la liste ici</a>.',
'required' => true,
'number' => true,
'type' => 'phone_number',
],
[
'name' => 'status_change_callback',

View File

@ -484,6 +484,54 @@ footer img
padding-left: 15px;
}
#adapter-data-fields input[type="checkbox"]
{
display: block;
width: auto;
}
#adapter-data-fields input[type=checkbox]{
height: 0;
width: 0;
visibility: hidden;
}
#adapter-data-fields .switch {
cursor: pointer;
text-indent: -9999px;
width: 44px;
height: 24px;
background: #aaa;
display: block;
border-radius: 100px;
position: relative;
}
#adapter-data-fields .switch:after {
content: '';
position: absolute;
top: 2px;
left: 2px;
width: 20px;
height: 20px;
background: #fff;
border-radius: 20px;
transition: 0.3s;
}
#adapter-data-fields input:checked + .switch {
background: #5cb85c;
}
#adapter-data-fields input:checked + .switch:after {
left: calc(100% - 2px);
transform: translateX(-100%);
}
#adapter-data-fields .switch:active:after {
width: 30px;
}
/* DATATABLES */
.dataTables_paginate
{

View File

@ -211,7 +211,7 @@ class Phone extends \descartes\Controller
//If field phone number is invalid
foreach ($find_adapter['meta_data_fields'] as $field)
{
if (false === ($field['number'] ?? false))
if ('phone_number' !== ($field['type'] ?? false))
{
continue;
}

View File

@ -58,7 +58,7 @@ class Phone extends AbstractDaemon
{
usleep(0.5 * 1000000); //Micro sleep for perfs
++$this->read_tick;
$this->read_tick += 1;
$this->bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);

View File

@ -105,17 +105,7 @@
var html = '';
jQuery.each(data_fields, function (index, field)
{
if (!field.number)
{
html += '<div class="form-group">' +
'<label>' + field.title + '</label>' +
'<p class="italic small help">' + field.description + '</p>' +
'<div class="form-group">' +
'<input name="adapter_data[' + field.name + ']" class="form-control" ' + (field.required ? 'required' : '') + ' ' + (field.default_value ? 'value="' + field.default_value + '"' : '') + '>' +
'</div>' +
'</div>';
}
else
if (field.type == 'phone_number')
{
var random_id = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
html += '' +
@ -133,6 +123,27 @@
};
numbers.push(number);
}
else if (field.type == 'boolean')
{
html += '<div class="form-group">' +
'<label>' + field.title + '</label>' +
'<p class="italic small help">' + field.description + '</p>' +
'<div class="form-group">' +
'<input type="checkbox" id="adapter_data[' + field.name + ']" name="adapter_data[' + field.name + ']" class="form-control" ' + (field.required ? 'required' : '') + ' ' + (field.default_value ? 'value="' + field.default_value + '" checked' : 'value="1"') + '><label class="switch" for="adapter_data[' + field.name + ']"></label>' +
'</div>' +
'</div>';
}
else
{
html += '<div class="form-group">' +
'<label>' + field.title + '</label>' +
'<p class="italic small help">' + field.description + '</p>' +
'<div class="form-group">' +
'<input name="adapter_data[' + field.name + ']" class="form-control" ' + (field.required ? 'required' : '') + ' ' + (field.default_value ? 'value="' + field.default_value + '"' : '') + '>' +
'</div>' +
'</div>';
}
});