Enabled netmail test message

This commit is contained in:
Deon George 2021-11-27 00:36:57 +11:00
parent b35655a163
commit e0239d95a8
4 changed files with 198 additions and 0 deletions

View File

@ -0,0 +1,40 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Notification;
use App\Models\Address;
use App\Notifications\NetmailTest;
class SendTestNetmail extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'netmail:test'
.' {ftn : FTN to send netmail to}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Send a netmail test message';
/**
* Execute the console command.
*
* @return mixed
* @throws \Exception
*/
public function handle()
{
$ao = Address::findFTN($this->argument('ftn'));
Notification::route('netmail',$ao)->notify(new NetmailTest($ao));
}
}

View File

@ -0,0 +1,50 @@
<?php
namespace App\Notifications\Channels;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Log;
use App\Models\Netmail;
use App\Jobs\AddressPoll as Job;
class NetmailChannel
{
private const LOGKEY = 'CN-';
/**
* The HTTP client instance.
*
* @var Netmail
*/
protected Netmail $netmail;
/**
* Create a new Slack channel instance.
*
* @param Netmail $o
*/
public function __construct(Netmail $o)
{
$this->netmail = $o;
}
/**
* Send the given notification.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return \Psr\Http\Message\ResponseInterface|null
*/
public function send($notifiable,Notification $notification)
{
if (! $ao = $notifiable->routeNotificationFor('netmail',$notification))
return;
$o = $notification->toNetmail($notifiable);
Log::info(sprintf('%s:Test Netmail created [%s]',self::LOGKEY,$o->id));
Job::dispatch($ao);
Log::info(sprintf('%s:Dispatched job to pool address [%s]',self::LOGKEY,$ao->ftn));
}
}

View File

@ -0,0 +1,98 @@
<?php
namespace App\Notifications;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Log;
use App\Classes\{ANSI,Fonts\Thin,Page};
use App\Classes\Fonts\Thick;
use App\Classes\FTN\Message;
use App\Models\{Address,Netmail,Setup,User};
class NetmailTest extends Notification //implements ShouldQueue
{
private const LOGKEY = 'NNT';
use Queueable;
private Address $ao;
/**
* Create a new notification instance.
*
* @param Address $ao
* @param User $uo
*/
public function __construct(Address $ao)
{
$this->queue = 'netmail';
$this->ao = $ao;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['netmail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return Netmail
* @throws \Exception
*/
public function toNetmail($notifiable): Netmail
{
Log::info(sprintf('%s:Creating test netmail to [%s]',self::LOGKEY,$this->ao->ftn));
$so = Setup::findOrFail(config('app.id'))->system;
$o = new Netmail;
$o->to = $this->ao->system->sysop;
$o->from = Setup::PRODUCT_NAME;
$o->subject = 'Testing 1, 2, 3...';
$o->datetime = Carbon::now();
$o->tzoffset = $o->datetime->utcOffset();
$o->fftn_id = $so->match($this->ao->zone)->first();
$o->tftn_id = $this->ao->id;
$o->flags = Message::FLAG_LOCAL;
$o->cost = 0;
$o->tagline = 'Testing, testing, 1 2 3.';
$o->tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
// Message
$msg = new Page;
$msg->addLogo(new ANSI('public/logo/netmail.bin'));
$header = new Thick;
$header->addText(ANSI::ansi_code([1,37]).'Clearing Houz');
$msg->addHeader($header,'FTN Mailer and Tosser',TRUE,0xc4);
$lbc = new Thin;
$lbc->addText('Test');
$msg->addLeftBoxContent($lbc);
$msg->addText(
"Hi there,\r\r".
"This is just a test netmail to make sure we can send a message to your system.\r\r".
"There is no need to reply, but if you do, it'll boost my spirits :)\r"
);
$o->msg = $msg->render();
$o->save();
return $o;
}
}

View File

@ -2,9 +2,13 @@
namespace App\Providers; namespace App\Providers;
use Illuminate\Notifications\ChannelManager;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Laravel\Passport\Passport; use Laravel\Passport\Passport;
use App\Notifications\Channels\NetmailChannel;
use App\Models\Netmail;
use App\Traits\SingleOrFail; use App\Traits\SingleOrFail;
class AppServiceProvider extends ServiceProvider class AppServiceProvider extends ServiceProvider
@ -19,6 +23,12 @@ class AppServiceProvider extends ServiceProvider
public function register() public function register()
{ {
Passport::ignoreMigrations(); Passport::ignoreMigrations();
Notification::resolved(function (ChannelManager $service) {
$service->extend('netmail', function ($app) {
return new NetmailChannel($app->make(Netmail::class));
});
});
} }
/** /**