Send multiple SMS with the sc_send_sms macro

In this example we will be seeing how we can create an application that helps us send multiple messages through the sc_send_sms macro.

Creating a Control application

1 – We create an application of type Control.

2 – Once the application is created we must create 10 fields with the following types of data:

3 – Then we configure the following fields in this way:

  • sms_group
  • sms_gateway
  • sms_date_time
  • sms_binary
  • sms_send_type

4 – After having configured the fields according to the images, we proceed to create the following methods:

5 – Within the m_sms_clickatell method we place the following:


$var_config    = array(
    ‘message’ => [
    ‘to’ => {loc_numbers},
    ‘from’ => {loc_from_number},
    ‘binary’ => ({sms_binary}==1 ? true : false),
    //clientMessageId’ => ”
    ‘scheduledDeliveryTime’ => {sms_date_time}, // yyyy-MM-ddTHH:mm:ss-0300 — 2018-01-01T10:01:10+0300
    ‘validityPeriod’ => {sms_periody}, //day
    ‘charset’ => {sms_charset}, //ASCII, UCS2-BE, UTF-8, Windows-1252
    ‘message’ => {loc_message},
],
‘settings’ => [
     ‘gateway’ => $p_gateway,
    ‘auth_token’ => {loc_token},
     ]
);

if(empty({sms_date_time}) || {sm_date_time}==””){
    unset($var_config[‘message’][‘scheduledDeliveryTime’]);
}

$return = sc_send_sms($var_config);

$msg_body = ‘<table class=”table table-bordered table-striped”>
    <tr>
    <td>MessageID</td>
    <td>Acepted</td>
    <td>TO</td>
    <td>ErrorCode</td>
    <td>Error</td>
    <td>Error Message</td>
    </tr>’;

    foreach($return as $key => $values){
    $values[‘accepted’] = ($values[‘accepted’] == 1 ? ‘Success’ : $values[‘accepted’]);
    $msg_body .= “<tr>
    <td>”.$values[‘apiMessageId’].”</td>
    <td>”.$values[‘accepted’].”</td>
    <td>”.substr($values[‘to’],0,-3).’xxx’.”</td>
    <td>”.$values[‘errorCode’].”</td>
    <td>”.$values[‘error’].”</td>
    <td>”.$values[‘errorDescription’].”</td>
    </tr>”;
    }
    $msg_body .='</table>’;

return $msg_body;

6 – In the m_sms_plivo method:


$var_config    = array(
    ‘message’ => [
    ‘to’ => $loc_numbers,
    ‘from’ => $loc_from_number,
    ‘message’ => $loc_message,
    ‘ValidityPeriod’ => {sms_periody}, //seconds
    ‘ProvideFeedback’ => false, //feedback message API – true
     
],
‘settings’ => [
     ‘gateway’ => $p_gateway,
    ‘auth_id’ => $loc_sid,
    ‘auth_token’ => $loc_token,
     ]
);

/*
if(empty({sms_date_time}) || {sm_date_time}==””){
    unset($var_config[‘message’][‘scheduledDeliveryTime’]);
}
*/

$return = sc_send_sms($var_config);

$msg_body = ‘<table class=”table table-bordered table-striped”>
    <tr>
    <td>Message Response</td>
    </tr>’;
$msg_body .= “
    <tr>
    <td>”.$return.”</td>
    </tr>”;
$msg_body .='</table>’;

return $msg_body;

7 – In the m_sms_twilio method:


$var_config    = array(
    ‘message’ => [
    ‘to’ => $loc_numbers,
    ‘from’ => $loc_from_number,
     //”mediaUrl” => “https://www.scriptcase.com.br/docs/pt_br/v9/assets/images/scriptcase-logo.svg”,
    ‘message’ => $loc_message,
    ‘ValidityPeriod’ => {sms_periody}, //seconds
    ‘ProvideFeedback’ => false, //feedback message API – true
    //’MessagingServiceSid’ => ” //34 char unique from twilio service
    ‘StatusCallback’ => ‘http://’ . $_SERVER[“HTTP_HOST”] . $_SERVER[“PHP_SELF”],
    //”MessagingServiceSid” => “”,
     
],
‘settings’ => [
     ‘gateway’ => $p_gateway,
    ‘auth_id’ => $loc_sid,
    ‘auth_token’ => $loc_token,
     ]
);

/*
if(empty({sms_date_time}) || {sm_date_time}==””){
    unset($var_config[‘message’][‘scheduledDeliveryTime’]);
}
*/

$return = sc_send_sms($var_config);

