using composer package inside Row_CustomAction server event

Hi,
I want to call a composer package and use it inside Row_CustomAction server event. I can’t do that:
if ($action == “SendPush”) { // Check action name
$siteconf = new SiteConfig();
\Minishlink\WebPush\WebPush;
\Minishlink\WebPush\Subscription;
$auth = array(
‘VAPID’ => array(
‘subject’ => ‘----------’,
‘publicKey’ => $siteconf->PublicKey,
‘privateKey’ => $siteconf->PrivateKey,
),
);
//push content
$notifContent = array(
‘title’ => ‘Testing’,
‘msg’ => ‘Testing the system’,
‘badge’ => $siteconf->PushBadge,
‘icon’ => $siteconf->PushIcon,
);
$subscriber = ExecuteRow(“SELECT * FROM subscribers WHERE patient = '”.$row[‘PatientID’].“'”);
$notification = [
‘subscription’ => Subscription::create([
‘endpoint’ => $subscriber[‘endpoint’],
‘keys’ => [
‘p256dh’ => $subscriber[‘p256dh’],
‘auth’ => $subscriber[‘auth’]
]
])
];
$webPush = new WebPush($auth);
//sending push message
$webPush->sendNotification(
$notification[‘subscription’],
json_encode($notifContent)
);
//show the result
foreach ($webPush->flush() as $report) {
$endpoint = $report->getRequest()->getUri()->__toString();
if ($report->isSuccess()) {
$this->setFailureMessage(“خطا در ارسال ایمیل به کاربر شماره “. $row[‘PatientID’].””);
return FALSE; // Abort and rollback } elseif ($this->SelectedIndex == $this->SelectedCount) {
$this->setSuccessMessage(“بارکد اختصاصی بیماران انتخاب شده ارسال شد”);
}
}
return TRUE; // Success
}

what’s wrong in my code? how to use composer package in functions ?

Thanks
Mansour

You should use:

// \Minishlink\WebPush\WebPush; // remove

$webPush = new \Minishlink\WebPush\WebPush($auth); // use namespace

See: https://www.php.net/manual/en/language.namespaces.basics.php.

Hi,
First, thank you for your help.
I read the suggested document but I have still a question:
How I can use “Minishlink\WebPush\Subscription” function :

$subscriber = ExecuteRow(“SELECT * FROM subscribers WHERE patient = '”.$row[‘PatientID’].“'”);
$notification = [
‘subscription’ => Subscription::create([ /// ??? HERE ???
‘endpoint’ => $subscriber[‘endpoint’],
‘keys’ => [
‘p256dh’ => $subscriber[‘p256dh’],
‘auth’ => $subscriber[‘auth’]
]
])
];

Thanks

Hi,
I used the following code and it works:
$subscriber = ExecuteRow(“SELECT * FROM subscribers WHERE patient = '”.$row[‘PatientID’].“'”);
$notification = [
‘subscription’ => \Minishlink\WebPush\Subscription::create([
‘endpoint’ => $subscriber[‘endpoint’],
‘keys’ => [
‘p256dh’ => $subscriber[‘p256dh’],
‘auth’ => $subscriber[‘auth’]
]
])
];


Thank you for your help.