FIle - /trunk/views/php/admin/communicate/broadcast_sms.php

/trunk/views/php/admin/communicate/broadcast_sms.php
1,731 bytes
January 20, 2025 at 08:22
4




<?php
declare(strict_types 1);

namespace 
Views\admin\communicate;

use 
Apex\Svc\{ViewAppQueue};
use 
App\Webapp\AdminProfiles;
use 
App\Users\Tasks\BroadcastSMS;
use 
Brick\PhoneNumber\PhoneNumber;
use 
Brick\PhoneNumber\PhoneNumberParseException;

/**
 * Render the template.
 */
class broadcast_sms
{

    
/**
     * Render
     */
    
public function render(View $viewApp $appAdminProfiles $admin_profilesQueue $queue):void
    
{

        
// Get sender
        
$phone $app->config('core.nexmo_sender');
        try {
            
$number PhoneNumber::parse('+' $phone);
            
$view->assign('sender'$number->formatForCallingFrom($phone));
        } catch(
PhoneNumberParseException $e) { 
            
$view->addCallout('You do not have Nexmo configured on this system, hence a SMS broadcast will not work.  You may configure Nexmo via the Settings-&gt;Settings menu, API Keys tab.');
            
$view->assign('sender''Not Configured');
        }

        
// Check for form post
        
if ($app->getAction() != 'send') {
            return;
        } elseif (
$phone == '') {
            throw new 
\Exception("You do not have Nexmo configured on this system, hence can not send a SMS broadcast.");
        }

        
// Set json vars
        
$json $app->getAllPost();
        
$json['admin_email'] = $app->getUser()->getEmail();
        
$json['admin_name'] = $app->getUser()->getFullName();

            
// Add to queue
        
$queue->add(BroadcastSMS::class, $json);

        
// Callout
        
$view->addCallout('Successfully queued the message to be sent, and it will send within minutes.  If the message does not send, check to ensure the crontab job on your server is correctly added.');
    }

}