$msg_body = ‘<table class=”table table-bordered table-striped”>
    <tr>
    <td>Message Response</td>
    </tr>’;
$msg_body .= “
    <tr>
    <td>”.$return.”</td>
    </tr>”;
$msg_body .='</table>’;

return $msg_body;

8 – After creating these methods, we proceed to include a library that will help us complement what is necessary for the application:

9 – Then in the onScriptInit event we call the library as follows:

10 – Then inside the onLoad event:


?>
<link rel=”stylesheet” href=”https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css”>
<script>
    $(document).ready(function(){
    $(“#id_sc_field_sms_date_time”).attr(“placeholder”, “dd/mm/aaaa hh:mm:ss”);
    $(“#id_sc_field_sms_date_time”).val(“”);
    $(“#sub_form_t”).css(“background-color”,”green”);
    $(“#sub_form_t”).css(“color”,”white”);
    });
</script>
<?php

if({sms_send_type}==1){
    sc_field_disabled(“sms_unique_to”);
    sc_field_disabled(“sms_group=false”);
}else{
    sc_field_disabled(“sms_unique_to=false”);
    sc_field_disabled(“sms_group”);
}

11 – Inside the onValidateSuccess:


//$sql  = “SELECT token,from_number,gateway FROM sms_info WHERE id = “. {sms_gateway};
//sc_lookup(ds,$sql);

$loc_gateway    = {sms_gateway};
$loc_message    = {sms_message};
$loc_numbers    = array();
if({sms_send_type}==1){
    $sql = “SELECT phone, contactname FROM customers WHERE regionid = “. {sms_group};
    sc_lookup(ds,$sql);
    foreach({ds} as $values){
    $loc_numbers[] = $values[0];
    }
}else{
    $loc_numbers = {sms_unique_to};
}

if( $loc_gateway == “clickatell” ){
    $loc_token    = “J3OMe9DJTP6pR_0PTSVamA==”;
    $loc_from_number     = “+16165120069”;
    {sms_msg_return} = m_sms_clickatell($loc_gateway,$loc_token,$loc_from_number,$loc_message,$loc_numbers);
}
elseif( $loc_gateway == “twilio” ){
    $loc_token    = “6b5c3c3d0beed4d2422737a20dca3763”;
    $loc_from_number     = “+16165120069”;
    $loc_sid = “ACc21dd9d81b91aa2876446f9a1fb00784”;
    {sms_msg_return} = m_sms_twilio($loc_gateway, $loc_token, $loc_from_number, $loc_message, $loc_numbers, $loc_sid);
}
elseif( $loc_gateway == “plivo” ){
    $loc_token    = “MGIzNjRmOTE5ZDY5YjNkNGFhOGQ1ODcwYzljMTFl”; // Get your token at your Plivo account
    $loc_from_number     = “+16165120069”; // Register a cellphone number into your Plivo account
    $loc_sid = “MAYZNLZMQZOWNJMZM3ZT”; // Get your Sid at your Plivo account
    {sms_msg_return} = m_sms_plivo($loc_gateway, $loc_token, $loc_from_number, $loc_message, $loc_numbers, $loc_sid);
}



/* return:
Array
(
[0] => Array
     (
         [apiMessageId] => 38fc56069a24401f8a58439c5317312e
         [accepted] => 1
         [to] => xxxxxx
         [errorCode] =>
         [error] =>
         [errorDescription] =>
     )

[1] => Array
     (
         [apiMessageId] => 1aee3a58c2ed472fa303d511147f74d3
         [accepted] => 1
         [to] => xxxxxx
         [errorCode] =>
         [error] =>
         [errorDescription] =>
     )

)
*/

12 – Finally we create an AJAX event of the sms_send_type field of type OnClick:

13 – We add the following:


if({sms_send_type}==1){
    sc_field_disabled(“sms_unique_to”);
    sc_field_disabled(“sms_group=false”);
}else{
    sc_field_disabled(“sms_unique_to=false”);
    sc_field_disabled(“sms_group”);
}

14 – Save the changes and run the application

Tutorials in the same category

Using the Paypal and Pagseguro API

1 - We create an application of the grid type 2 - We edit the following fields and create a ...

Send SMS with the sc_send_sms macro

Creating a Control application 1 - We create an application of type Control. 2 - Once the...

Using the Mandrill API with macro sc_call_api

In this tutorial we will be showing how to use the sc_call_api macro with the Mandrill API. ...

Email API with the sc_send_mail_api Macro

1 - Create an application of type Control 2 - We proceed to create the necessary fields for ...

Comment this post